Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ from smolagents import (
|
|
| 7 |
|
| 8 |
import datetime
|
| 9 |
import pytz
|
| 10 |
-
import yaml
|
| 11 |
import re
|
| 12 |
|
| 13 |
from tools.final_answer import FinalAnswerTool
|
|
@@ -47,9 +46,7 @@ def extract_price_from_snippet(snippet: str) -> list[str]:
|
|
| 47 |
r"(?:USD|EUR|GBP|INR|AUD|CAD)?"
|
| 48 |
)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
return matches
|
| 53 |
|
| 54 |
|
| 55 |
@tool
|
|
@@ -62,15 +59,11 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 62 |
"""
|
| 63 |
|
| 64 |
try:
|
| 65 |
-
|
| 66 |
tz = pytz.timezone(timezone)
|
| 67 |
-
|
| 68 |
now = datetime.datetime.now(tz)
|
| 69 |
-
|
| 70 |
return now.strftime("%Y-%m-%d %H:%M:%S")
|
| 71 |
|
| 72 |
except Exception as e:
|
| 73 |
-
|
| 74 |
return str(e)
|
| 75 |
|
| 76 |
|
|
@@ -80,14 +73,15 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 80 |
|
| 81 |
final_answer = FinalAnswerTool()
|
| 82 |
|
|
|
|
| 83 |
# ==========================================================
|
| 84 |
# WEB TOOLS
|
| 85 |
# ==========================================================
|
| 86 |
|
| 87 |
web_search = DuckDuckGoSearchTool()
|
| 88 |
-
|
| 89 |
visit_webpage = VisitWebpageTool()
|
| 90 |
|
|
|
|
| 91 |
# ==========================================================
|
| 92 |
# OPTIONAL IMAGE TOOL
|
| 93 |
# ==========================================================
|
|
@@ -97,63 +91,39 @@ image_generation_tool = load_tool(
|
|
| 97 |
trust_remote_code=True,
|
| 98 |
)
|
| 99 |
|
|
|
|
| 100 |
# ==========================================================
|
| 101 |
# MODEL
|
| 102 |
# ==========================================================
|
| 103 |
|
| 104 |
model = HfApiModel(
|
| 105 |
-
|
| 106 |
model_id="https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud",
|
| 107 |
-
|
| 108 |
max_tokens=2048,
|
| 109 |
-
|
| 110 |
temperature=0.1,
|
| 111 |
-
|
| 112 |
custom_role_conversions=None,
|
| 113 |
)
|
| 114 |
|
| 115 |
-
# ==========================================================
|
| 116 |
-
# PROMPTS
|
| 117 |
-
# ==========================================================
|
| 118 |
-
|
| 119 |
-
with open("prompts.yaml", "r") as stream:
|
| 120 |
-
|
| 121 |
-
prompt_templates = yaml.safe_load(stream)
|
| 122 |
|
| 123 |
# ==========================================================
|
| 124 |
# AGENT
|
| 125 |
# ==========================================================
|
| 126 |
|
| 127 |
agent = CodeAgent(
|
| 128 |
-
|
| 129 |
model=model,
|
| 130 |
-
|
| 131 |
tools=[
|
| 132 |
-
|
| 133 |
final_answer,
|
| 134 |
-
|
| 135 |
web_search,
|
| 136 |
-
|
| 137 |
visit_webpage,
|
| 138 |
-
|
| 139 |
calculate_min_price,
|
| 140 |
-
|
| 141 |
extract_price_from_snippet,
|
| 142 |
-
|
| 143 |
get_current_time_in_timezone,
|
| 144 |
-
|
| 145 |
],
|
| 146 |
-
|
| 147 |
max_steps=12,
|
| 148 |
-
|
| 149 |
verbosity_level=2,
|
| 150 |
-
|
| 151 |
planning_interval=2,
|
| 152 |
-
|
| 153 |
-
prompt_templates=prompt_templates,
|
| 154 |
-
|
| 155 |
)
|
| 156 |
|
|
|
|
| 157 |
# ==========================================================
|
| 158 |
# UI
|
| 159 |
# ==========================================================
|
|
|
|
| 7 |
|
| 8 |
import datetime
|
| 9 |
import pytz
|
|
|
|
| 10 |
import re
|
| 11 |
|
| 12 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 46 |
r"(?:USD|EUR|GBP|INR|AUD|CAD)?"
|
| 47 |
)
|
| 48 |
|
| 49 |
+
return re.findall(pattern, snippet)
|
|
|
|
|
|
|
| 50 |
|
| 51 |
|
| 52 |
@tool
|
|
|
|
| 59 |
"""
|
| 60 |
|
| 61 |
try:
|
|
|
|
| 62 |
tz = pytz.timezone(timezone)
|
|
|
|
| 63 |
now = datetime.datetime.now(tz)
|
|
|
|
| 64 |
return now.strftime("%Y-%m-%d %H:%M:%S")
|
| 65 |
|
| 66 |
except Exception as e:
|
|
|
|
| 67 |
return str(e)
|
| 68 |
|
| 69 |
|
|
|
|
| 73 |
|
| 74 |
final_answer = FinalAnswerTool()
|
| 75 |
|
| 76 |
+
|
| 77 |
# ==========================================================
|
| 78 |
# WEB TOOLS
|
| 79 |
# ==========================================================
|
| 80 |
|
| 81 |
web_search = DuckDuckGoSearchTool()
|
|
|
|
| 82 |
visit_webpage = VisitWebpageTool()
|
| 83 |
|
| 84 |
+
|
| 85 |
# ==========================================================
|
| 86 |
# OPTIONAL IMAGE TOOL
|
| 87 |
# ==========================================================
|
|
|
|
| 91 |
trust_remote_code=True,
|
| 92 |
)
|
| 93 |
|
| 94 |
+
|
| 95 |
# ==========================================================
|
| 96 |
# MODEL
|
| 97 |
# ==========================================================
|
| 98 |
|
| 99 |
model = HfApiModel(
|
|
|
|
| 100 |
model_id="https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud",
|
|
|
|
| 101 |
max_tokens=2048,
|
|
|
|
| 102 |
temperature=0.1,
|
|
|
|
| 103 |
custom_role_conversions=None,
|
| 104 |
)
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
# ==========================================================
|
| 108 |
# AGENT
|
| 109 |
# ==========================================================
|
| 110 |
|
| 111 |
agent = CodeAgent(
|
|
|
|
| 112 |
model=model,
|
|
|
|
| 113 |
tools=[
|
|
|
|
| 114 |
final_answer,
|
|
|
|
| 115 |
web_search,
|
|
|
|
| 116 |
visit_webpage,
|
|
|
|
| 117 |
calculate_min_price,
|
|
|
|
| 118 |
extract_price_from_snippet,
|
|
|
|
| 119 |
get_current_time_in_timezone,
|
|
|
|
| 120 |
],
|
|
|
|
| 121 |
max_steps=12,
|
|
|
|
| 122 |
verbosity_level=2,
|
|
|
|
| 123 |
planning_interval=2,
|
|
|
|
|
|
|
|
|
|
| 124 |
)
|
| 125 |
|
| 126 |
+
|
| 127 |
# ==========================================================
|
| 128 |
# UI
|
| 129 |
# ==========================================================
|