STARX33 commited on
Commit
b0fda60
·
verified ·
1 Parent(s): 5df9cdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -3
app.py CHANGED
@@ -17,8 +17,18 @@ prompt_templates = {
17
  }
18
 
19
  # === Tools Defined Inline ===
 
20
  @tool
21
  def get_weather(city: str) -> str:
 
 
 
 
 
 
 
 
 
22
  try:
23
  response = requests.get(f"https://wttr.in/{city}?format=3")
24
  return f"The current weather in {city} is: {response.text}" if response.status_code == 200 else f"Failed to fetch weather data for {city}."
@@ -27,6 +37,15 @@ def get_weather(city: str) -> str:
27
 
28
  @tool
29
  def get_current_time_in_timezone(timezone: str) -> str:
 
 
 
 
 
 
 
 
 
30
  try:
31
  tz = pytz.timezone(timezone)
32
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
@@ -36,6 +55,15 @@ def get_current_time_in_timezone(timezone: str) -> str:
36
 
37
  @tool
38
  def generate_pun(topic: str) -> str:
 
 
 
 
 
 
 
 
 
39
  puns = {
40
  "banana": "I find bananas very *a-peeling*.",
41
  "fish": "You cod not be more fin-tastic!",
@@ -48,13 +76,22 @@ def generate_pun(topic: str) -> str:
48
 
49
  @tool
50
  def final_answer(text: str) -> str:
 
 
 
 
 
 
 
 
 
51
  return text
52
 
53
  # === Load Remote Tools ===
54
  web_search = load_tool("smol-ai/web-search")
55
  image_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
56
 
57
- # === Smart Agent ===
58
  class BasicAgent:
59
  def __init__(self):
60
  model = HfApiModel(
@@ -87,7 +124,7 @@ class BasicAgent:
87
  return f"Error while answering: {e}"
88
 
89
 
90
- # === Evaluation Logic ===
91
  def run_and_submit_all(profile: gr.OAuthProfile | None):
92
  space_id = os.getenv("SPACE_ID")
93
 
@@ -166,7 +203,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
166
  return f"Submission Failed: {e}", pd.DataFrame(results_log)
167
 
168
 
169
- # === Gradio UI ===
170
  with gr.Blocks() as demo:
171
  gr.Markdown("# Basic Agent Evaluation Runner")
172
  gr.Markdown("""
 
17
  }
18
 
19
  # === Tools Defined Inline ===
20
+
21
  @tool
22
  def get_weather(city: str) -> str:
23
+ """
24
+ Get the current weather for a given city.
25
+
26
+ Args:
27
+ city (str): Name of the city to get weather for.
28
+
29
+ Returns:
30
+ str: Weather description.
31
+ """
32
  try:
33
  response = requests.get(f"https://wttr.in/{city}?format=3")
34
  return f"The current weather in {city} is: {response.text}" if response.status_code == 200 else f"Failed to fetch weather data for {city}."
 
37
 
38
  @tool
39
  def get_current_time_in_timezone(timezone: str) -> str:
40
+ """
41
+ Get current time in a specific timezone.
42
+
43
+ Args:
44
+ timezone (str): Timezone string like 'America/New_York'.
45
+
46
+ Returns:
47
+ str: Current time as string.
48
+ """
49
  try:
50
  tz = pytz.timezone(timezone)
51
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
 
55
 
56
  @tool
57
  def generate_pun(topic: str) -> str:
58
+ """
59
+ Generate a pun based on a topic.
60
+
61
+ Args:
62
+ topic (str): A topic to create a pun from.
63
+
64
+ Returns:
65
+ str: A humorous pun related to the topic.
66
+ """
67
  puns = {
68
  "banana": "I find bananas very *a-peeling*.",
69
  "fish": "You cod not be more fin-tastic!",
 
76
 
77
  @tool
78
  def final_answer(text: str) -> str:
79
+ """
80
+ Finalize and return the last answer.
81
+
82
+ Args:
83
+ text (str): Final response.
84
+
85
+ Returns:
86
+ str: Same response passed through.
87
+ """
88
  return text
89
 
90
  # === Load Remote Tools ===
91
  web_search = load_tool("smol-ai/web-search")
92
  image_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
93
 
94
+ # === Smart Agent Definition ===
95
  class BasicAgent:
96
  def __init__(self):
97
  model = HfApiModel(
 
124
  return f"Error while answering: {e}"
125
 
126
 
127
+ # === Evaluation Logic (Do Not Touch) ===
128
  def run_and_submit_all(profile: gr.OAuthProfile | None):
129
  space_id = os.getenv("SPACE_ID")
130
 
 
203
  return f"Submission Failed: {e}", pd.DataFrame(results_log)
204
 
205
 
206
+ # === Gradio UI (Do Not Touch) ===
207
  with gr.Blocks() as demo:
208
  gr.Markdown("# Basic Agent Evaluation Runner")
209
  gr.Markdown("""