Spaces:
Runtime error
Runtime error
Abdulbaki Aybakan commited on
Commit ·
8066953
1
Parent(s): 81917a3
Added smolagents
Browse files
app.py
CHANGED
|
@@ -2,7 +2,10 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import inspect
|
|
|
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -10,14 +13,27 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
print("BasicAgent initialized.")
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
@@ -193,4 +209,4 @@ if __name__ == "__main__":
|
|
| 193 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 194 |
|
| 195 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
| 196 |
-
demo.launch(debug=True, share=False)
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
+
import time
|
| 6 |
import pandas as pd
|
| 7 |
+
import os
|
| 8 |
+
from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool
|
| 9 |
|
| 10 |
# (Keep Constants as is)
|
| 11 |
# --- Constants ---
|
|
|
|
| 13 |
|
| 14 |
# --- Basic Agent Definition ---
|
| 15 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 16 |
+
model_id = "gemini/gemini-2.0-flash-001"
|
| 17 |
+
model = LiteLLMModel(
|
| 18 |
+
model_id=model_id,
|
| 19 |
+
api_key=os.environ.get("GOOGLE_API_KEY", "")
|
| 20 |
+
)
|
| 21 |
+
search_tool = DuckDuckGoSearchTool()
|
| 22 |
+
agent_with_search = CodeAgent(tools=[search_tool], model=model, add_base_tools=True)
|
| 23 |
+
|
| 24 |
class BasicAgent:
|
| 25 |
def __init__(self):
|
| 26 |
print("BasicAgent initialized.")
|
| 27 |
def __call__(self, question: str) -> str:
|
| 28 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 29 |
+
try:
|
| 30 |
+
answer = agent_with_search.run(question)
|
| 31 |
+
print(f"Agent returning answer: {answer}")
|
| 32 |
+
time.sleep(30)
|
| 33 |
+
return answer
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"Error running agent: {e}")
|
| 36 |
+
return f"Agent Error: {e}"
|
| 37 |
|
| 38 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 39 |
"""
|
|
|
|
| 209 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 210 |
|
| 211 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
| 212 |
+
demo.launch(debug=True, share=False)
|