Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
|
|
|
|
|
| 1 |
from duckduckgo_search import DDGS
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
@tool
|
| 5 |
def duckduckgo_search(query: str, max_results: int = 5) -> str:
|
|
@@ -28,4 +34,34 @@ def duckduckgo_search(query: str, max_results: int = 5) -> str:
|
|
| 28 |
return "\n".join(output) if output else "No results found."
|
| 29 |
|
| 30 |
except Exception as e:
|
| 31 |
-
return f"Search failed due to error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, HfApiModel, load_tool, tool
|
| 2 |
+
from tools.final_answer import FinalAnswerTool
|
| 3 |
from duckduckgo_search import DDGS
|
| 4 |
+
import datetime
|
| 5 |
+
import pytz
|
| 6 |
+
import yaml
|
| 7 |
+
from Gradio_UI import GradioUI
|
| 8 |
+
|
| 9 |
|
| 10 |
@tool
|
| 11 |
def duckduckgo_search(query: str, max_results: int = 5) -> str:
|
|
|
|
| 34 |
return "\n".join(output) if output else "No results found."
|
| 35 |
|
| 36 |
except Exception as e:
|
| 37 |
+
return f"Search failed due to error: {str(e)}"
|
| 38 |
+
|
| 39 |
+
@tool
|
| 40 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
| 41 |
+
"""Get current time in a timezone."""
|
| 42 |
+
tz = pytz.timezone(timezone)
|
| 43 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 44 |
+
return f"The current time in {timezone} is {local_time}"
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
final_answer = FinalAnswerTool()
|
| 48 |
+
|
| 49 |
+
model = HfApiModel(
|
| 50 |
+
max_tokens=2096,
|
| 51 |
+
temperature=0.5,
|
| 52 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
with open("prompts.yaml", "r") as stream:
|
| 56 |
+
prompt_templates = yaml.safe_load(stream)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
agent = CodeAgent(
|
| 60 |
+
model=model,
|
| 61 |
+
tools=[duckduckgo_search, get_current_time_in_timezone, final_answer],
|
| 62 |
+
max_steps=6,
|
| 63 |
+
verbosity_level=1,
|
| 64 |
+
prompt_templates=prompt_templates
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
GradioUI(agent).launch()
|