Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
| 4 |
import gradio as gr
|
|
@@ -19,9 +18,7 @@ model = InferenceClientModel(
|
|
| 19 |
agent = CodeAgent(
|
| 20 |
tools=[DuckDuckGoSearchTool()],
|
| 21 |
model=model,
|
| 22 |
-
additional_authorized_imports=[
|
| 23 |
-
"math", "re", "json", "datetime", "pandas"
|
| 24 |
-
],
|
| 25 |
max_steps=6
|
| 26 |
)
|
| 27 |
|
|
@@ -29,11 +26,8 @@ agent = CodeAgent(
|
|
| 29 |
def get_attachment(task_id):
|
| 30 |
"""Download and read spreadsheet attachments, if available."""
|
| 31 |
try:
|
| 32 |
-
response = requests.get(
|
| 33 |
-
f"{API_URL}/files/{task_id}", timeout=30
|
| 34 |
-
)
|
| 35 |
response.raise_for_status()
|
| 36 |
-
|
| 37 |
data = BytesIO(response.content)
|
| 38 |
|
| 39 |
try:
|
|
@@ -103,18 +97,12 @@ def run_evaluation(profile: gr.OAuthProfile | None):
|
|
| 103 |
if item.get("file_name"):
|
| 104 |
attachment = get_attachment(task_id)
|
| 105 |
|
| 106 |
-
|
| 107 |
|
|
|
|
| 108 |
if answer.startswith("Agent error:"):
|
| 109 |
log += f"Model inference failed: {answer}\n"
|
| 110 |
-
return log + "\nNo answers submitted.
|
| 111 |
-
|
| 112 |
-
answers.append({
|
| 113 |
-
"task_id": task_id,
|
| 114 |
-
"submitted_answer": answer
|
| 115 |
-
})
|
| 116 |
-
|
| 117 |
-
log += f"Answer: {answer}\n"
|
| 118 |
|
| 119 |
answers.append({
|
| 120 |
"task_id": task_id,
|
|
@@ -123,7 +111,7 @@ def run_evaluation(profile: gr.OAuthProfile | None):
|
|
| 123 |
|
| 124 |
log += f"Answer: {answer}\n"
|
| 125 |
|
| 126 |
-
# Submit answers to
|
| 127 |
payload = {
|
| 128 |
"username": username,
|
| 129 |
"agent_code": AGENT_CODE_URL,
|
|
@@ -178,4 +166,4 @@ with gr.Blocks() as demo:
|
|
| 178 |
|
| 179 |
|
| 180 |
if __name__ == "__main__":
|
| 181 |
-
demo.launch()
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
import pandas as pd
|
| 3 |
import gradio as gr
|
|
|
|
| 18 |
agent = CodeAgent(
|
| 19 |
tools=[DuckDuckGoSearchTool()],
|
| 20 |
model=model,
|
| 21 |
+
additional_authorized_imports=["math", "re", "json", "datetime", "pandas"],
|
|
|
|
|
|
|
| 22 |
max_steps=6
|
| 23 |
)
|
| 24 |
|
|
|
|
| 26 |
def get_attachment(task_id):
|
| 27 |
"""Download and read spreadsheet attachments, if available."""
|
| 28 |
try:
|
| 29 |
+
response = requests.get(f"{API_URL}/files/{task_id}", timeout=30)
|
|
|
|
|
|
|
| 30 |
response.raise_for_status()
|
|
|
|
| 31 |
data = BytesIO(response.content)
|
| 32 |
|
| 33 |
try:
|
|
|
|
| 97 |
if item.get("file_name"):
|
| 98 |
attachment = get_attachment(task_id)
|
| 99 |
|
| 100 |
+
answer = answer_question(question, attachment)
|
| 101 |
|
| 102 |
+
# Stop if model inference fails
|
| 103 |
if answer.startswith("Agent error:"):
|
| 104 |
log += f"Model inference failed: {answer}\n"
|
| 105 |
+
return log + "\nNo answers submitted. Fix model inference first.", answers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
answers.append({
|
| 108 |
"task_id": task_id,
|
|
|
|
| 111 |
|
| 112 |
log += f"Answer: {answer}\n"
|
| 113 |
|
| 114 |
+
# Submit answers to official scoring API
|
| 115 |
payload = {
|
| 116 |
"username": username,
|
| 117 |
"agent_code": AGENT_CODE_URL,
|
|
|
|
| 166 |
|
| 167 |
|
| 168 |
if __name__ == "__main__":
|
| 169 |
+
demo.launch()
|