kakimtched commited on
Commit
3622d4c
·
verified ·
1 Parent(s): 86a98c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -11
app.py CHANGED
@@ -1,4 +1,5 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
 
2
  import datetime
3
  import requests
4
  import pytz
@@ -9,8 +10,7 @@ from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
  """A tool that does nothing yet
15
  Args:
16
  arg1: the first argument
@@ -33,6 +33,34 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  final_answer = FinalAnswerTool()
38
 
@@ -40,13 +68,12 @@ final_answer = FinalAnswerTool()
40
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
41
 
42
  model = HfApiModel(
43
- max_tokens=2096,
44
- temperature=0.5,
45
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
46
- custom_role_conversions=None,
47
  )
48
 
49
-
50
  # Import tool from Hub
51
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
52
 
@@ -55,7 +82,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
@@ -65,5 +92,4 @@ agent = CodeAgent(
65
  prompt_templates=prompt_templates
66
  )
67
 
68
-
69
- GradioUI(agent).launch()
 
1
+ import string
2
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
3
  import datetime
4
  import requests
5
  import pytz
 
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
+ def my_custom_tool(arg1: str, arg2: int) -> str: # it's import to specify the return type
 
14
  """A tool that does nothing yet
15
  Args:
16
  arg1: the first argument
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ @tool
37
+ def emoji_summarizer(text: str) -> str:
38
+ """
39
+ Summarizes the input text into a sequence of emojis that capture the main ideas.
40
+ Args:
41
+ text: Input string to summarize
42
+ """
43
+ mapping = {
44
+ "happy": "😊",
45
+ "sad": "😢",
46
+ "fire": "🔥",
47
+ "love": "❤️",
48
+ "party": "🎉",
49
+ "work": "💼",
50
+ "sleep": "😴",
51
+ "money": "💰",
52
+ "music": "🎵",
53
+ "food": "🍔",
54
+ "travel": "✈️",
55
+ "error": "❌",
56
+ "question": "❓",
57
+ }
58
+
59
+ words = text.lower().split()
60
+ emojis = [mapping[word] for word in words if word in mapping]
61
+ if not emojis:
62
+ return "🤔 (no matching emojis found)"
63
+ return "".join(emojis)
64
 
65
  final_answer = FinalAnswerTool()
66
 
 
68
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
69
 
70
  model = HfApiModel(
71
+ max_tokens=2096,
72
+ temperature=0.5,
73
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
74
+ custom_role_conversions=None,
75
  )
76
 
 
77
  # Import tool from Hub
78
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
79
 
 
82
 
83
  agent = CodeAgent(
84
  model=model,
85
+ tools=[final_answer, emoji_summarizer], ## add your tools here (don't remove final answer)
86
  max_steps=6,
87
  verbosity_level=1,
88
  grammar=None,
 
92
  prompt_templates=prompt_templates
93
  )
94
 
95
+ GradioUI(agent).launch()