Update app.py
Browse files
app.py
CHANGED
@@ -10,10 +10,22 @@ from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
|
10 |
|
11 |
from groq_api import GrokApi
|
12 |
|
|
|
13 |
|
14 |
|
15 |
-
|
|
|
|
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
|
19 |
|
@@ -36,6 +48,9 @@ def run_and_submit_all(nb_questions: int, profile: gr.OAuthProfile | None):
|
|
36 |
Fetches all questions, runs my Agent on them, submits all answers,
|
37 |
and displays the results.
|
38 |
"""
|
|
|
|
|
|
|
39 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
40 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
41 |
|
@@ -90,8 +105,12 @@ def run_and_submit_all(nb_questions: int, profile: gr.OAuthProfile | None):
|
|
90 |
# for testing keep only some questions
|
91 |
questions_data = questions_data[:nb_questions]
|
92 |
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
95 |
task_id = item.get("task_id")
|
96 |
question_text = item.get("question")
|
97 |
file_name = item.get("file_name")
|
@@ -107,13 +126,20 @@ def run_and_submit_all(nb_questions: int, profile: gr.OAuthProfile | None):
|
|
107 |
agent_question += f"\n\nFile URL: {file_question_url}"
|
108 |
|
109 |
submitted_answer = agent(agent_question)
|
|
|
110 |
|
111 |
-
|
|
|
|
|
112 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
113 |
except Exception as e:
|
114 |
print(f"Error running agent on task {task_id}: {e}")
|
115 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
116 |
|
|
|
|
|
|
|
|
|
117 |
if not answers_payload:
|
118 |
print("Agent did not produce any answers to submit.")
|
119 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
|
|
10 |
|
11 |
from groq_api import GrokApi
|
12 |
|
13 |
+
My_Agent = MultiAgent
|
14 |
|
15 |
|
16 |
+
import json
|
17 |
+
|
18 |
+
CACHE_FILE = "answers_cache.json"
|
19 |
|
20 |
+
def load_cached_answers():
|
21 |
+
if os.path.exists(CACHE_FILE):
|
22 |
+
with open(CACHE_FILE, "r") as f:
|
23 |
+
return json.load(f)
|
24 |
+
return {}
|
25 |
+
|
26 |
+
def save_cached_answers(cache):
|
27 |
+
with open(CACHE_FILE, "w") as f:
|
28 |
+
json.dump(cache, f)
|
29 |
|
30 |
|
31 |
|
|
|
48 |
Fetches all questions, runs my Agent on them, submits all answers,
|
49 |
and displays the results.
|
50 |
"""
|
51 |
+
|
52 |
+
cached_answers = load_cached_answers()
|
53 |
+
|
54 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
55 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
56 |
|
|
|
105 |
# for testing keep only some questions
|
106 |
questions_data = questions_data[:nb_questions]
|
107 |
|
108 |
+
new_questions = [q for q in questions_data if q["task_id"] not in cached_answers]
|
109 |
+
|
110 |
+
answers_payload_new = []
|
111 |
+
|
112 |
+
print(f"Running agent on {len(new_questions)} questions...")
|
113 |
+
for item in new_questions:
|
114 |
task_id = item.get("task_id")
|
115 |
question_text = item.get("question")
|
116 |
file_name = item.get("file_name")
|
|
|
126 |
agent_question += f"\n\nFile URL: {file_question_url}"
|
127 |
|
128 |
submitted_answer = agent(agent_question)
|
129 |
+
answers_payload_new.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
130 |
|
131 |
+
cached_answers[task_id] = submitted_answer
|
132 |
+
|
133 |
+
#answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
134 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
135 |
except Exception as e:
|
136 |
print(f"Error running agent on task {task_id}: {e}")
|
137 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
138 |
|
139 |
+
save_cached_answers(cached_answers)
|
140 |
+
answers_payload = [{"task_id": k, "submitted_answer": v} for k, v in cached_answers.items()]
|
141 |
+
|
142 |
+
|
143 |
if not answers_payload:
|
144 |
print("Agent did not produce any answers to submit.")
|
145 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|