cowrycode commited on
Commit
9accbf6
·
verified ·
1 Parent(s): b56e115

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -39,14 +39,23 @@ class BasicAgent:
39
  return answer
40
 
41
  def __call__(self, question: str) -> str:
42
- return self.run(question)
 
 
 
 
 
 
 
 
 
43
  #print(f"Agent received question (first 50 chars): {question[:50]}...")
44
  #fixed_answer = "This is a default answer."
45
  #fixed_answer = self.llamaindex_agent.run(question)
46
  #print(f"Agent returning fixed answer: {fixed_answer}")
47
  #return fixed_answer
48
 
49
- async def run_and_submit_all( profile: gr.OAuthProfile | None):
50
  """
51
  Fetches all questions, runs the BasicAgent on them, submits all answers,
52
  and displays the results.
@@ -67,7 +76,7 @@ async def run_and_submit_all( profile: gr.OAuthProfile | None):
67
 
68
  # 1. Instantiate Agent ( modify this part to create your agent)
69
  try:
70
- agent = await BasicAgent()
71
  except Exception as e:
72
  print(f"Error instantiating agent: {e}")
73
  return f"Error initializing agent: {e}", None
 
39
  return answer
40
 
41
  def __call__(self, question: str) -> str:
42
+ #return self.run(question)
43
+
44
+ try:
45
+ loop = asyncio.get_running_loop() # already inside async environment?
46
+ return loop.run_until_complete(self.run(question))
47
+ except RuntimeError:
48
+ # no running loop → safe to create one
49
+ return asyncio.run(self.run(question))
50
+
51
+
52
  #print(f"Agent received question (first 50 chars): {question[:50]}...")
53
  #fixed_answer = "This is a default answer."
54
  #fixed_answer = self.llamaindex_agent.run(question)
55
  #print(f"Agent returning fixed answer: {fixed_answer}")
56
  #return fixed_answer
57
 
58
+ def run_and_submit_all( profile: gr.OAuthProfile | None):
59
  """
60
  Fetches all questions, runs the BasicAgent on them, submits all answers,
61
  and displays the results.
 
76
 
77
  # 1. Instantiate Agent ( modify this part to create your agent)
78
  try:
79
+ agent = BasicAgent()
80
  except Exception as e:
81
  print(f"Error instantiating agent: {e}")
82
  return f"Error initializing agent: {e}", None