Update app.py
Browse files
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-
|
| 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 |
-
|
| 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 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
| 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.")
|