Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,48 +6,7 @@ import io
|
|
6 |
|
7 |
genai.configure(api_key="AIzaSyAj-b3sO_wUguMdpXWScxKzMHxb8C5cels")
|
8 |
|
9 |
-
|
10 |
-
questions = {
|
11 |
-
"Forex": [
|
12 |
-
"Is the current trend bullish or bearish for this pair?",
|
13 |
-
"What are the key support and resistance levels?",
|
14 |
-
"Are there any significant economic events impacting this pair?",
|
15 |
-
"What do candlestick patterns suggest about future price movements?",
|
16 |
-
"How do moving averages influence this pair's trend?",
|
17 |
-
"What does the RSI indicate about this pair’s strength?",
|
18 |
-
"Are there any MACD signals indicating a change in trend?",
|
19 |
-
"How does volume affect the current forex pair's trend?",
|
20 |
-
"Is there a potential breakout or breakdown in the chart?",
|
21 |
-
"What are the Fibonacci retracement levels for this pair?"
|
22 |
-
],
|
23 |
-
"Crypto": [
|
24 |
-
"What is the current trend of this cryptocurrency?",
|
25 |
-
"Are there any significant candlestick patterns forming?",
|
26 |
-
"How do moving averages impact the crypto's price action?",
|
27 |
-
"What are the support and resistance levels for this crypto?",
|
28 |
-
"What does the RSI indicate about the crypto's market condition?",
|
29 |
-
"Are there any divergences between price and MACD?",
|
30 |
-
"How does the volume confirm the current trend?",
|
31 |
-
"Is there a potential reversal signal in the chart?",
|
32 |
-
"What are the potential breakout points in the chart?",
|
33 |
-
"How do news or events affect the crypto's price?"
|
34 |
-
],
|
35 |
-
"Stocks": [
|
36 |
-
"Is the stock currently in an uptrend or downtrend?",
|
37 |
-
"What are the key support and resistance levels?",
|
38 |
-
"Are there any significant candlestick patterns forming?",
|
39 |
-
"How do moving averages influence the stock's price action?",
|
40 |
-
"What does the RSI indicate about the stock's market condition?",
|
41 |
-
"Are there any divergence signals between price and MACD?",
|
42 |
-
"How does the volume confirm the current trend?",
|
43 |
-
"Is there a potential reversal signal in the stock's chart?",
|
44 |
-
"What are the potential breakout points in the stock's chart?",
|
45 |
-
"How do earnings reports or company news impact the stock's price?"
|
46 |
-
],
|
47 |
-
# Add similar lists for Futures and Options
|
48 |
-
}
|
49 |
-
|
50 |
-
def ImageChat(image, chart_type, ticker, prompt="Analyze", analyze_more=None):
|
51 |
# Check image file and convert to a PIL Image object
|
52 |
if isinstance(image, np.ndarray):
|
53 |
img = PIL.Image.fromarray(image)
|
@@ -61,9 +20,7 @@ def ImageChat(image, chart_type, ticker, prompt="Analyze", analyze_more=None):
|
|
61 |
model = genai.GenerativeModel("gemini-pro-vision")
|
62 |
|
63 |
# Determine the prompt to use
|
64 |
-
if
|
65 |
-
custom_prompt = f"Act as a genius Trader and answer the following request: {analyze_more} after analyzing the chart thoroughly."
|
66 |
-
elif prompt == "Analyze":
|
67 |
custom_prompt = (
|
68 |
"Analyze the attached stock chart image as a technical quant analyst. Based on the trend, movement, and price action visible in the chart, make intelligent and substantial trading suggestions. Provide clear entry, exit, and hold conditions, along with detailed risk management strategies. Discuss the expected timeframe for the trade, specifying the duration in terms of the timesteps shown in the chart. Aim for a good profit-to-time ratio, favoring high profits within shorter timeframes unless longer timeframes yield significantly higher profits. Reference absolute values from the chart rather than relying on general strategies. Avoid basic explanations of indicators, and focus on providing in-depth analysis.\n\n"
|
69 |
|
@@ -135,47 +92,12 @@ def ImageChat(image, chart_type, ticker, prompt="Analyze", analyze_more=None):
|
|
135 |
except ValueError as e:
|
136 |
return f"Error in generating response: {e}"
|
137 |
|
138 |
-
def populate_questions(chart_type):
|
139 |
-
return questions.get(chart_type, [])
|
140 |
-
|
141 |
-
def update_analyze_more(chart_type):
|
142 |
-
return gr.update(choices=populate_questions(chart_type))
|
143 |
-
|
144 |
app = gr.Interface(
|
145 |
fn=ImageChat,
|
146 |
-
inputs=[
|
147 |
-
gr.Image(label="Image"),
|
148 |
-
gr.Dropdown(label="Chart Type", choices=["Forex", "Crypto", "Stocks"], type="value", value="Stocks"),
|
149 |
-
gr.Textbox(label="Ticker", placeholder="Enter ticker symbol"),
|
150 |
-
gr.Textbox(label="Prompt", value="Analyze"),
|
151 |
-
gr.Dropdown(label="Analyze more", choices=[], type="value", interactive=True)
|
152 |
-
],
|
153 |
outputs=gr.Textbox(label="Response"),
|
154 |
title="Trading View Chat Analyzer",
|
155 |
theme=gr.themes.Soft()
|
156 |
)
|
157 |
|
158 |
-
|
159 |
-
def dynamic_analyze_more(chart_type):
|
160 |
-
questions_list = populate_questions(chart_type)
|
161 |
-
return gr.update(choices=questions_list)
|
162 |
-
|
163 |
-
# Create a new Gradio Block to handle interactions
|
164 |
-
with gr.Blocks() as demo:
|
165 |
-
chart_type = gr.Dropdown(label="Chart Type", choices=["Forex", "Crypto", "Stocks"], type="value", value="Stocks")
|
166 |
-
ticker = gr.Textbox(label="Ticker", placeholder="Enter ticker symbol")
|
167 |
-
prompt = gr.Textbox(label="Prompt", value="Analyze")
|
168 |
-
analyze_more = gr.Dropdown(label="Analyze more", choices=[], type="value", interactive=True)
|
169 |
-
image = gr.Image(label="Image")
|
170 |
-
response = gr.Textbox(label="Response")
|
171 |
-
|
172 |
-
chart_type.change(dynamic_analyze_more, inputs=chart_type, outputs=analyze_more)
|
173 |
-
|
174 |
-
gr.Interface(
|
175 |
-
fn=ImageChat,
|
176 |
-
inputs=[image, chart_type, ticker, prompt, analyze_more],
|
177 |
-
outputs=response
|
178 |
-
).launch()
|
179 |
-
|
180 |
-
demo.launch()
|
181 |
-
|
|
|
6 |
|
7 |
genai.configure(api_key="AIzaSyAj-b3sO_wUguMdpXWScxKzMHxb8C5cels")
|
8 |
|
9 |
+
def ImageChat(image, prompt="Analyze"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
# Check image file and convert to a PIL Image object
|
11 |
if isinstance(image, np.ndarray):
|
12 |
img = PIL.Image.fromarray(image)
|
|
|
20 |
model = genai.GenerativeModel("gemini-pro-vision")
|
21 |
|
22 |
# Determine the prompt to use
|
23 |
+
if prompt == "Analyze":
|
|
|
|
|
24 |
custom_prompt = (
|
25 |
"Analyze the attached stock chart image as a technical quant analyst. Based on the trend, movement, and price action visible in the chart, make intelligent and substantial trading suggestions. Provide clear entry, exit, and hold conditions, along with detailed risk management strategies. Discuss the expected timeframe for the trade, specifying the duration in terms of the timesteps shown in the chart. Aim for a good profit-to-time ratio, favoring high profits within shorter timeframes unless longer timeframes yield significantly higher profits. Reference absolute values from the chart rather than relying on general strategies. Avoid basic explanations of indicators, and focus on providing in-depth analysis.\n\n"
|
26 |
|
|
|
92 |
except ValueError as e:
|
93 |
return f"Error in generating response: {e}"
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
app = gr.Interface(
|
96 |
fn=ImageChat,
|
97 |
+
inputs=[gr.Image(label="Image"), gr.Textbox(label="Prompt", value="Analyze")],
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
outputs=gr.Textbox(label="Response"),
|
99 |
title="Trading View Chat Analyzer",
|
100 |
theme=gr.themes.Soft()
|
101 |
)
|
102 |
|
103 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|