Update app.py
Browse files
app.py
CHANGED
@@ -3,45 +3,56 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
-
from langchain_tavily import TavilySearch
|
7 |
-
from langgraph.prebuilt import create_react_agent
|
8 |
-
from langchain.chat_models import init_chat_model
|
9 |
-
# from langchain_sandbox import PyodideSandboxTool
|
10 |
|
11 |
# (Keep Constants as is)
|
12 |
# --- Constants ---
|
13 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
14 |
-
OPENAI_API_KEY=os.getenv("OPENAI_API_KEY")
|
15 |
-
TAVILY_API_KEY=os.getenv("TAVILY_API_KEY")
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
)
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
# --- Basic Agent Definition ---
|
25 |
-
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
26 |
class BasicAgent:
|
27 |
def __init__(self):
|
28 |
-
|
29 |
-
self.llm = init_chat_model(model="openai:gpt-4.1")
|
30 |
-
self.agent = create_react_agent(
|
31 |
-
model=self.llm,
|
32 |
-
tools=[websearch_tool],
|
33 |
-
prompt="You are a helpful assistant. You can use websearch tool to answer some questions."
|
34 |
-
)
|
35 |
-
print("BasicAgent initialized.")
|
36 |
-
except Exception as e:
|
37 |
-
print(f"Failed to initialize BasicAgent: {e}")
|
38 |
-
|
39 |
def __call__(self, question: str) -> str:
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
return
|
|
|
|
|
44 |
|
|
|
45 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
46 |
"""
|
47 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
@@ -216,4 +227,4 @@ if __name__ == "__main__":
|
|
216 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
217 |
|
218 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
219 |
-
demo.launch(debug=True, share=False)
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
|
10 |
|
11 |
+
# --- My code ---
|
12 |
+
"""
|
13 |
+
Tools needed :
|
14 |
+
- Websearch - OK
|
15 |
+
- Access web page - OK
|
16 |
+
- PY analyser (for 1 response) - OK
|
17 |
+
- Transcript (for 2 responses)
|
18 |
+
- xlsx analyser (for 1 response)
|
19 |
+
- Image analyser (for 1 response)
|
20 |
+
- Youtube video Analyser (for 2 response)
|
21 |
+
|
22 |
+
|
23 |
+
Features needed :
|
24 |
+
- Planning and reasoning - OK
|
25 |
+
- Tool calling - OK
|
26 |
+
- Get the associated file (for 5 response)
|
27 |
+
"""
|
28 |
+
|
29 |
+
from smolagents import CodeAgent, OpenAIServerModel, tool, DuckDuckGoSearchTool
|
30 |
+
import os
|
31 |
+
|
32 |
+
model = OpenAIServerModel(
|
33 |
+
model_id="gpt-4.1",
|
34 |
+
api_key=os.getenv("OPENAI_API_KEY"),
|
35 |
)
|
36 |
|
37 |
+
agent = CodeAgent(
|
38 |
+
tools=[],
|
39 |
+
model=model,
|
40 |
+
add_base_tools=True, # default tools are : DuckDuckGo web search / Python code interpreter / speech-to-text (? doesn't seam to work)
|
41 |
+
planning_interval=3 # Planning and reasoning
|
42 |
+
)
|
43 |
|
|
|
|
|
44 |
class BasicAgent:
|
45 |
def __init__(self):
|
46 |
+
print("Smolagent initialized.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
def __call__(self, question: str) -> str:
|
48 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
49 |
+
answer = agent.run(question)
|
50 |
+
print(f"Agent answer: {answer}")
|
51 |
+
return answer
|
52 |
+
|
53 |
+
|
54 |
|
55 |
+
# --- Default code below ---
|
56 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
57 |
"""
|
58 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
227 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
228 |
|
229 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
230 |
+
demo.launch(debug=True, share=False)
|