media-agent-mcp 2.6.1__py3-none-any.whl → 2.6.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -167,8 +167,6 @@ def google_edit(image_urls: List[str], prompt: str) -> Dict[str, Any]:
167
167
  "data": None,
168
168
  "message": "GOOGLE_API_KEY environment variable is not set."
169
169
  }
170
-
171
- genai.configure(api_key=api_key)
172
170
 
173
171
  if not image_urls or not isinstance(image_urls, list):
174
172
  return {
@@ -185,25 +183,47 @@ def google_edit(image_urls: List[str], prompt: str) -> Dict[str, Any]:
185
183
 
186
184
  contents = pil_images + [prompt]
187
185
 
188
- model = genai.GenerativeModel("gemini-1.5-flash-latest")
189
- response = model.generate_content(contents)
190
-
191
- image_data = None
192
- if response.candidates and response.candidates[0].content and response.candidates[0].content.parts:
193
- image_parts = [
194
- part.inline_data.data
195
- for part in response.candidates[0].content.parts
196
- if part.inline_data
197
- ]
198
- if image_parts:
199
- image_data = image_parts[0]
200
-
201
- if not image_data:
202
- return {
203
- "status": "error",
204
- "data": None,
205
- "message": "Google API response did not contain image data."
206
- }
186
+ client = genai.Client(
187
+ api_key=api_key,
188
+ )
189
+
190
+ # 最多尝试3次
191
+ max_retries = 3
192
+ for attempt in range(max_retries):
193
+ try:
194
+ response = client.models.generate_content(
195
+ model="gemini-2.5-flash-image-preview",
196
+ contents=contents
197
+ )
198
+
199
+ image_data = None
200
+ if response.candidates and response.candidates[0].content and response.candidates[0].content.parts:
201
+ image_parts = [
202
+ part.inline_data.data
203
+ for part in response.candidates[0].content.parts
204
+ if part.inline_data
205
+ ]
206
+ if image_parts:
207
+ image_data = image_parts[0]
208
+
209
+ # 如果获取到了图片数据,跳出重试循环
210
+ if image_data:
211
+ break
212
+
213
+ # 如果是最后一次尝试且仍然没有图片数据,返回错误
214
+ if attempt == max_retries - 1:
215
+ return {
216
+ "status": "error",
217
+ "data": None,
218
+ "message": f"Google API response did not contain image data after {max_retries} attempts."
219
+ }
220
+
221
+ except Exception as api_error:
222
+ # 如果是最后一次尝试,抛出异常
223
+ if attempt == max_retries - 1:
224
+ raise api_error
225
+ # 否则继续下一次尝试
226
+ continue
207
227
 
208
228
  with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_edited_file:
209
229
  temp_edited_file.write(image_data)
@@ -237,8 +257,8 @@ if __name__ == '__main__':
237
257
  # For example: export OPENAI_API_KEY='your-api-key'
238
258
  image_url = 'https://carey.tos-ap-southeast-1.bytepluses.com/Art%20Portrait/Art%20Portrait/Art%20Portrait/Art%20Portrait%20(1).jpg'
239
259
  prompt = 'A cute baby sea otter cooking a meal'
240
- result = openaiedit([image_url, image_url], prompt)
241
- print(result)
260
+ # result = openaiedit([image_url, image_url], prompt)
261
+ # print(result)
242
262
 
243
263
  # Test for google_edit
244
264
  # Make sure to set your GOOGLE_API_KEY environment variable
@@ -246,7 +266,7 @@ if __name__ == '__main__':
246
266
  print("\nTesting Google Edit...")
247
267
  if os.getenv("GOOGLE_API_KEY"):
248
268
  google_prompt = "make the person smile"
249
- google_result = google_edit([image_url], google_prompt)
269
+ google_result = google_edit([image_url, image_url], google_prompt)
250
270
  print(f"Google Edit result: {google_result}")
251
271
  else:
252
272
  print("GOOGLE_API_KEY not set, skipping google_edit test.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: media-agent-mcp
3
- Version: 2.6.1
3
+ Version: 2.6.3
4
4
  Summary: A Model Context Protocol server for media processing with AI tools
5
5
  Author-email: Media Agent Team <team@mediaagent.com>
6
6
  Keywords: mcp,ai,media,video,image,processing
@@ -4,7 +4,7 @@ media_agent_mcp/async_wrapper.py,sha256=hiiBhhz9WeVDfSBWVh6ovhf5jeP5ZbsieBbz9P-K
4
4
  media_agent_mcp/server.py,sha256=e8ubU0-R0OnuJy5Gk6jPg8rQXq478O_6f5lNMRMyeQA,19494
5
5
  media_agent_mcp/ai_models/__init__.py,sha256=2kHzTYwjQw89U4QGDq0e2WqJScqDkDNlDaWHGak5JeY,553
6
6
  media_agent_mcp/ai_models/omni_human.py,sha256=s_Ja4gEmHG_bgii1x4SoeV73lz0Zg_3iBRvu36goxVA,4643
7
- media_agent_mcp/ai_models/openaiedit.py,sha256=nz29gYXaTmmekDS2UOiPK1mpq0gimpiRJIb5JcI1MDY,8894
7
+ media_agent_mcp/ai_models/openaiedit.py,sha256=uu4d2BgXSrjWRdNPs_SryI9muxO93pItVtEze9nDhjc,9776
8
8
  media_agent_mcp/ai_models/seed16.py,sha256=_rPBfgDASxb2_5-mydus-SLK-6XGy2Cy5lLh5ORBtN8,5078
9
9
  media_agent_mcp/ai_models/seedance.py,sha256=ni7LtXn4jTn5wX2NtcWDMj5Eea8LoP1QLYgwSx_GvBs,9014
10
10
  media_agent_mcp/ai_models/seededit.py,sha256=2f0GiQPqH5IJKsZyW0h5WNA99DX--9oOKiD6vqg8Urk,2091
@@ -44,8 +44,8 @@ media_agent_mcp/video/__init__.py,sha256=tfz22XEeFSeuKa3AggYCE0vCDt4IwXRCKW6avof
44
44
  media_agent_mcp/video/processor.py,sha256=twfqmN5DbVryjDawZUcqTUcnglcBJYpUbAnApqHgD0c,12787
45
45
  media_agent_mcp/video/stack.py,sha256=pyoJiJ9NhU1tjy2l3kARI9sWFoC00Fj97psxYOBi2NU,1736
46
46
  media_agent_mcp/video/subtitle.py,sha256=TlrWVhWJqYTUJpnVz7eccwMAn8ixfrRzRxS6ETMY-DM,16323
47
- media_agent_mcp-2.6.1.dist-info/METADATA,sha256=zvJ0hMsKHt2xTnZVvORWbecu15EqGJlGuX9VdApXerw,11310
48
- media_agent_mcp-2.6.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
49
- media_agent_mcp-2.6.1.dist-info/entry_points.txt,sha256=qhOUwR-ORVf9GO7emhhl7Lgd6MISgqbZr8bEuSH_VdA,70
50
- media_agent_mcp-2.6.1.dist-info/top_level.txt,sha256=WEa0YfchpTxZgiKn8gdxYgs-dir5HepJaTOrxAGx9nY,16
51
- media_agent_mcp-2.6.1.dist-info/RECORD,,
47
+ media_agent_mcp-2.6.3.dist-info/METADATA,sha256=FsbCwmhhslumpLV0wamMizqUxyzE4G3qTJMfd7wrcYE,11310
48
+ media_agent_mcp-2.6.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
49
+ media_agent_mcp-2.6.3.dist-info/entry_points.txt,sha256=qhOUwR-ORVf9GO7emhhl7Lgd6MISgqbZr8bEuSH_VdA,70
50
+ media_agent_mcp-2.6.3.dist-info/top_level.txt,sha256=WEa0YfchpTxZgiKn8gdxYgs-dir5HepJaTOrxAGx9nY,16
51
+ media_agent_mcp-2.6.3.dist-info/RECORD,,