GoodLuckChuck commited on
Commit
a82d216
·
verified ·
1 Parent(s): 733ec57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -15,7 +15,6 @@ try:
15
  from smolagents import CodeAgent, Tool, OpenAIServerModel
16
  except ImportError:
17
  logging.error("Failed to import smolagents. Please ensure it is installed.")
18
-
19
  # Dummy classes for script parsing if smolagents is not installed
20
  class CodeAgent:
21
  pass
@@ -345,6 +344,9 @@ class QuestionAnsweringAgent(CodeAgent):
345
  return final_answer_for_submission, reasoning_trace
346
 
347
  # --- Agent Adapter for Synchronous Use (e.g., Gradio) ---
 
 
 
348
  class ChuckAgent:
349
  def __init__(self):
350
  required_env_vars = ['OPENAI_API_KEY', 'SERPER_API_KEY']
@@ -369,13 +371,17 @@ class ChuckAgent:
369
  def __call__(self, question: str) -> Tuple[str, str]:
370
  logger.info(f"ChuckAgent received question (first 50 chars): {question[:50]}...")
371
  try:
372
- if asyncio.get_event_loop() is not self.loop:
373
- asyncio.set_event_loop(self.loop)
 
 
 
 
374
 
375
  # Schedule the agent's processing within the current event loop
376
  agent_task = asyncio.ensure_future(self.agent.process_question(question),
377
- loop=self.loop)
378
- final_answer, reasoning_trace = self.loop.run_until_complete(agent_task)
379
 
380
  logger.info(f"ChuckAgent returning answer (first 50 chars): {final_answer[:50]}...")
381
  return final_answer, reasoning_trace
@@ -492,6 +498,7 @@ def submit_answers(base_api_url: str, username: str, agent_code_url: str,
492
  # --- Gradio Interface Main Function ---
493
  GLOBAL_CHUCK_AGENT: Optional[ChuckAgent] = None
494
 
 
495
  def run_and_submit_all_evaluation(profile: Optional[gr.OAuthProfile] = None, *args) -> Tuple[str, pd.DataFrame]:
496
  global GLOBAL_CHUCK_AGENT
497
  logger.info(f"run_and_submit_all_evaluation received profile: {type(profile)}")
 
15
  from smolagents import CodeAgent, Tool, OpenAIServerModel
16
  except ImportError:
17
  logging.error("Failed to import smolagents. Please ensure it is installed.")
 
18
  # Dummy classes for script parsing if smolagents is not installed
19
  class CodeAgent:
20
  pass
 
344
  return final_answer_for_submission, reasoning_trace
345
 
346
  # --- Agent Adapter for Synchronous Use (e.g., Gradio) ---
347
+ GLOBAL_CHUCK_AGENT: Optional[ChuckAgent] = None
348
+
349
+
350
  class ChuckAgent:
351
  def __init__(self):
352
  required_env_vars = ['OPENAI_API_KEY', 'SERPER_API_KEY']
 
371
  def __call__(self, question: str) -> Tuple[str, str]:
372
  logger.info(f"ChuckAgent received question (first 50 chars): {question[:50]}...")
373
  try:
374
+ # Ensure we're using the correct event loop (important in Gradio)
375
+ try:
376
+ loop = asyncio.get_event_loop()
377
+ except RuntimeError:
378
+ loop = asyncio.new_event_loop()
379
+ asyncio.set_event_loop(loop)
380
 
381
  # Schedule the agent's processing within the current event loop
382
  agent_task = asyncio.ensure_future(self.agent.process_question(question),
383
+ loop=loop)
384
+ final_answer, reasoning_trace = loop.run_until_complete(agent_task)
385
 
386
  logger.info(f"ChuckAgent returning answer (first 50 chars): {final_answer[:50]}...")
387
  return final_answer, reasoning_trace
 
498
  # --- Gradio Interface Main Function ---
499
  GLOBAL_CHUCK_AGENT: Optional[ChuckAgent] = None
500
 
501
+
502
  def run_and_submit_all_evaluation(profile: Optional[gr.OAuthProfile] = None, *args) -> Tuple[str, pd.DataFrame]:
503
  global GLOBAL_CHUCK_AGENT
504
  logger.info(f"run_and_submit_all_evaluation received profile: {type(profile)}")