Update app.py
Browse files
app.py
CHANGED
|
@@ -3,20 +3,26 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from
|
|
|
|
|
|
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
-
DEFAULT_API_URL =
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
-
class
|
| 14 |
def __init__(self):
|
|
|
|
|
|
|
| 15 |
print("BasicAgent initialized.")
|
| 16 |
-
def __call__(self,
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 22 |
"""
|
|
@@ -39,7 +45,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 39 |
|
| 40 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 41 |
try:
|
| 42 |
-
agent =
|
| 43 |
except Exception as e:
|
| 44 |
print(f"Error instantiating agent: {e}")
|
| 45 |
return f"Error initializing agent: {e}", None
|
|
@@ -75,11 +81,12 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 75 |
for item in questions_data:
|
| 76 |
task_id = item.get("task_id")
|
| 77 |
question_text = item.get("question")
|
|
|
|
| 78 |
if not task_id or question_text is None:
|
| 79 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 80 |
continue
|
| 81 |
try:
|
| 82 |
-
submitted_answer = agent(question_text)
|
| 83 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 84 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 85 |
except Exception as e:
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from agent import BasicAgent
|
| 7 |
+
from constants import DEFAULT_API_URL, OPENROUTER_MODEL
|
| 8 |
+
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
| 11 |
+
DEFAULT_API_URL = DEFAULT_API_URL
|
| 12 |
+
OPENROUTER_API = os.getenv("OPENROUTER_API")
|
| 13 |
+
OPENROUTER_MODEL = OPENROUTER_MODEL
|
| 14 |
|
| 15 |
# --- Basic Agent Definition ---
|
| 16 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 17 |
+
class Agent:
|
| 18 |
def __init__(self):
|
| 19 |
+
self.agent = BasicAgent(OPENROUTER_API, OPENROUTER_MODEL, DEFAULT_API_URL)
|
| 20 |
+
self.agent.initialize_agent()
|
| 21 |
print("BasicAgent initialized.")
|
| 22 |
+
def __call__(self, input: tuple):
|
| 23 |
+
return self.agent.run(input)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
|
| 27 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 28 |
"""
|
|
|
|
| 45 |
|
| 46 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 47 |
try:
|
| 48 |
+
agent = Agent()
|
| 49 |
except Exception as e:
|
| 50 |
print(f"Error instantiating agent: {e}")
|
| 51 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 81 |
for item in questions_data:
|
| 82 |
task_id = item.get("task_id")
|
| 83 |
question_text = item.get("question")
|
| 84 |
+
file_name = item.get("file_name")
|
| 85 |
if not task_id or question_text is None:
|
| 86 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 87 |
continue
|
| 88 |
try:
|
| 89 |
+
submitted_answer = agent(input=(task_id, question_text, file_name))
|
| 90 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 91 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 92 |
except Exception as e:
|