Spaces:
Sleeping
Sleeping
Update Gradio app with multiple files
Browse files- app.py +84 -77
- requirements.txt +21 -17
app.py
CHANGED
|
@@ -2,9 +2,6 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
import numpy as np
|
| 5 |
-
|
| 6 |
-
# ASUMSI: Komponen-komponen berikut sudah ada dan berfungsi
|
| 7 |
-
# dari file data_processor.py, sentiment_analyzer.py, model_handler.py, dan trading_logic.py
|
| 8 |
from data_processor import DataProcessor
|
| 9 |
from sentiment_analyzer import SentimentAnalyzer
|
| 10 |
from model_handler import ModelHandler
|
|
@@ -72,7 +69,6 @@ def update_analysis(interval):
|
|
| 72 |
|
| 73 |
except Exception as e:
|
| 74 |
error_msg = f"Error: {str(e)}"
|
| 75 |
-
# Mengembalikan nilai yang dapat di-update untuk semua 7 output
|
| 76 |
return [gr.update(value=error_msg)] * 7
|
| 77 |
|
| 78 |
def create_candlestick_chart(df, interval):
|
|
@@ -203,27 +199,26 @@ def create_sentiment_gauge(score):
|
|
| 203 |
|
| 204 |
return fig
|
| 205 |
|
| 206 |
-
# --- FUNGSI YANG DIPERBAIKI ---
|
| 207 |
def create_fundamentals_gauge(fundamentals):
|
| 208 |
"""Create fundamentals gauge"""
|
| 209 |
value = fundamentals.get('Gold Strength Index', 50)
|
| 210 |
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
)
|
| 227 |
|
| 228 |
fig.update_layout(
|
| 229 |
template='plotly_dark',
|
|
@@ -234,78 +229,90 @@ def create_fundamentals_gauge(fundamentals):
|
|
| 234 |
)
|
| 235 |
|
| 236 |
return fig
|
| 237 |
-
# --- AKHIR FUNGSI YANG DIPERBAIKI ---
|
| 238 |
-
|
| 239 |
-
# --- Gradio UI definition (Tambahan untuk kode lengkap) ---
|
| 240 |
|
| 241 |
-
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
|
| 244 |
with gr.Row():
|
| 245 |
-
|
| 246 |
-
[
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
)
|
|
|
|
| 251 |
|
| 252 |
-
with gr.
|
| 253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
-
with gr.
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
col_count=(2, "fixed"),
|
| 260 |
-
label="Key Metrics",
|
| 261 |
-
interactive=False
|
| 262 |
-
)
|
| 263 |
-
|
| 264 |
-
fundamentals_fig_output = gr.Plot(label="Fundamentals Gauge")
|
| 265 |
-
fundamentals_df_output = gr.Dataframe(
|
| 266 |
-
headers=["Metric", "Value"],
|
| 267 |
-
label="Fundamental Data",
|
| 268 |
-
interactive=False,
|
| 269 |
-
visible=False
|
| 270 |
-
)
|
| 271 |
-
|
| 272 |
-
with gr.Row():
|
| 273 |
-
pred_output = gr.Plot(label="Price Prediction")
|
| 274 |
-
sentiment_fig_output = gr.Plot(label="Market Sentiment Gauge")
|
| 275 |
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
fn=update_analysis,
|
| 280 |
-
inputs=
|
| 281 |
outputs=[
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
sentiment_fig_output,
|
| 286 |
-
news_output,
|
| 287 |
-
fundamentals_fig_output,
|
| 288 |
-
fundamentals_df_output
|
| 289 |
]
|
| 290 |
)
|
| 291 |
|
| 292 |
-
# Initial load
|
| 293 |
demo.load(
|
| 294 |
fn=update_analysis,
|
| 295 |
-
inputs=
|
| 296 |
outputs=[
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
sentiment_fig_output,
|
| 301 |
-
news_output,
|
| 302 |
-
fundamentals_fig_output,
|
| 303 |
-
fundamentals_df_output
|
| 304 |
]
|
| 305 |
)
|
| 306 |
|
| 307 |
if __name__ == "__main__":
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
| 5 |
from data_processor import DataProcessor
|
| 6 |
from sentiment_analyzer import SentimentAnalyzer
|
| 7 |
from model_handler import ModelHandler
|
|
|
|
| 69 |
|
| 70 |
except Exception as e:
|
| 71 |
error_msg = f"Error: {str(e)}"
|
|
|
|
| 72 |
return [gr.update(value=error_msg)] * 7
|
| 73 |
|
| 74 |
def create_candlestick_chart(df, interval):
|
|
|
|
| 199 |
|
| 200 |
return fig
|
| 201 |
|
|
|
|
| 202 |
def create_fundamentals_gauge(fundamentals):
|
| 203 |
"""Create fundamentals gauge"""
|
| 204 |
value = fundamentals.get('Gold Strength Index', 50)
|
| 205 |
|
| 206 |
+
fig = go.Figure(
|
| 207 |
+
go.Indicator(
|
| 208 |
+
mode="gauge+number",
|
| 209 |
+
value=value,
|
| 210 |
+
title={'text': "Gold Strength Index"},
|
| 211 |
+
gauge={
|
| 212 |
+
'axis': {'range': [0, 100]},
|
| 213 |
+
'bar': {'color': "#FFD700"},
|
| 214 |
+
'steps': [
|
| 215 |
+
{'range': [0, 30], 'color': "rgba(255,0,0,0.5)"},
|
| 216 |
+
{'range': [30, 70], 'color': "rgba(255,255,255,0.3)"},
|
| 217 |
+
{'range': [70, 100], 'color': "rgba(0,255,0,0.5)"}
|
| 218 |
+
]
|
| 219 |
+
}
|
| 220 |
+
)
|
| 221 |
+
)
|
| 222 |
|
| 223 |
fig.update_layout(
|
| 224 |
template='plotly_dark',
|
|
|
|
| 229 |
)
|
| 230 |
|
| 231 |
return fig
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
+
# Gradio Interface
|
| 234 |
+
with gr.Blocks(
|
| 235 |
+
title="Gold Trading Analysis",
|
| 236 |
+
theme=gr.themes.Default(
|
| 237 |
+
primary_hue="yellow",
|
| 238 |
+
secondary_hue="yellow",
|
| 239 |
+
neutral_hue="black"
|
| 240 |
+
),
|
| 241 |
+
css="""
|
| 242 |
+
body {background: #000000; color: #FFFFFF}
|
| 243 |
+
.gradio-container {background: #000000}
|
| 244 |
+
.gr-button-primary {background: #FFD700 !important; color: #000000 !important}
|
| 245 |
+
.gr-padded {padding: 20px}
|
| 246 |
+
"""
|
| 247 |
+
) as demo:
|
| 248 |
+
|
| 249 |
+
gr.HTML("""
|
| 250 |
+
<div style="text-align: center; padding: 20px; background: black;">
|
| 251 |
+
<h1 style="color: #FFD700; margin: 0;">Gold Trading Analysis & Prediction</h1>
|
| 252 |
+
<p style="color: white; margin: 10px 0;">AI-powered analysis for Gold Futures (GC=F)</p>
|
| 253 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank"
|
| 254 |
+
style="color: #FFD700; text-decoration: none; font-weight: bold;">
|
| 255 |
+
Built with anycoder
|
| 256 |
+
</a>
|
| 257 |
+
</div>
|
| 258 |
+
""")
|
| 259 |
|
| 260 |
with gr.Row():
|
| 261 |
+
interval = gr.Dropdown(
|
| 262 |
+
choices=["5m", "15m", "30m", "1h", "4h", "1d", "1wk", "1mo", "3mo"],
|
| 263 |
+
value="1d",
|
| 264 |
+
label="Time Interval",
|
| 265 |
+
info="Select analysis timeframe"
|
| 266 |
)
|
| 267 |
+
refresh_btn = gr.Button("🔄 Refresh Analysis", variant="primary")
|
| 268 |
|
| 269 |
+
with gr.Tabs():
|
| 270 |
+
with gr.Tab("📊 Technical Analysis"):
|
| 271 |
+
with gr.Row():
|
| 272 |
+
chart = gr.Plot(label="Price Chart")
|
| 273 |
+
pred_chart = gr.Plot(label="Price Forecast")
|
| 274 |
+
metrics = gr.JSON(label="Trading Signals")
|
| 275 |
|
| 276 |
+
with gr.Tab("📰 Market Sentiment"):
|
| 277 |
+
with gr.Row():
|
| 278 |
+
sentiment_chart = gr.Plot(label="Sentiment Gauge")
|
| 279 |
+
news_html = gr.HTML(label="Market News")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
|
| 281 |
+
with gr.Tab("📈 Fundamentals"):
|
| 282 |
+
with gr.Row():
|
| 283 |
+
fundamentals_chart = gr.Plot(label="Strength Index")
|
| 284 |
+
fundamentals_table = gr.Dataframe(
|
| 285 |
+
headers=["Metric", "Value"],
|
| 286 |
+
label="Key Fundamentals",
|
| 287 |
+
interactive=False
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
# Event handlers
|
| 291 |
+
refresh_btn.click(
|
| 292 |
fn=update_analysis,
|
| 293 |
+
inputs=interval,
|
| 294 |
outputs=[
|
| 295 |
+
chart, metrics, pred_chart,
|
| 296 |
+
sentiment_chart, news_html,
|
| 297 |
+
fundamentals_chart, fundamentals_table
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
]
|
| 299 |
)
|
| 300 |
|
|
|
|
| 301 |
demo.load(
|
| 302 |
fn=update_analysis,
|
| 303 |
+
inputs=interval,
|
| 304 |
outputs=[
|
| 305 |
+
chart, metrics, pred_chart,
|
| 306 |
+
sentiment_chart, news_html,
|
| 307 |
+
fundamentals_chart, fundamentals_table
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
]
|
| 309 |
)
|
| 310 |
|
| 311 |
if __name__ == "__main__":
|
| 312 |
+
demo.launch(
|
| 313 |
+
server_name="0.0.0.0",
|
| 314 |
+
server_port=7860,
|
| 315 |
+
share=False,
|
| 316 |
+
show_api=True,
|
| 317 |
+
ssr_mode=False
|
| 318 |
+
)
|
requirements.txt
CHANGED
|
@@ -1,30 +1,34 @@
|
|
| 1 |
-
|
| 2 |
numpy
|
|
|
|
| 3 |
gradio
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
kaleido
|
| 6 |
requests
|
| 7 |
Pillow
|
| 8 |
-
matplotlib
|
| 9 |
-
openpyxl
|
| 10 |
-
xlrd
|
| 11 |
-
python-docx
|
| 12 |
-
PyPDF2
|
| 13 |
scikit-learn
|
| 14 |
-
scipy
|
| 15 |
-
joblib
|
| 16 |
-
git+https://github.com/huggingface/transformers
|
| 17 |
-
sentencepiece
|
| 18 |
torch
|
|
|
|
| 19 |
accelerate
|
| 20 |
tokenizers
|
| 21 |
datasets
|
| 22 |
-
yfinance
|
| 23 |
-
ta-lib
|
| 24 |
-
seaborn
|
| 25 |
scipy
|
| 26 |
joblib
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
tqdm
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
numpy
|
| 3 |
+
plotly
|
| 4 |
gradio
|
| 5 |
+
openpyxl
|
| 6 |
+
xlrd
|
| 7 |
+
pyarrow
|
| 8 |
kaleido
|
| 9 |
requests
|
| 10 |
Pillow
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
scikit-learn
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
torch
|
| 13 |
+
git+https://github.com/huggingface/transformers
|
| 14 |
accelerate
|
| 15 |
tokenizers
|
| 16 |
datasets
|
|
|
|
|
|
|
|
|
|
| 17 |
scipy
|
| 18 |
joblib
|
| 19 |
+
matplotlib
|
| 20 |
+
seaborn
|
| 21 |
+
yfinance
|
| 22 |
+
ta-lib
|
| 23 |
+
streamlit
|
| 24 |
+
fastapi
|
| 25 |
+
uvicorn
|
| 26 |
+
pydantic
|
| 27 |
+
python-dotenv
|
| 28 |
+
jupyter
|
| 29 |
+
ipykernel
|
| 30 |
tqdm
|
| 31 |
+
click
|
| 32 |
+
pytest
|
| 33 |
+
black
|
| 34 |
+
flake8
|