Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,93 +1,72 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
# 검색 tool
|
11 |
-
|
12 |
@tool
|
13 |
-
def
|
14 |
-
"""
|
15 |
-
|
16 |
Args:
|
17 |
-
|
18 |
Returns:
|
19 |
-
|
|
|
20 |
"""
|
21 |
try:
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
)
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
except Exception as e:
|
30 |
traceback.print_exc()
|
31 |
-
return
|
32 |
|
33 |
-
# 기자 tool
|
34 |
@tool
|
35 |
-
def
|
36 |
-
"""
|
37 |
-
검색 결과를 바탕으로 새로운 기사를 작성하는 도구입니다.
|
38 |
Args:
|
39 |
-
|
40 |
-
search_results: 검색된 뉴스 정보
|
41 |
-
Returns:
|
42 |
-
작성된 기사
|
43 |
"""
|
44 |
try:
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
2. 요약 (핵심 내용을 2-3문장으로 요약)
|
51 |
-
3. 본문 (상세한 내용을 단락으로 구분하여 작성)
|
52 |
-
4. 결론 (기사의 의의나 향후 전망)
|
53 |
-
|
54 |
-
기사는 객관적이고 사실에 기반하여 작성해야 하며, 검색된 정보를 재구성하여 새로운 시각으로 작성해주세요.
|
55 |
-
"""
|
56 |
-
|
57 |
-
prompt = f"""
|
58 |
-
다음 주제와 검색 결과를 바탕으로 새로운 기사를 한국어로 작성해주세요:
|
59 |
-
|
60 |
-
주제: {topic}
|
61 |
-
|
62 |
-
검색 결과:
|
63 |
-
{search_results}
|
64 |
-
|
65 |
-
위 정보를 바탕으로 새롭고 통찰력 있는 기사를 작성해주세요.
|
66 |
-
"""
|
67 |
-
return model.generate(system_prompt + prompt)
|
68 |
except Exception as e:
|
69 |
-
|
70 |
-
return f"기사 작성 중 오류 발생: {str(e)}"
|
71 |
|
72 |
|
73 |
final_answer = FinalAnswerTool()
|
74 |
model = HfApiModel(
|
75 |
max_tokens=2096,
|
76 |
temperature=0.5,
|
77 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
78 |
custom_role_conversions=None,
|
79 |
)
|
80 |
|
81 |
|
82 |
-
#
|
83 |
-
|
84 |
|
85 |
with open("prompts.yaml", 'r') as stream:
|
86 |
prompt_templates = yaml.safe_load(stream)
|
87 |
|
88 |
agent = CodeAgent(
|
89 |
model=model,
|
90 |
-
tools=[
|
91 |
max_steps=6,
|
92 |
verbosity_level=1,
|
93 |
grammar=None,
|
|
|
1 |
+
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
import traceback
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
|
|
|
|
11 |
@tool
|
12 |
+
def nse_stock_price_tool(stock_ticker:str)-> str:
|
13 |
+
"""A tool that is used to retrieve the latest closing price of a stock based on the stock ticker from the Indian Stock Exchange (NSE).
|
14 |
+
example: 'RELIANCE.NS'
|
15 |
Args:
|
16 |
+
stock_ticker: The stock ticker/symbol for the stock listed in NSE. The exact string input needs to be provided to the function.
|
17 |
Returns:
|
18 |
+
result_string: A string containing the stock_ticker along with the amount in Rupees.
|
19 |
+
example: "RELIANCE NS: 1237.22 Rupees."
|
20 |
"""
|
21 |
try:
|
22 |
+
import math
|
23 |
+
import yfinance as yf
|
24 |
+
stock_symbol = stock_ticker
|
25 |
+
data = yf.download(tickers=stock_symbol, period='1d', interval='1m')
|
26 |
+
if len(data):
|
27 |
+
latest_data = data.tail(1)
|
28 |
+
latest_price = latest_data['Close'].values[0]
|
29 |
+
return (f"{stock_symbol}: {round(latest_price, 2)} Rupees.")
|
30 |
+
else:
|
31 |
+
return "INVALID TICKER/STOCK"
|
32 |
except Exception as e:
|
33 |
traceback.print_exc()
|
34 |
+
return "INVALID REQUEST"
|
35 |
|
|
|
36 |
@tool
|
37 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
38 |
+
"""A tool that fetches the current local time in a specified timezone.
|
|
|
39 |
Args:
|
40 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
|
|
|
|
|
|
41 |
"""
|
42 |
try:
|
43 |
+
# Create timezone object
|
44 |
+
tz = pytz.timezone(timezone)
|
45 |
+
# Get current time in that timezone
|
46 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
47 |
+
return f"The current local time in {timezone} is: {local_time}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
except Exception as e:
|
49 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
|
|
50 |
|
51 |
|
52 |
final_answer = FinalAnswerTool()
|
53 |
model = HfApiModel(
|
54 |
max_tokens=2096,
|
55 |
temperature=0.5,
|
56 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
57 |
custom_role_conversions=None,
|
58 |
)
|
59 |
|
60 |
|
61 |
+
# Import tool from Hub
|
62 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
63 |
|
64 |
with open("prompts.yaml", 'r') as stream:
|
65 |
prompt_templates = yaml.safe_load(stream)
|
66 |
|
67 |
agent = CodeAgent(
|
68 |
model=model,
|
69 |
+
tools=[nse_stock_price_tool, final_answer], ## add your tools here (don't remove final answer)
|
70 |
max_steps=6,
|
71 |
verbosity_level=1,
|
72 |
grammar=None,
|