melomba2 commited on
Commit
2814cf2
·
verified ·
1 Parent(s): 144af19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -23,7 +23,7 @@ class BasicAgent:
23
  raise ValueError("GOOGLE_API_KEY environment variable not set. Please set it in your Hugging Face Space secrets.")
24
 
25
  genai.configure(api_key=api_key)
26
- self.model = genai.GenerativeModel('gemini-2.5-pro')
27
  print("Gemini Agent initialized successfully.")
28
 
29
  def __call__(self, question: str) -> str:
@@ -41,7 +41,7 @@ class BasicAgent:
41
  print(f"Error calling Gemini API: {e}")
42
  return f"Error during Gemini API call: {e}"
43
  @spaces.GPU
44
- async def run_and_submit_all( profile: gr.OAuthProfile | None):
45
  """
46
  Fetches all questions, runs the BasicAgent on them asynchronously,
47
  caches the answers, submits all answers, and displays the results.
@@ -127,12 +127,16 @@ async def run_and_submit_all( profile: gr.OAuthProfile | None):
127
  # Do not create a payload for submission in case of an error
128
  return log_entry, None
129
 
130
- print(f"Running agent on {len(questions_data)} questions asynchronously...")
131
- tasks = [process_question(item, agent) for item in questions_data]
132
- results = await asyncio.gather(*tasks)
 
133
 
134
- results_log = [res[0] for res in results if res and res[0] is not None]
135
- answers_payload = [res[1] for res in results if res and res[1] is not None]
 
 
 
136
 
137
  if not answers_payload:
138
  print("Agent did not produce any answers to submit.")
 
23
  raise ValueError("GOOGLE_API_KEY environment variable not set. Please set it in your Hugging Face Space secrets.")
24
 
25
  genai.configure(api_key=api_key)
26
+ self.model = genai.GenerativeModel('gemini-pro')
27
  print("Gemini Agent initialized successfully.")
28
 
29
  def __call__(self, question: str) -> str:
 
41
  print(f"Error calling Gemini API: {e}")
42
  return f"Error during Gemini API call: {e}"
43
  @spaces.GPU
44
+ def run_and_submit_all( profile: gr.OAuthProfile | None):
45
  """
46
  Fetches all questions, runs the BasicAgent on them asynchronously,
47
  caches the answers, submits all answers, and displays the results.
 
127
  # Do not create a payload for submission in case of an error
128
  return log_entry, None
129
 
130
+ async def run_all_questions_async():
131
+ print(f"Running agent on {len(questions_data)} questions asynchronously...")
132
+ tasks = [process_question(item, agent) for item in questions_data]
133
+ results = await asyncio.gather(*tasks)
134
 
135
+ results_log = [res[0] for res in results if res and res[0] is not None]
136
+ answers_payload = [res[1] for res in results if res and res[1] is not None]
137
+ return results_log, answers_payload
138
+
139
+ results_log, answers_payload = asyncio.run(run_all_questions_async())
140
 
141
  if not answers_payload:
142
  print("Agent did not produce any answers to submit.")