Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
-
|
10 |
def respond(
|
11 |
message,
|
12 |
history: list[tuple[str, str]],
|
@@ -35,30 +35,58 @@ def respond(
|
|
35 |
top_p=top_p,
|
36 |
):
|
37 |
token = message.choices[0].delta.content
|
38 |
-
|
39 |
response += token
|
40 |
yield response
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
""
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
gr.
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
-
],
|
60 |
-
)
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
|
|
63 |
if __name__ == "__main__":
|
64 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import yfinance as yf
|
4 |
from huggingface_hub import InferenceClient
|
5 |
|
6 |
+
# Initialize the Inference Client for the chatbot
|
|
|
|
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
+
# Function for the chatbot response
|
10 |
def respond(
|
11 |
message,
|
12 |
history: list[tuple[str, str]],
|
|
|
35 |
top_p=top_p,
|
36 |
):
|
37 |
token = message.choices[0].delta.content
|
|
|
38 |
response += token
|
39 |
yield response
|
40 |
|
41 |
+
# Function for the trading screener
|
42 |
+
def trading_screener(price_threshold, volume_threshold):
|
43 |
+
stocks = ["AAPL", "MSFT", "GOOGL", "AMZN", "TSLA"]
|
44 |
+
data = []
|
45 |
+
|
46 |
+
for stock in stocks:
|
47 |
+
ticker = yf.Ticker(stock)
|
48 |
+
hist = ticker.history(period="1d")
|
49 |
+
current_price = hist['Close'].iloc[-1]
|
50 |
+
avg_volume = hist['Volume'].mean()
|
51 |
+
data.append({"Stock": stock, "Price": current_price, "Avg Volume": avg_volume})
|
52 |
+
|
53 |
+
df = pd.DataFrame(data)
|
54 |
+
filtered_df = df[(df['Price'] > price_threshold) & (df['Avg Volume'] > volume_threshold)]
|
55 |
+
return filtered_df
|
56 |
|
57 |
+
# Create the Gradio interface
|
58 |
+
with gr.Blocks() as demo:
|
59 |
+
gr.Markdown("# Trading Screener and Chatbot")
|
60 |
+
|
61 |
+
# Trading Screener Section
|
62 |
+
with gr.Row():
|
63 |
+
with gr.Column():
|
64 |
+
gr.Markdown("## Trading Screener")
|
65 |
+
price_threshold = gr.Number(label="Price Threshold", value=100.0)
|
66 |
+
volume_threshold = gr.Number(label="Volume Threshold", value=1000000)
|
67 |
+
submit_btn = gr.Button("Run Screener")
|
68 |
+
output_df = gr.Dataframe(label="Filtered Stocks")
|
69 |
+
|
70 |
+
submit_btn.click(fn=trading_screener, inputs=[price_threshold, volume_threshold], outputs=output_df)
|
|
|
|
|
|
|
|
|
71 |
|
72 |
+
# Chatbot Section
|
73 |
+
gr.Markdown("## Chatbot")
|
74 |
+
chat_interface = gr.ChatInterface(
|
75 |
+
respond,
|
76 |
+
additional_inputs=[
|
77 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
78 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
79 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
80 |
+
gr.Slider(
|
81 |
+
minimum=0.1,
|
82 |
+
maximum=1.0,
|
83 |
+
value=0.95,
|
84 |
+
step=0.05,
|
85 |
+
label="Top-p (nucleus sampling)",
|
86 |
+
),
|
87 |
+
],
|
88 |
+
)
|
89 |
|
90 |
+
# Launch the app
|
91 |
if __name__ == "__main__":
|
92 |
+
demo.launch()
|