Toymakerftw
commited on
Commit
ยท
3d1de25
1
Parent(s):
c5a48ec
Ui improvements
Browse files- app.py +89 -24
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -396,39 +396,104 @@ def analyze_asset_sentiment(asset_input):
|
|
| 396 |
None
|
| 397 |
)
|
| 398 |
|
| 399 |
-
# Update the Gradio interface
|
| 400 |
-
|
| 401 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
|
| 403 |
-
with gr.Row():
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
|
|
|
|
|
|
|
|
|
| 410 |
|
| 411 |
-
with gr.Tabs():
|
| 412 |
-
with gr.TabItem("Sentiment
|
| 413 |
-
gr.Markdown("
|
| 414 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
|
| 416 |
-
with gr.TabItem("Technical Analysis"):
|
| 417 |
-
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
|
|
|
|
|
|
|
|
|
| 426 |
|
| 427 |
analyze_btn.click(
|
| 428 |
analyze_asset_sentiment,
|
| 429 |
inputs=[input_asset],
|
| 430 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
)
|
| 432 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
logging.info("Launching enhanced Gradio interface")
|
| 434 |
iface.queue().launch()
|
|
|
|
| 396 |
None
|
| 397 |
)
|
| 398 |
|
| 399 |
+
# Update the Gradio interface with dark theme and improved UI
|
| 400 |
+
custom_theme = gr.themes.Default(
|
| 401 |
+
primary_hue="emerald",
|
| 402 |
+
secondary_hue="emerald",
|
| 403 |
+
neutral_hue="slate",
|
| 404 |
+
font=[gr.themes.GoogleFont("Inter")],
|
| 405 |
+
).set(
|
| 406 |
+
body_background_fill='*neutral_950',
|
| 407 |
+
button_primary_background_fill='linear-gradient(90deg, #059669 0%, #10b981 100%)',
|
| 408 |
+
button_primary_text_color='white',
|
| 409 |
+
block_background_fill='*neutral_900',
|
| 410 |
+
block_label_text_color='*primary_300',
|
| 411 |
+
block_title_text_color='*primary_300',
|
| 412 |
+
input_background_fill='*neutral_800',
|
| 413 |
+
)
|
| 414 |
+
|
| 415 |
+
with gr.Blocks(theme=custom_theme, css="footer {visibility: hidden}") as iface:
|
| 416 |
+
gr.Markdown("""
|
| 417 |
+
# ๐ Advanced Trading Analytics Suite
|
| 418 |
+
*AI-powered market analysis with real-time sentiment and technical indicators*
|
| 419 |
+
""")
|
| 420 |
|
| 421 |
+
with gr.Row(variant="panel"):
|
| 422 |
+
with gr.Column(scale=3):
|
| 423 |
+
input_asset = gr.Textbox(
|
| 424 |
+
label="๐ Search Asset",
|
| 425 |
+
placeholder="Enter stock name or symbol (e.g., Apple or AAPL)...",
|
| 426 |
+
max_lines=1,
|
| 427 |
+
container=False
|
| 428 |
+
)
|
| 429 |
+
with gr.Column(scale=1):
|
| 430 |
+
analyze_btn = gr.Button("Analyze Now โ", variant="primary", size="lg")
|
| 431 |
|
| 432 |
+
with gr.Tabs(selected=0):
|
| 433 |
+
with gr.TabItem("๐ฐ News Sentiment", id=1):
|
| 434 |
+
gr.Markdown("### ๐ Sentiment Analysis from Latest News")
|
| 435 |
+
with gr.Row():
|
| 436 |
+
sentiment_summary = gr.Label(label="Overall Sentiment",
|
| 437 |
+
value={"Positive": 0, "Neutral": 0, "Negative": 0},
|
| 438 |
+
num_top_classes=3)
|
| 439 |
+
articles_output = gr.HTML(label="Latest News Analysis")
|
| 440 |
|
| 441 |
+
with gr.TabItem("๐ Technical Analysis", id=2):
|
| 442 |
+
with gr.Row():
|
| 443 |
+
with gr.Column(scale=2):
|
| 444 |
+
gr.Markdown("### Price Chart")
|
| 445 |
+
price_chart = gr.Plot(label="Technical Analysis")
|
| 446 |
+
with gr.Column(scale=1):
|
| 447 |
+
gr.Markdown("### Key Indicators")
|
| 448 |
+
ta_metrics = gr.DataFrame(
|
| 449 |
+
headers=["Indicator", "Value"],
|
| 450 |
+
datatype=["str", "number"],
|
| 451 |
+
interactive=False,
|
| 452 |
+
label="Technical Metrics"
|
| 453 |
+
)
|
| 454 |
+
|
| 455 |
+
with gr.TabItem("๐ก Recommendation", id=3):
|
| 456 |
+
with gr.Row():
|
| 457 |
+
with gr.Column(scale=1):
|
| 458 |
+
gr.Markdown("### Trading Recommendation")
|
| 459 |
+
recommendation_output = gr.Markdown()
|
| 460 |
+
with gr.Column(scale=1):
|
| 461 |
+
gr.Markdown("### Risk Analysis")
|
| 462 |
+
risk_indicators = gr.DataFrame(
|
| 463 |
+
headers=["Risk Factor", "Severity"],
|
| 464 |
+
datatype=["str", "str"],
|
| 465 |
+
interactive=False
|
| 466 |
+
)
|
| 467 |
|
| 468 |
+
# Add loading animation
|
| 469 |
+
analyze_btn.click(
|
| 470 |
+
lambda: gr.Loading(loader_args={
|
| 471 |
+
'text': '๐ฎ Analyzing market data...',
|
| 472 |
+
'spinner_type': 'dots',
|
| 473 |
+
'timeout': 10
|
| 474 |
+
}),
|
| 475 |
+
outputs=[]
|
| 476 |
+
)
|
| 477 |
|
| 478 |
analyze_btn.click(
|
| 479 |
analyze_asset_sentiment,
|
| 480 |
inputs=[input_asset],
|
| 481 |
+
outputs=[
|
| 482 |
+
articles_output,
|
| 483 |
+
ta_metrics,
|
| 484 |
+
recommendation_output,
|
| 485 |
+
price_chart
|
| 486 |
+
]
|
| 487 |
)
|
| 488 |
|
| 489 |
+
# Additional callback for sentiment summary
|
| 490 |
+
def update_sentiment_summary(articles):
|
| 491 |
+
sentiments = [a['sentiment']['label'].lower() for a in articles]
|
| 492 |
+
return {
|
| 493 |
+
"Positive": sentiments.count('positive'),
|
| 494 |
+
"Neutral": sentiments.count('neutral'),
|
| 495 |
+
"Negative": sentiments.count('negative')
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
logging.info("Launching enhanced Gradio interface")
|
| 499 |
iface.queue().launch()
|
requirements.txt
CHANGED
|
@@ -7,4 +7,5 @@ GoogleNews==1.6.14
|
|
| 7 |
yfinance
|
| 8 |
fuzzywuzzy
|
| 9 |
matplotlib
|
| 10 |
-
numpy
|
|
|
|
|
|
| 7 |
yfinance
|
| 8 |
fuzzywuzzy
|
| 9 |
matplotlib
|
| 10 |
+
numpy
|
| 11 |
+
python-Levenshtein
|