Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -245,11 +245,11 @@ class GaiaRunner:
|
|
| 245 |
self.username = username
|
| 246 |
|
| 247 |
def run_on_question(self, question_text: str, file: Optional[str] = None) -> str:
|
| 248 |
-
|
| 249 |
-
|
| 250 |
|
| 251 |
-
|
| 252 |
-
|
| 253 |
# حماية استدعاء الـ agent (langchain / llama-cpp) من الوصول المتوازي
|
| 254 |
with llama_lock:
|
| 255 |
result = self.agent.invoke({"input": prompt})
|
|
@@ -257,20 +257,20 @@ class GaiaRunner:
|
|
| 257 |
output = result.get("output") or result.get("text") or str(result)
|
| 258 |
else:
|
| 259 |
output = getattr(result, "output", str(result))
|
| 260 |
-
|
| 261 |
logger.exception("Agent execution failed")
|
| 262 |
output = f"AGENT_ERROR: {e}"
|
| 263 |
|
| 264 |
-
|
| 265 |
final_out = final_client.predict_text(output)
|
| 266 |
-
|
| 267 |
logger.exception("Final client failed")
|
| 268 |
final_out = f"FINAL_AGENT_ERROR: {e}"
|
| 269 |
|
| 270 |
-
|
| 271 |
-
|
| 272 |
|
| 273 |
-
|
| 274 |
|
| 275 |
def run_all_and_submit(self) -> Dict[str, Any]:
|
| 276 |
questions_url =f"{GAIA_API_BASE}/questions"
|
|
|
|
| 245 |
self.username = username
|
| 246 |
|
| 247 |
def run_on_question(self, question_text: str, file: Optional[str] = None) -> str:
|
| 248 |
+
import time
|
| 249 |
+
start = time.time()
|
| 250 |
|
| 251 |
+
prompt = SYSTEM_INSTRUCTIONS + "\n\n" + question_text
|
| 252 |
+
try:
|
| 253 |
# حماية استدعاء الـ agent (langchain / llama-cpp) من الوصول المتوازي
|
| 254 |
with llama_lock:
|
| 255 |
result = self.agent.invoke({"input": prompt})
|
|
|
|
| 257 |
output = result.get("output") or result.get("text") or str(result)
|
| 258 |
else:
|
| 259 |
output = getattr(result, "output", str(result))
|
| 260 |
+
except Exception as e:
|
| 261 |
logger.exception("Agent execution failed")
|
| 262 |
output = f"AGENT_ERROR: {e}"
|
| 263 |
|
| 264 |
+
try:
|
| 265 |
final_out = final_client.predict_text(output)
|
| 266 |
+
except Exception as e:
|
| 267 |
logger.exception("Final client failed")
|
| 268 |
final_out = f"FINAL_AGENT_ERROR: {e}"
|
| 269 |
|
| 270 |
+
end = time.time()
|
| 271 |
+
logger.info(f"⏱️ Time for question: {end - start:.2f} sec")
|
| 272 |
|
| 273 |
+
return final_out
|
| 274 |
|
| 275 |
def run_all_and_submit(self) -> Dict[str, Any]:
|
| 276 |
questions_url =f"{GAIA_API_BASE}/questions"
|