Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
import openai
|
3 |
import os
|
4 |
import base64
|
5 |
-
import time
|
6 |
|
7 |
# OpenAI API Configuration
|
8 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
@@ -10,7 +9,7 @@ ANALYSIS_MODEL = "gpt-4o"
|
|
10 |
MAX_TOKENS = 4096
|
11 |
|
12 |
# System Prompt Configuration
|
13 |
-
SYSTEM_PROMPT = """
|
14 |
1. Identify all technical patterns in the chart
|
15 |
2. Determine key support/resistance levels
|
16 |
3. Analyze volume and momentum indicators
|
@@ -77,25 +76,30 @@ custom_css = """
|
|
77 |
--text-color: #1e293b;
|
78 |
--border-color: #e2e8f0;
|
79 |
}
|
|
|
80 |
body {
|
81 |
background-color: var(--background-color);
|
82 |
color: var(--text-color);
|
83 |
}
|
|
|
84 |
.container {
|
85 |
max-width: 1200px;
|
86 |
margin: 0 auto;
|
87 |
padding: 20px;
|
88 |
}
|
|
|
89 |
.analysis-box {
|
90 |
background-color: white;
|
91 |
border-radius: 12px;
|
92 |
padding: 24px;
|
93 |
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
94 |
border: 1px solid var(--border-color);
|
95 |
-
height:
|
96 |
overflow-y: auto;
|
97 |
width: 100%;
|
|
|
98 |
}
|
|
|
99 |
.upload-box {
|
100 |
background-color: white;
|
101 |
border-radius: 12px;
|
@@ -104,6 +108,7 @@ body {
|
|
104 |
border: 1px solid var(--border-color);
|
105 |
width: 100%;
|
106 |
}
|
|
|
107 |
.primary-button {
|
108 |
background-color: var(--primary-color) !important;
|
109 |
color: white !important;
|
@@ -112,30 +117,57 @@ body {
|
|
112 |
font-weight: 500 !important;
|
113 |
width: 100%;
|
114 |
}
|
|
|
115 |
.primary-button:hover {
|
116 |
background-color: var(--secondary-color) !important;
|
117 |
}
|
|
|
118 |
.markdown-container {
|
119 |
max-width: 100%;
|
120 |
margin: 0 auto;
|
121 |
padding: 0 15px;
|
122 |
word-wrap: break-word;
|
123 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
.loading-text {
|
125 |
color: var(--primary-color);
|
126 |
font-size: 1.2rem;
|
127 |
text-align: center;
|
128 |
margin-top: 2rem;
|
129 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
.row {
|
131 |
display: flex;
|
132 |
flex-wrap: wrap;
|
133 |
gap: 20px;
|
134 |
}
|
|
|
135 |
.column {
|
136 |
flex: 1;
|
137 |
min-width: 300px;
|
138 |
}
|
|
|
139 |
@media (max-width: 768px) {
|
140 |
.row {
|
141 |
flex-direction: column;
|
@@ -147,6 +179,14 @@ body {
|
|
147 |
}
|
148 |
"""
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
# Gradio Interface
|
151 |
analyzer = ChartAnalyzer()
|
152 |
|
@@ -156,7 +196,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
156 |
gr.Markdown("""
|
157 |
<div style="text-align: center; margin-bottom: 32px;">
|
158 |
<h1 style="color: var(--primary-color); font-size: 2.5rem; margin-bottom: 16px;">
|
159 |
-
π
|
160 |
</h1>
|
161 |
<p style="color: var(--text-color); font-size: 1.1rem;">
|
162 |
Advanced AI-powered cryptocurrency technical analysis
|
@@ -188,12 +228,16 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
188 |
gr.Markdown("### π Analysis Report")
|
189 |
analysis_output = gr.Markdown(
|
190 |
label="",
|
191 |
-
|
192 |
-
|
193 |
)
|
194 |
|
195 |
# Event Handling
|
196 |
analyze_btn.click(
|
|
|
|
|
|
|
|
|
197 |
fn=analyzer.analyze_chart,
|
198 |
inputs=chart_input,
|
199 |
outputs=analysis_output,
|
@@ -201,4 +245,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
201 |
)
|
202 |
|
203 |
if __name__ == "__main__":
|
204 |
-
demo.launch(
|
|
|
|
|
|
|
|
2 |
import openai
|
3 |
import os
|
4 |
import base64
|
|
|
5 |
|
6 |
# OpenAI API Configuration
|
7 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
|
9 |
MAX_TOKENS = 4096
|
10 |
|
11 |
# System Prompt Configuration
|
12 |
+
SYSTEM_PROMPT = """Professional Crypto Technical Analyst:
|
13 |
1. Identify all technical patterns in the chart
|
14 |
2. Determine key support/resistance levels
|
15 |
3. Analyze volume and momentum indicators
|
|
|
76 |
--text-color: #1e293b;
|
77 |
--border-color: #e2e8f0;
|
78 |
}
|
79 |
+
|
80 |
body {
|
81 |
background-color: var(--background-color);
|
82 |
color: var(--text-color);
|
83 |
}
|
84 |
+
|
85 |
.container {
|
86 |
max-width: 1200px;
|
87 |
margin: 0 auto;
|
88 |
padding: 20px;
|
89 |
}
|
90 |
+
|
91 |
.analysis-box {
|
92 |
background-color: white;
|
93 |
border-radius: 12px;
|
94 |
padding: 24px;
|
95 |
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
96 |
border: 1px solid var(--border-color);
|
97 |
+
height: 400px; /* Initial height */
|
98 |
overflow-y: auto;
|
99 |
width: 100%;
|
100 |
+
transition: height 0.3s ease;
|
101 |
}
|
102 |
+
|
103 |
.upload-box {
|
104 |
background-color: white;
|
105 |
border-radius: 12px;
|
|
|
108 |
border: 1px solid var(--border-color);
|
109 |
width: 100%;
|
110 |
}
|
111 |
+
|
112 |
.primary-button {
|
113 |
background-color: var(--primary-color) !important;
|
114 |
color: white !important;
|
|
|
117 |
font-weight: 500 !important;
|
118 |
width: 100%;
|
119 |
}
|
120 |
+
|
121 |
.primary-button:hover {
|
122 |
background-color: var(--secondary-color) !important;
|
123 |
}
|
124 |
+
|
125 |
.markdown-container {
|
126 |
max-width: 100%;
|
127 |
margin: 0 auto;
|
128 |
padding: 0 15px;
|
129 |
word-wrap: break-word;
|
130 |
}
|
131 |
+
|
132 |
+
.loading-container {
|
133 |
+
display: flex;
|
134 |
+
justify-content: center;
|
135 |
+
align-items: center;
|
136 |
+
height: 100%;
|
137 |
+
}
|
138 |
+
|
139 |
.loading-text {
|
140 |
color: var(--primary-color);
|
141 |
font-size: 1.2rem;
|
142 |
text-align: center;
|
143 |
margin-top: 2rem;
|
144 |
}
|
145 |
+
|
146 |
+
.loading-spinner {
|
147 |
+
border: 4px solid #f3f3f3;
|
148 |
+
border-top: 4px solid var(--primary-color);
|
149 |
+
border-radius: 50%;
|
150 |
+
width: 40px;
|
151 |
+
height: 40px;
|
152 |
+
animation: spin 1s linear infinite;
|
153 |
+
}
|
154 |
+
|
155 |
+
@keyframes spin {
|
156 |
+
0% { transform: rotate(0deg); }
|
157 |
+
100% { transform: rotate(360deg); }
|
158 |
+
}
|
159 |
+
|
160 |
.row {
|
161 |
display: flex;
|
162 |
flex-wrap: wrap;
|
163 |
gap: 20px;
|
164 |
}
|
165 |
+
|
166 |
.column {
|
167 |
flex: 1;
|
168 |
min-width: 300px;
|
169 |
}
|
170 |
+
|
171 |
@media (max-width: 768px) {
|
172 |
.row {
|
173 |
flex-direction: column;
|
|
|
179 |
}
|
180 |
"""
|
181 |
|
182 |
+
# Loading HTML template
|
183 |
+
loading_html = """
|
184 |
+
<div class="loading-container">
|
185 |
+
<div class="loading-spinner"></div>
|
186 |
+
<div class="loading-text">Generating report...</div>
|
187 |
+
</div>
|
188 |
+
"""
|
189 |
+
|
190 |
# Gradio Interface
|
191 |
analyzer = ChartAnalyzer()
|
192 |
|
|
|
196 |
gr.Markdown("""
|
197 |
<div style="text-align: center; margin-bottom: 32px;">
|
198 |
<h1 style="color: var(--primary-color); font-size: 2.5rem; margin-bottom: 16px;">
|
199 |
+
π CryptoVision Pro
|
200 |
</h1>
|
201 |
<p style="color: var(--text-color); font-size: 1.1rem;">
|
202 |
Advanced AI-powered cryptocurrency technical analysis
|
|
|
228 |
gr.Markdown("### π Analysis Report")
|
229 |
analysis_output = gr.Markdown(
|
230 |
label="",
|
231 |
+
value="Analysis report will appear here",
|
232 |
+
elem_classes=["markdown-container"]
|
233 |
)
|
234 |
|
235 |
# Event Handling
|
236 |
analyze_btn.click(
|
237 |
+
fn=lambda: "Generating report...", # Show loading text immediately
|
238 |
+
outputs=analysis_output,
|
239 |
+
queue=False
|
240 |
+
).then(
|
241 |
fn=analyzer.analyze_chart,
|
242 |
inputs=chart_input,
|
243 |
outputs=analysis_output,
|
|
|
245 |
)
|
246 |
|
247 |
if __name__ == "__main__":
|
248 |
+
demo.launch(
|
249 |
+
server_port=int(os.getenv("PORT", 7860)),
|
250 |
+
show_error=True
|
251 |
+
)
|