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 |
-
from typing import Tuple
|
6 |
|
7 |
# OpenAI API Configuration
|
8 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
@@ -23,9 +22,6 @@ SYSTEM_PROMPT = """Professional Crypto Technical Analyst:
|
|
23 |
10. Provide time-based projections"""
|
24 |
|
25 |
class ChartAnalyzer:
|
26 |
-
def __init__(self):
|
27 |
-
self.last_analysis = ""
|
28 |
-
|
29 |
def encode_image(self, image_path: str) -> str:
|
30 |
"""Encode image to base64 with validation"""
|
31 |
if not os.path.exists(image_path):
|
@@ -64,34 +60,118 @@ class ChartAnalyzer:
|
|
64 |
max_tokens=MAX_TOKENS
|
65 |
)
|
66 |
|
67 |
-
|
68 |
-
return self.last_analysis
|
69 |
|
70 |
except openai.error.APIError as e:
|
71 |
return f"OpenAI API Error: {str(e)}"
|
72 |
except Exception as e:
|
73 |
return f"Analysis Error: {str(e)}"
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
# Gradio Interface
|
76 |
analyzer = ChartAnalyzer()
|
77 |
|
78 |
-
with gr.Blocks(theme=gr.themes.Soft(
|
79 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
with gr.Row():
|
82 |
-
with gr.Column(scale=1):
|
|
|
83 |
chart_input = gr.Image(
|
84 |
type="filepath",
|
85 |
-
label="
|
86 |
sources=["upload"],
|
87 |
-
height=
|
|
|
|
|
|
|
|
|
|
|
88 |
)
|
89 |
-
analyze_btn = gr.Button("Start Analysis", variant="primary")
|
90 |
|
91 |
-
with gr.Column(scale=2):
|
|
|
92 |
analysis_output = gr.Markdown(
|
93 |
-
label="
|
94 |
-
elem_classes=["
|
95 |
)
|
96 |
|
97 |
analyze_btn.click(
|
|
|
2 |
import openai
|
3 |
import os
|
4 |
import base64
|
|
|
5 |
|
6 |
# OpenAI API Configuration
|
7 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
|
22 |
10. Provide time-based projections"""
|
23 |
|
24 |
class ChartAnalyzer:
|
|
|
|
|
|
|
25 |
def encode_image(self, image_path: str) -> str:
|
26 |
"""Encode image to base64 with validation"""
|
27 |
if not os.path.exists(image_path):
|
|
|
60 |
max_tokens=MAX_TOKENS
|
61 |
)
|
62 |
|
63 |
+
return response.choices[0].message.content
|
|
|
64 |
|
65 |
except openai.error.APIError as e:
|
66 |
return f"OpenAI API Error: {str(e)}"
|
67 |
except Exception as e:
|
68 |
return f"Analysis Error: {str(e)}"
|
69 |
|
70 |
+
# Custom CSS for professional look
|
71 |
+
custom_css = """
|
72 |
+
:root {
|
73 |
+
--primary-color: #2563eb;
|
74 |
+
--secondary-color: #1e40af;
|
75 |
+
--background-color: #f8fafc;
|
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 |
+
.analysis-box {
|
86 |
+
background-color: white;
|
87 |
+
border-radius: 12px;
|
88 |
+
padding: 24px;
|
89 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
90 |
+
border: 1px solid var(--border-color);
|
91 |
+
height: 600px;
|
92 |
+
overflow-y: auto;
|
93 |
+
}
|
94 |
+
|
95 |
+
.upload-box {
|
96 |
+
background-color: white;
|
97 |
+
border-radius: 12px;
|
98 |
+
padding: 24px;
|
99 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
100 |
+
border: 1px solid var(--border-color);
|
101 |
+
}
|
102 |
+
|
103 |
+
.primary-button {
|
104 |
+
background-color: var(--primary-color) !important;
|
105 |
+
color: white !important;
|
106 |
+
border-radius: 8px !important;
|
107 |
+
padding: 12px 24px !important;
|
108 |
+
font-weight: 500 !important;
|
109 |
+
}
|
110 |
+
|
111 |
+
.primary-button:hover {
|
112 |
+
background-color: var(--secondary-color) !important;
|
113 |
+
}
|
114 |
+
|
115 |
+
.markdown-container {
|
116 |
+
max-width: 800px;
|
117 |
+
margin: 0 auto;
|
118 |
+
}
|
119 |
+
|
120 |
+
.markdown-container h2 {
|
121 |
+
color: var(--primary-color);
|
122 |
+
border-bottom: 2px solid var(--border-color);
|
123 |
+
padding-bottom: 8px;
|
124 |
+
margin-top: 24px;
|
125 |
+
}
|
126 |
+
|
127 |
+
.markdown-container ul {
|
128 |
+
list-style-type: disc;
|
129 |
+
padding-left: 24px;
|
130 |
+
}
|
131 |
+
|
132 |
+
.markdown-container code {
|
133 |
+
background-color: var(--background-color);
|
134 |
+
padding: 2px 4px;
|
135 |
+
border-radius: 4px;
|
136 |
+
font-family: monospace;
|
137 |
+
}
|
138 |
+
"""
|
139 |
+
|
140 |
# Gradio Interface
|
141 |
analyzer = ChartAnalyzer()
|
142 |
|
143 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
144 |
+
gr.Markdown("""
|
145 |
+
<div style="text-align: center; margin-bottom: 32px;">
|
146 |
+
<h1 style="color: var(--primary-color); font-size: 2.5rem; margin-bottom: 16px;">
|
147 |
+
π CryptoVision Pro
|
148 |
+
</h1>
|
149 |
+
<p style="color: var(--text-color); font-size: 1.1rem;">
|
150 |
+
Advanced AI-powered cryptocurrency technical analysis
|
151 |
+
</p>
|
152 |
+
</div>
|
153 |
+
""")
|
154 |
|
155 |
with gr.Row():
|
156 |
+
with gr.Column(scale=1, elem_classes=["upload-box"]):
|
157 |
+
gr.Markdown("### π€ Upload Your Chart")
|
158 |
chart_input = gr.Image(
|
159 |
type="filepath",
|
160 |
+
label="",
|
161 |
sources=["upload"],
|
162 |
+
height=300
|
163 |
+
)
|
164 |
+
analyze_btn = gr.Button(
|
165 |
+
"Analyze Chart",
|
166 |
+
variant="primary",
|
167 |
+
elem_classes=["primary-button"]
|
168 |
)
|
|
|
169 |
|
170 |
+
with gr.Column(scale=2, elem_classes=["analysis-box"]):
|
171 |
+
gr.Markdown("### π Analysis Report")
|
172 |
analysis_output = gr.Markdown(
|
173 |
+
label="",
|
174 |
+
elem_classes=["markdown-container"]
|
175 |
)
|
176 |
|
177 |
analyze_btn.click(
|