Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,40 +3,40 @@ import os
|
|
| 3 |
import requests
|
| 4 |
import pandas as pd
|
| 5 |
import gradio as gr
|
| 6 |
-
from smolagents import ToolCallingAgent
|
| 7 |
-
from smolagents.models import OpenAIServerModel
|
| 8 |
|
|
|
|
| 9 |
from audio_transcriber import AudioTranscriptionTool
|
| 10 |
from image_analyzer import ImageAnalysisTool
|
| 11 |
from wikipedia_searcher import WikipediaSearcher
|
| 12 |
|
| 13 |
-
DEFAULT_API_URL = "https://
|
| 14 |
|
| 15 |
class GaiaAgent:
|
| 16 |
def __init__(self):
|
| 17 |
-
api_key = os.getenv("OPENAI_API_KEY")
|
| 18 |
-
if not api_key:
|
| 19 |
-
raise EnvironmentError("OPENAI_API_KEY not found in environment variables.")
|
| 20 |
-
|
| 21 |
-
model = OpenAIServerModel(
|
| 22 |
-
model_id="gpt-3.5-turbo",
|
| 23 |
-
api_key=api_key
|
| 24 |
-
)
|
| 25 |
tools = [
|
| 26 |
AudioTranscriptionTool(),
|
| 27 |
ImageAnalysisTool(),
|
| 28 |
WikipediaSearcher()
|
| 29 |
]
|
| 30 |
-
self.agent = ToolCallingAgent(model=model, tools=tools)
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 36 |
space_id = os.getenv("SPACE_ID")
|
| 37 |
|
| 38 |
if profile:
|
| 39 |
username = profile.username
|
|
|
|
|
|
|
|
|
|
| 40 |
print(f"User logged in: {username}")
|
| 41 |
else:
|
| 42 |
print("User not logged in.")
|
|
@@ -118,7 +118,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 118 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 119 |
|
| 120 |
submission_data = {
|
| 121 |
-
"username": username
|
| 122 |
"agent_code": agent_code,
|
| 123 |
"answers": answers_payload
|
| 124 |
}
|
|
@@ -149,6 +149,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 149 |
return f"An unexpected error occurred during submission: {e}", pd.DataFrame(results_log)
|
| 150 |
|
| 151 |
|
|
|
|
| 152 |
with gr.Blocks() as demo:
|
| 153 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
| 154 |
gr.Markdown("""
|
|
@@ -172,16 +173,16 @@ if __name__ == "__main__":
|
|
| 172 |
space_id = os.getenv("SPACE_ID")
|
| 173 |
|
| 174 |
if space_host:
|
| 175 |
-
print(f"
|
| 176 |
print(f" Runtime URL should be: https://{space_host}.hf.space")
|
| 177 |
else:
|
| 178 |
-
print("
|
| 179 |
|
| 180 |
if space_id:
|
| 181 |
-
print(f"
|
| 182 |
print(f" Repo URL: https://huggingface.co/spaces/{space_id}")
|
| 183 |
else:
|
| 184 |
-
print("
|
| 185 |
|
| 186 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 187 |
demo.launch(debug=True, share=False)
|
|
|
|
| 3 |
import requests
|
| 4 |
import pandas as pd
|
| 5 |
import gradio as gr
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
from smolagents import ToolCallingAgent, OpenAIServerModel
|
| 8 |
from audio_transcriber import AudioTranscriptionTool
|
| 9 |
from image_analyzer import ImageAnalysisTool
|
| 10 |
from wikipedia_searcher import WikipediaSearcher
|
| 11 |
|
| 12 |
+
DEFAULT_API_URL = "https://gaia-benchmark.com/api"
|
| 13 |
|
| 14 |
class GaiaAgent:
|
| 15 |
def __init__(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
tools = [
|
| 17 |
AudioTranscriptionTool(),
|
| 18 |
ImageAnalysisTool(),
|
| 19 |
WikipediaSearcher()
|
| 20 |
]
|
|
|
|
| 21 |
|
| 22 |
+
model_id = os.getenv("OPENAI_MODEL_ID", "gpt-3.5-turbo")
|
| 23 |
+
self.agent = ToolCallingAgent(
|
| 24 |
+
model=OpenAIServerModel(model_id=model_id),
|
| 25 |
+
tools=tools
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
def __call__(self, query: str) -> str:
|
| 29 |
+
result = self.agent.run(query)
|
| 30 |
+
return result.get("output", "No output returned")
|
| 31 |
|
| 32 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 33 |
space_id = os.getenv("SPACE_ID")
|
| 34 |
|
| 35 |
if profile:
|
| 36 |
username = profile.username
|
| 37 |
+
if isinstance(username, list):
|
| 38 |
+
username = username[0]
|
| 39 |
+
username = username.strip()
|
| 40 |
print(f"User logged in: {username}")
|
| 41 |
else:
|
| 42 |
print("User not logged in.")
|
|
|
|
| 118 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 119 |
|
| 120 |
submission_data = {
|
| 121 |
+
"username": username,
|
| 122 |
"agent_code": agent_code,
|
| 123 |
"answers": answers_payload
|
| 124 |
}
|
|
|
|
| 149 |
return f"An unexpected error occurred during submission: {e}", pd.DataFrame(results_log)
|
| 150 |
|
| 151 |
|
| 152 |
+
# Gradio UI
|
| 153 |
with gr.Blocks() as demo:
|
| 154 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
| 155 |
gr.Markdown("""
|
|
|
|
| 173 |
space_id = os.getenv("SPACE_ID")
|
| 174 |
|
| 175 |
if space_host:
|
| 176 |
+
print(f"✅ SPACE_HOST found: {space_host}")
|
| 177 |
print(f" Runtime URL should be: https://{space_host}.hf.space")
|
| 178 |
else:
|
| 179 |
+
print("ℹ️ SPACE_HOST not found.")
|
| 180 |
|
| 181 |
if space_id:
|
| 182 |
+
print(f"✅ SPACE_ID found: {space_id}")
|
| 183 |
print(f" Repo URL: https://huggingface.co/spaces/{space_id}")
|
| 184 |
else:
|
| 185 |
+
print("ℹ️ SPACE_ID not found.")
|
| 186 |
|
| 187 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 188 |
demo.launch(debug=True, share=False)
|