Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
@@ -6,8 +6,10 @@ import yaml
|
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
import os
|
8 |
from huggingface_hub import list_models
|
9 |
-
|
10 |
from Gradio_UI import GradioUI
|
|
|
|
|
|
|
11 |
|
12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
13 |
@tool
|
@@ -47,8 +49,6 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
47 |
except Exception as e:
|
48 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
49 |
|
50 |
-
import baostock as bs
|
51 |
-
import pandas as pd
|
52 |
@tool
|
53 |
def get_stock_data_baostock(stock_code: str) -> str:
|
54 |
"""Fetch the latest stock data for a given stock code using Baostock.
|
@@ -70,40 +70,43 @@ def get_stock_data_baostock(stock_code: str) -> str:
|
|
70 |
)
|
71 |
if rs.error_code != '0':
|
72 |
return f"Failed to fetch stock data: {rs.error_msg}"
|
73 |
-
|
74 |
# Convert the data to a DataFrame
|
75 |
data_list = []
|
76 |
while (rs.error_code == '0') & rs.next():
|
77 |
data_list.append(rs.get_row_data())
|
78 |
df = pd.DataFrame(data_list, columns=rs.fields)
|
79 |
-
|
80 |
# Log out of the Baostock system
|
81 |
bs.logout()
|
82 |
-
|
83 |
# Check if the data is empty
|
84 |
if df.empty:
|
85 |
return f"No data found for stock code '{stock_code}'."
|
86 |
-
|
87 |
# Extract the latest trading day's data
|
88 |
latest_data = df.iloc[-1] # Get the last row of data (most recent trading day)
|
89 |
date = latest_data['date'] # Date
|
90 |
stock_name = latest_data['code'] # Stock code
|
91 |
close_price = latest_data['close'] # Closing price
|
92 |
volume = latest_data['volume'] # Trading volume
|
93 |
-
|
94 |
# Construct the result string
|
95 |
result = f"Stock Code: {stock_name}\nDate: {date}\nClosing Price: {close_price}\nVolume: {volume}"
|
96 |
return result
|
97 |
-
|
98 |
except Exception as e:
|
99 |
return f"An error occurred while fetching stock data: {str(e)}"
|
100 |
-
|
101 |
# Example call
|
102 |
print(get_stock_data_baostock('sh.600941'))
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
|
|
|
|
105 |
|
106 |
-
final_answer = FinalAnswerTool()
|
107 |
model = HfApiModel(
|
108 |
max_tokens=2096,
|
109 |
temperature=0.5,
|
@@ -112,19 +115,9 @@ model = HfApiModel(
|
|
112 |
token=os.getenv('hf_token'),
|
113 |
)
|
114 |
|
115 |
-
|
116 |
-
# Import tool from Hub
|
117 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
118 |
-
|
119 |
-
with open("prompts.yaml", 'r') as stream:
|
120 |
-
prompt_templates = yaml.safe_load(stream)
|
121 |
-
|
122 |
agent = CodeAgent(
|
123 |
model=model,
|
124 |
-
tools=[
|
125 |
-
final_answer,
|
126 |
-
image_generation_tool,
|
127 |
-
get_stock_data_baostock], ## add your tools here (don't remove final answer)
|
128 |
max_steps=6,
|
129 |
verbosity_level=1,
|
130 |
grammar=None,
|
@@ -135,5 +128,4 @@ agent = CodeAgent(
|
|
135 |
add_base_tools=True,
|
136 |
)
|
137 |
|
138 |
-
|
139 |
GradioUI(agent).launch()
|
|
|
1 |
+
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
|
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
import os
|
8 |
from huggingface_hub import list_models
|
|
|
9 |
from Gradio_UI import GradioUI
|
10 |
+
import baostock as bs
|
11 |
+
import pandas as pd
|
12 |
+
from tools.house_drawing_tool import HouseDrawingTool
|
13 |
|
14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
15 |
@tool
|
|
|
49 |
except Exception as e:
|
50 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
51 |
|
|
|
|
|
52 |
@tool
|
53 |
def get_stock_data_baostock(stock_code: str) -> str:
|
54 |
"""Fetch the latest stock data for a given stock code using Baostock.
|
|
|
70 |
)
|
71 |
if rs.error_code != '0':
|
72 |
return f"Failed to fetch stock data: {rs.error_msg}"
|
|
|
73 |
# Convert the data to a DataFrame
|
74 |
data_list = []
|
75 |
while (rs.error_code == '0') & rs.next():
|
76 |
data_list.append(rs.get_row_data())
|
77 |
df = pd.DataFrame(data_list, columns=rs.fields)
|
|
|
78 |
# Log out of the Baostock system
|
79 |
bs.logout()
|
|
|
80 |
# Check if the data is empty
|
81 |
if df.empty:
|
82 |
return f"No data found for stock code '{stock_code}'."
|
|
|
83 |
# Extract the latest trading day's data
|
84 |
latest_data = df.iloc[-1] # Get the last row of data (most recent trading day)
|
85 |
date = latest_data['date'] # Date
|
86 |
stock_name = latest_data['code'] # Stock code
|
87 |
close_price = latest_data['close'] # Closing price
|
88 |
volume = latest_data['volume'] # Trading volume
|
|
|
89 |
# Construct the result string
|
90 |
result = f"Stock Code: {stock_name}\nDate: {date}\nClosing Price: {close_price}\nVolume: {volume}"
|
91 |
return result
|
|
|
92 |
except Exception as e:
|
93 |
return f"An error occurred while fetching stock data: {str(e)}"
|
|
|
94 |
# Example call
|
95 |
print(get_stock_data_baostock('sh.600941'))
|
96 |
|
97 |
+
@tool
|
98 |
+
final_answer = FinalAnswerTool()
|
99 |
+
|
100 |
+
@tool
|
101 |
+
# Import tool from Hub
|
102 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
103 |
+
|
104 |
+
@tool
|
105 |
+
house_draw = HouseDrawingTool()
|
106 |
|
107 |
+
with open("prompts.yaml", 'r') as stream:
|
108 |
+
prompt_templates = yaml.safe_load(stream)
|
109 |
|
|
|
110 |
model = HfApiModel(
|
111 |
max_tokens=2096,
|
112 |
temperature=0.5,
|
|
|
115 |
token=os.getenv('hf_token'),
|
116 |
)
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
agent = CodeAgent(
|
119 |
model=model,
|
120 |
+
tools=[final_answer, image_generation_tool, get_stock_data_baostock, house_draw], ## add your tools here (don't remove final answer)
|
|
|
|
|
|
|
121 |
max_steps=6,
|
122 |
verbosity_level=1,
|
123 |
grammar=None,
|
|
|
128 |
add_base_tools=True,
|
129 |
)
|
130 |
|
|
|
131 |
GradioUI(agent).launch()
|