Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -187,7 +187,7 @@ def normalize_messages(messages):
|
|
| 187 |
if a.get('kind') == 'image' and a.get('dataUrl'):
|
| 188 |
parts.append({"type": "image_url", "image_url": {"url": a.get('dataUrl')}})
|
| 189 |
else:
|
| 190 |
-
extra_text +=
|
| 191 |
|
| 192 |
if extra_text:
|
| 193 |
content = content + extra_text
|
|
@@ -331,7 +331,7 @@ def execute_tool(tool_data):
|
|
| 331 |
logger.info(f"[tool] Searching: {query[:100]}")
|
| 332 |
results = web_search_with_timeout(query, timeout=5)
|
| 333 |
if results:
|
| 334 |
-
formatted = "\n\n###
|
| 335 |
for i, r in enumerate(results[:5], 1):
|
| 336 |
formatted += f"**{i}. {r.get('title', '')}**\n"
|
| 337 |
formatted += f" {r.get('snippet', '')[:200]}\n"
|
|
@@ -344,7 +344,7 @@ def execute_tool(tool_data):
|
|
| 344 |
logger.info(f"[tool] Image search: {query[:100]}")
|
| 345 |
images = image_search(query)
|
| 346 |
if images:
|
| 347 |
-
formatted = "\n\n###
|
| 348 |
for i, img in enumerate(images[:4], 1):
|
| 349 |
formatted += f"})\n\n"
|
| 350 |
return formatted
|
|
@@ -554,7 +554,7 @@ def chat():
|
|
| 554 |
except json.JSONDecodeError:
|
| 555 |
continue
|
| 556 |
|
| 557 |
-
#
|
| 558 |
if not tool_executed:
|
| 559 |
tool = extract_tool_from_text(full_response)
|
| 560 |
if tool:
|
|
@@ -572,7 +572,8 @@ def chat():
|
|
| 572 |
yield f"data: {json.dumps({'delta': tool_result})}\n\n"
|
| 573 |
except Exception as tool_error:
|
| 574 |
logger.error(f"[tool] Error: {tool_error}")
|
| 575 |
-
|
|
|
|
| 576 |
|
| 577 |
yield f"data: {json.dumps({'done': True})}\n\n"
|
| 578 |
return
|
|
@@ -726,5 +727,5 @@ def internal_error(e):
|
|
| 726 |
|
| 727 |
if __name__ == '__main__':
|
| 728 |
port = int(os.environ.get('PORT', 7860))
|
| 729 |
-
logger.info(f"
|
| 730 |
app.run(host='0.0.0.0', port=port, threaded=True)
|
|
|
|
| 187 |
if a.get('kind') == 'image' and a.get('dataUrl'):
|
| 188 |
parts.append({"type": "image_url", "image_url": {"url": a.get('dataUrl')}})
|
| 189 |
else:
|
| 190 |
+
extra_text += "\n\n[File: " + a.get('name', '') + "]\n" + (a.get('text') or '')[:8000]
|
| 191 |
|
| 192 |
if extra_text:
|
| 193 |
content = content + extra_text
|
|
|
|
| 331 |
logger.info(f"[tool] Searching: {query[:100]}")
|
| 332 |
results = web_search_with_timeout(query, timeout=5)
|
| 333 |
if results:
|
| 334 |
+
formatted = "\n\n### نتائج البحث:\n\n"
|
| 335 |
for i, r in enumerate(results[:5], 1):
|
| 336 |
formatted += f"**{i}. {r.get('title', '')}**\n"
|
| 337 |
formatted += f" {r.get('snippet', '')[:200]}\n"
|
|
|
|
| 344 |
logger.info(f"[tool] Image search: {query[:100]}")
|
| 345 |
images = image_search(query)
|
| 346 |
if images:
|
| 347 |
+
formatted = "\n\n### الصور:\n\n"
|
| 348 |
for i, img in enumerate(images[:4], 1):
|
| 349 |
formatted += f"})\n\n"
|
| 350 |
return formatted
|
|
|
|
| 554 |
except json.JSONDecodeError:
|
| 555 |
continue
|
| 556 |
|
| 557 |
+
# استخراج وتنفيذ الأداة بعد اكتمال الرد
|
| 558 |
if not tool_executed:
|
| 559 |
tool = extract_tool_from_text(full_response)
|
| 560 |
if tool:
|
|
|
|
| 572 |
yield f"data: {json.dumps({'delta': tool_result})}\n\n"
|
| 573 |
except Exception as tool_error:
|
| 574 |
logger.error(f"[tool] Error: {tool_error}")
|
| 575 |
+
error_msg = "\n\n⚠️ خطأ في تنفيذ الأداة: " + str(tool_error) + "\n\n"
|
| 576 |
+
yield f"data: {json.dumps({'delta': error_msg})}\n\n"
|
| 577 |
|
| 578 |
yield f"data: {json.dumps({'done': True})}\n\n"
|
| 579 |
return
|
|
|
|
| 727 |
|
| 728 |
if __name__ == '__main__':
|
| 729 |
port = int(os.environ.get('PORT', 7860))
|
| 730 |
+
logger.info(f"Genisi running on port {port} | Flash: {FLASH_MODEL} | Search: local | Video: disabled")
|
| 731 |
app.run(host='0.0.0.0', port=port, threaded=True)
|