Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,13 +31,46 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
31 |
except Exception as e:
|
32 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
final_answer = FinalAnswerTool()
|
36 |
model = HfApiModel(
|
37 |
max_tokens=2096,
|
38 |
temperature=0.5,
|
39 |
-
|
40 |
-
model_id="deepseek-ai/DeepSeek-R1",
|
41 |
custom_role_conversions=None,
|
42 |
)
|
43 |
|
@@ -50,7 +83,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
50 |
|
51 |
agent = CodeAgent(
|
52 |
model=model,
|
53 |
-
tools=[
|
54 |
max_steps=6,
|
55 |
verbosity_level=1,
|
56 |
grammar=None,
|
|
|
31 |
except Exception as e:
|
32 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
33 |
|
34 |
+
@tool
|
35 |
+
def duckduckgo_search(query: str) -> str:
|
36 |
+
"""Searches DuckDuckGo for a given query and returns the top result.
|
37 |
+
Args:
|
38 |
+
query: The search query string.
|
39 |
+
Returns:
|
40 |
+
A short summary with the top DuckDuckGo result.
|
41 |
+
"""
|
42 |
+
search_tool = DuckDuckGoSearchTool()
|
43 |
+
results = search_tool.run(query)
|
44 |
+
|
45 |
+
if results:
|
46 |
+
return f"Top search result: {results[0]['title']} - {results[0]['link']}"
|
47 |
+
else:
|
48 |
+
return "No results found."
|
49 |
+
|
50 |
+
@tool
|
51 |
+
def get_sentiment(text: str) -> str:
|
52 |
+
"""Analyze the sentiment of the given text (Positive/Negative/Neutral)
|
53 |
+
|
54 |
+
Args:
|
55 |
+
text: The input text to analyze. (e.g., 'I am so happy today!')
|
56 |
+
|
57 |
+
Returns:
|
58 |
+
A string indicating the sentiment (Positive, Negative, or Neutral).
|
59 |
+
"""
|
60 |
+
text_lower = text.lower()
|
61 |
+
if any(word in text_lower for word in ["good", "great", "awesome", "fantastic", "love", "happy"]):
|
62 |
+
return "Sentiment: Positive"
|
63 |
+
elif any(word in text_lower for word in ["bad", "terrible", "awful", "hate", "angry", "sad"]):
|
64 |
+
return "Sentiment: Negative"
|
65 |
+
else:
|
66 |
+
return "Sentiment: Neutral"
|
67 |
|
68 |
final_answer = FinalAnswerTool()
|
69 |
model = HfApiModel(
|
70 |
max_tokens=2096,
|
71 |
temperature=0.5,
|
72 |
+
model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
|
73 |
+
#model_id="deepseek-ai/DeepSeek-R1",
|
74 |
custom_role_conversions=None,
|
75 |
)
|
76 |
|
|
|
83 |
|
84 |
agent = CodeAgent(
|
85 |
model=model,
|
86 |
+
tools=[image_generation_tool, add_numbers, duckduckgo_search, get_current_time_in_timezone,final_answer], ## add your tools here (don't remove final answer)
|
87 |
max_steps=6,
|
88 |
verbosity_level=1,
|
89 |
grammar=None,
|