Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,88 +0,0 @@
|
|
| 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 |
-
from Gradio_UI import GradioUI
|
| 8 |
-
|
| 9 |
-
# Define a custom tool using the @tool decorator
|
| 10 |
-
@tool
|
| 11 |
-
def my_custom_tool(arg1: str, arg2: int) -> str:
|
| 12 |
-
"""
|
| 13 |
-
A tool that answers customers' queries on working with and as a Virtual Assistant by searching the web and producing a snippet of the first web result in line with parameter arg2.
|
| 14 |
-
|
| 15 |
-
Args:
|
| 16 |
-
arg1: Questions about working with and as a Virtual Assistant. (For example; Why should I hire a Virtual Assistant?, What courses do I need to complete to become a Virtual Assistant?)
|
| 17 |
-
arg2: 200 characters.
|
| 18 |
-
"""
|
| 19 |
-
return f"Processed {arg1} with value {arg2}"
|
| 20 |
-
|
| 21 |
-
# Define the FAQ bot tool using web search
|
| 22 |
-
@tool
|
| 23 |
-
def faq_bot_tool(query: str) -> str:
|
| 24 |
-
"""
|
| 25 |
-
A tool that answers frequently asked questions about virtual assistants by searching the web.
|
| 26 |
-
|
| 27 |
-
Args:
|
| 28 |
-
query: The question asked by the user.
|
| 29 |
-
"""
|
| 30 |
-
try:
|
| 31 |
-
# Initialize the web search tool
|
| 32 |
-
web_search_tool = DuckDuckGoSearchTool()
|
| 33 |
-
|
| 34 |
-
# Perform a web search using the query
|
| 35 |
-
search_results = web_search_tool.search(query)
|
| 36 |
-
|
| 37 |
-
# Extract relevant information from the search results
|
| 38 |
-
if search_results:
|
| 39 |
-
# For simplicity, return the first result's snippet
|
| 40 |
-
first_result = search_results[0]
|
| 41 |
-
return first_result.get('snippet', 'No relevant information found.')
|
| 42 |
-
else:
|
| 43 |
-
return "Sorry, I couldn't find any relevant information."
|
| 44 |
-
except Exception as e:
|
| 45 |
-
return f"An error occurred while searching: {str(e)}"
|
| 46 |
-
|
| 47 |
-
@tool
|
| 48 |
-
def get_current_time_in_timezone(timezone: str) -> str:
|
| 49 |
-
"""A tool that fetches the current local time in a specified timezone.
|
| 50 |
-
Args:
|
| 51 |
-
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 52 |
-
"""
|
| 53 |
-
try:
|
| 54 |
-
# Create timezone object
|
| 55 |
-
tz = pytz.timezone(timezone)
|
| 56 |
-
# Get current time in that timezone
|
| 57 |
-
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 58 |
-
return f"The current local time in {timezone} is: {local_time}"
|
| 59 |
-
except Exception as e:
|
| 60 |
-
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 61 |
-
|
| 62 |
-
final_answer = FinalAnswerTool()
|
| 63 |
-
model = HfApiModel(
|
| 64 |
-
max_tokens=2096,
|
| 65 |
-
temperature=0.5,
|
| 66 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 67 |
-
custom_role_conversions=None,
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
# Import tool from Hub
|
| 71 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 72 |
-
|
| 73 |
-
with open("prompts.yaml", 'r') as stream:
|
| 74 |
-
prompt_templates = yaml.safe_load(stream)
|
| 75 |
-
|
| 76 |
-
agent = CodeAgent(
|
| 77 |
-
model=model,
|
| 78 |
-
tools=[final_answer, faq_bot_tool], # Add the FAQ bot tool here
|
| 79 |
-
max_steps=6,
|
| 80 |
-
verbosity_level=1,
|
| 81 |
-
grammar=None,
|
| 82 |
-
planning_interval=None,
|
| 83 |
-
name=None,
|
| 84 |
-
description=None,
|
| 85 |
-
prompt_templates=prompt_templates
|
| 86 |
-
)
|
| 87 |
-
|
| 88 |
-
GradioUI(agent).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|