Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,12 @@
|
|
1 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
2 |
-
import datetime
|
3 |
-
import requests
|
4 |
-
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
7 |
|
8 |
-
#
|
9 |
-
search_tool = DuckDuckGoSearchTool(max_results=5)
|
10 |
|
11 |
-
#
|
12 |
@tool
|
13 |
def extract_summary_from_text(text: str) -> str:
|
14 |
"""Extracts a short summary from the given text.
|
@@ -17,7 +15,7 @@ def extract_summary_from_text(text: str) -> str:
|
|
17 |
"""
|
18 |
return text[:300] + "..." if len(text) > 300 else text
|
19 |
|
20 |
-
#
|
21 |
model = HfApiModel(
|
22 |
max_tokens=2096,
|
23 |
temperature=0.5,
|
@@ -25,12 +23,12 @@ model = HfApiModel(
|
|
25 |
custom_role_conversions=None,
|
26 |
)
|
27 |
|
28 |
-
#
|
29 |
with open("prompts.yaml", 'r') as stream:
|
30 |
prompt_templates = yaml.safe_load(stream)
|
31 |
|
32 |
-
#
|
33 |
-
agent =
|
34 |
model=model,
|
35 |
tools=[search_tool, extract_summary_from_text, FinalAnswerTool()], # Add tools
|
36 |
max_steps=6,
|
@@ -42,5 +40,5 @@ agent = WebAgent(
|
|
42 |
prompt_templates=prompt_templates
|
43 |
)
|
44 |
|
45 |
-
#
|
46 |
-
GradioUI(agent).launch()
|
|
|
1 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
|
|
|
|
|
|
2 |
import yaml
|
3 |
from tools.final_answer import FinalAnswerTool
|
4 |
+
from Gradio_UI import GradioUI
|
5 |
|
6 |
+
# Import the DuckDuckGo search tool
|
7 |
+
search_tool = DuckDuckGoSearchTool(max_results=5)
|
8 |
|
9 |
+
# Custom summarization tool
|
10 |
@tool
|
11 |
def extract_summary_from_text(text: str) -> str:
|
12 |
"""Extracts a short summary from the given text.
|
|
|
15 |
"""
|
16 |
return text[:300] + "..." if len(text) > 300 else text
|
17 |
|
18 |
+
# Hugging Face API model
|
19 |
model = HfApiModel(
|
20 |
max_tokens=2096,
|
21 |
temperature=0.5,
|
|
|
23 |
custom_role_conversions=None,
|
24 |
)
|
25 |
|
26 |
+
# Load prompt templates
|
27 |
with open("prompts.yaml", 'r') as stream:
|
28 |
prompt_templates = yaml.safe_load(stream)
|
29 |
|
30 |
+
# ✅ Use CodeAgent instead of WebAgent
|
31 |
+
agent = CodeAgent(
|
32 |
model=model,
|
33 |
tools=[search_tool, extract_summary_from_text, FinalAnswerTool()], # Add tools
|
34 |
max_steps=6,
|
|
|
40 |
prompt_templates=prompt_templates
|
41 |
)
|
42 |
|
43 |
+
# Launch Gradio UI
|
44 |
+
GradioUI(agent).launch()
|