hp1318 commited on
Commit
1083af3
·
verified ·
1 Parent(s): 9f6fc09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -7
app.py CHANGED
@@ -32,18 +32,51 @@ def get_current_time_in_timezone(timezone: str) -> str:
32
  return f"The current local time in {timezone} is: {local_time}"
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
 
 
37
  model = HfApiModel(
38
- max_tokens=2096,
39
- temperature=0.5,
40
- model_id='deepseek-ai/DeepSeek-R1-Distill-Qwen-32B', # ✅ New model
41
- custom_role_conversions=None,
42
  )
43
 
44
 
45
- final_answer = FinalAnswerTool()
46
-
47
  # Import tool from Hub
48
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
49
 
@@ -52,7 +85,7 @@ with open("prompts.yaml", 'r') as stream:
52
 
53
  agent = CodeAgent(
54
  model=model,
55
- tools=[final_answer,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
56
  max_steps=6,
57
  verbosity_level=1,
58
  grammar=None,
 
32
  return f"The current local time in {timezone} is: {local_time}"
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
+
36
+ @tool
37
+ def duckduckgo_search(query: str) -> str:
38
+ """Searches DuckDuckGo for a given query and returns the top result.
39
+ Args:
40
+ query: The search query string.
41
+ Returns:
42
+ A short summary with the top DuckDuckGo result.
43
+ """
44
+ search_tool = DuckDuckGoSearchTool()
45
+ results = search_tool.run(query)
46
+
47
+ if results:
48
+ return f"Top search result: {results[0]['title']} - {results[0]['link']}"
49
+ else:
50
+ return "No results found."
51
+
52
+ @tool
53
+ def analyze_sentiment(text: str) -> str:
54
+ """Analyzes the sentiment of a given text (Positive/Negative/Neutral).
55
+ Args:
56
+ text: The input text to analyze.
57
+ Returns:
58
+ A string indicating the sentiment (Positive, Negative, or Neutral).
59
+ """
60
+ # Simple sentiment analysis using keyword matching
61
+ text_lower = text.lower()
62
+ if any(word in text_lower for word in ["good", "great", "awesome", "fantastic", "love", "happy"]):
63
+ return "Sentiment: Positive"
64
+ elif any(word in text_lower for word in ["bad", "terrible", "awful", "hate", "angry", "sad"]):
65
+ return "Sentiment: Negative"
66
+ else:
67
+ return "Sentiment: Neutral"
68
+
69
 
70
 
71
+ final_answer = FinalAnswerTool()
72
  model = HfApiModel(
73
+ max_tokens=2096,
74
+ temperature=0.5,
75
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
76
+ custom_role_conversions=None,
77
  )
78
 
79
 
 
 
80
  # Import tool from Hub
81
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
82
 
 
85
 
86
  agent = CodeAgent(
87
  model=model,
88
+ tools=[final_answer,duckduckgo_search,image_generation_tool,analyze_sentiment], ## add your tools here (don't remove final answer)
89
  max_steps=6,
90
  verbosity_level=1,
91
  grammar=None,