Spaces:
Sleeping
Sleeping
Commit
·
94d81ba
1
Parent(s):
8101bd6
ajustes no app
Browse files- .gitignore +3 -0
- .gradio/certificate.pem +31 -0
- Gradio_UI.py +46 -0
- app.py +19 -20
- tools/city_time.py +85 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
.env
|
2 |
+
.venv
|
3 |
+
__pycache__
|
.gradio/certificate.pem
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-----BEGIN CERTIFICATE-----
|
2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq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O3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
26 |
+
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
31 |
+
-----END CERTIFICATE-----
|
Gradio_UI.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
#!/usr/bin/env python
|
2 |
# coding=utf-8
|
3 |
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
|
@@ -262,6 +263,51 @@ class GradioUI:
|
|
262 |
import gradio as gr
|
263 |
|
264 |
with gr.Blocks(fill_height=True) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
stored_messages = gr.State([])
|
266 |
file_uploads_log = gr.State([])
|
267 |
chatbot = gr.Chatbot(
|
|
|
1 |
+
# pylint: disable=no-member
|
2 |
#!/usr/bin/env python
|
3 |
# coding=utf-8
|
4 |
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
|
|
|
263 |
import gradio as gr
|
264 |
|
265 |
with gr.Blocks(fill_height=True) as demo:
|
266 |
+
gr.Markdown("""
|
267 |
+
# AI Assistant with Web Search and Time Tools
|
268 |
+
|
269 |
+
This AI assistant is powered by the Qwen2.5-Coder-32B-Instruct model and provides several capabilities through its integrated tools:
|
270 |
+
|
271 |
+
## Available Tools
|
272 |
+
|
273 |
+
1. **Web Search** (DuckDuckGo)
|
274 |
+
- Performs web searches and returns relevant results
|
275 |
+
- Helps gather information from the internet
|
276 |
+
|
277 |
+
2. **Webpage Visit**
|
278 |
+
- Can visit and read content from web pages
|
279 |
+
- Converts webpage content to readable markdown format
|
280 |
+
|
281 |
+
3. **City Time**
|
282 |
+
- Gets current time for major cities worldwide
|
283 |
+
- Handles timezone conversions automatically
|
284 |
+
|
285 |
+
## Important Notes and Limitations
|
286 |
+
|
287 |
+
- **AI Model Limitations**: As an AI assistant, it may occasionally:
|
288 |
+
- Provide incomplete or inaccurate information
|
289 |
+
- Take longer to respond during high server load
|
290 |
+
- Require multiple attempts for complex queries
|
291 |
+
- Have trouble with ambiguous requests
|
292 |
+
|
293 |
+
- **Web Search Constraints**:
|
294 |
+
- Searches are performed through DuckDuckGo
|
295 |
+
- Results may vary based on search engine availability
|
296 |
+
- Some websites may block access or be unavailable
|
297 |
+
|
298 |
+
- **Time Tool Limitations**:
|
299 |
+
- Works best with major cities
|
300 |
+
- May require specific city names
|
301 |
+
- Time accuracy depends on timezone database
|
302 |
+
|
303 |
+
## Usage Tips
|
304 |
+
|
305 |
+
1. Be specific with your queries
|
306 |
+
2. For web searches, use clear and concise terms
|
307 |
+
3. When asking for city times, use well-known city names
|
308 |
+
4. Allow time for processing complex requests
|
309 |
+
5. Refresh the page if you encounter any issues
|
310 |
+
""")
|
311 |
stored_messages = gr.State([])
|
312 |
file_uploads_log = gr.State([])
|
313 |
chatbot = gr.Chatbot(
|
app.py
CHANGED
@@ -4,6 +4,16 @@ import requests
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
@@ -18,21 +28,9 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
Args:
|
25 |
-
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
26 |
-
"""
|
27 |
-
try:
|
28 |
-
# Create timezone object
|
29 |
-
tz = pytz.timezone(timezone)
|
30 |
-
# Get current time in that timezone
|
31 |
-
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
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 |
final_answer = FinalAnswerTool()
|
38 |
|
@@ -40,10 +38,11 @@ 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 |
|
@@ -55,7 +54,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer,
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
import os
|
9 |
+
from tools.city_time import CityTimeTool
|
10 |
+
|
11 |
+
# Load .env file and print debug info
|
12 |
+
load_dotenv(verbose=True)
|
13 |
+
hf_token = os.getenv('HF_TOKEN')
|
14 |
+
if not hf_token:
|
15 |
+
print("Warning: HF_TOKEN not found in environment variables")
|
16 |
+
# Fallback to the token directly if needed
|
17 |
|
18 |
from Gradio_UI import GradioUI
|
19 |
|
|
|
28 |
"""
|
29 |
return "What magic will you build ?"
|
30 |
|
31 |
+
# Remove or comment out the old get_current_time_in_timezone tool
|
32 |
+
# @tool
|
33 |
+
# def get_current_time_in_timezone...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
final_answer = FinalAnswerTool()
|
36 |
|
|
|
38 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
39 |
|
40 |
model = HfApiModel(
|
41 |
+
max_tokens=2096,
|
42 |
+
temperature=0.5,
|
43 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
44 |
+
custom_role_conversions=None,
|
45 |
+
token=os.getenv('HF_TOKEN')
|
46 |
)
|
47 |
|
48 |
|
|
|
54 |
|
55 |
agent = CodeAgent(
|
56 |
model=model,
|
57 |
+
tools=[final_answer, CityTimeTool(), DuckDuckGoSearchTool()], # Updated tools list
|
58 |
max_steps=6,
|
59 |
verbosity_level=1,
|
60 |
grammar=None,
|
tools/city_time.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Optional
|
2 |
+
from smolagents.tools import Tool
|
3 |
+
import pytz
|
4 |
+
import datetime
|
5 |
+
import re
|
6 |
+
from duckduckgo_search import DDGS
|
7 |
+
|
8 |
+
class CityTimeTool(Tool):
|
9 |
+
name = "city_time"
|
10 |
+
description = "Get the current local time for any city by searching for its timezone and converting current UTC time."
|
11 |
+
inputs = {'city': {'type': 'string', 'description': 'The name of the city to get the current time for'}}
|
12 |
+
output_type = "string"
|
13 |
+
|
14 |
+
def __init__(self):
|
15 |
+
super().__init__()
|
16 |
+
self.ddgs = DDGS()
|
17 |
+
|
18 |
+
def _find_timezone(self, city: str) -> str:
|
19 |
+
"""Search for the timezone of a given city."""
|
20 |
+
# Search for timezone information
|
21 |
+
query = f"{city} timezone UTC time zone"
|
22 |
+
results = list(self.ddgs.text(query, max_results=3))
|
23 |
+
|
24 |
+
if not results:
|
25 |
+
raise Exception(f"Could not find timezone information for {city}")
|
26 |
+
|
27 |
+
# Common timezone patterns in city names
|
28 |
+
common_cities = {
|
29 |
+
'new york': 'America/New_York',
|
30 |
+
'london': 'Europe/London',
|
31 |
+
'paris': 'Europe/Paris',
|
32 |
+
'tokyo': 'Asia/Tokyo',
|
33 |
+
'sydney': 'Australia/Sydney',
|
34 |
+
'dubai': 'Asia/Dubai',
|
35 |
+
'singapore': 'Asia/Singapore',
|
36 |
+
'hong kong': 'Asia/Hong_Kong',
|
37 |
+
'los angeles': 'America/Los_Angeles',
|
38 |
+
'chicago': 'America/Chicago',
|
39 |
+
'toronto': 'America/Toronto',
|
40 |
+
'sao paulo': 'America/Sao_Paulo',
|
41 |
+
'rio': 'America/Sao_Paulo',
|
42 |
+
'moscow': 'Europe/Moscow',
|
43 |
+
'berlin': 'Europe/Berlin',
|
44 |
+
'madrid': 'Europe/Madrid',
|
45 |
+
'rome': 'Europe/Rome',
|
46 |
+
'beijing': 'Asia/Shanghai',
|
47 |
+
'shanghai': 'Asia/Shanghai',
|
48 |
+
'seoul': 'Asia/Seoul',
|
49 |
+
'bangkok': 'Asia/Bangkok',
|
50 |
+
'cairo': 'Africa/Cairo',
|
51 |
+
'johannesburg': 'Africa/Johannesburg',
|
52 |
+
'mexico city': 'America/Mexico_City',
|
53 |
+
'buenos aires': 'America/Argentina/Buenos_Aires'
|
54 |
+
}
|
55 |
+
|
56 |
+
# Check if city is in common cities first
|
57 |
+
city_lower = city.lower()
|
58 |
+
if city_lower in common_cities:
|
59 |
+
return common_cities[city_lower]
|
60 |
+
|
61 |
+
# Try to extract timezone from search results
|
62 |
+
for result in results:
|
63 |
+
text = result['body'].lower()
|
64 |
+
# Look for common timezone patterns
|
65 |
+
for known_city, timezone in common_cities.items():
|
66 |
+
if known_city in text and city_lower in text:
|
67 |
+
return timezone
|
68 |
+
|
69 |
+
# Default to UTC if we can't determine the timezone
|
70 |
+
raise Exception(f"Could not determine timezone for {city}. Please try a major city name.")
|
71 |
+
|
72 |
+
def forward(self, city: str) -> str:
|
73 |
+
try:
|
74 |
+
# Find the timezone
|
75 |
+
timezone_str = self._find_timezone(city)
|
76 |
+
|
77 |
+
# Get current time in that timezone
|
78 |
+
tz = pytz.timezone(timezone_str)
|
79 |
+
utc_now = datetime.datetime.now(pytz.UTC)
|
80 |
+
local_time = utc_now.astimezone(tz)
|
81 |
+
|
82 |
+
return f"Current time in {city} ({timezone_str}) is: {local_time.strftime('%Y-%m-%d %H:%M:%S %Z')}"
|
83 |
+
|
84 |
+
except Exception as e:
|
85 |
+
return f"Error getting time for {city}: {str(e)}"
|