import streamlit as st
import plotly.graph_objs as go
import plotly.express as px
from plotly.subplots import make_subplots
from main import CryptoCrew
import time
import os
import pandas as pd
st.set_page_config(page_title="Advanced Crypto Analyst", page_icon="📈", layout="wide")
# Custom CSS for better styling
st.markdown("""
""", unsafe_allow_html=True)
st.title("⚡ Advanced Crypto Analyst")
st.markdown("*Powered by Together AI with Enhanced Multi-Agent Analysis*")
# Enhanced caching with longer TTL for detailed analysis
@st.cache_data(ttl=600) # Cache for 10 minutes
def analyze_crypto(crypto_name):
crypto_crew = CryptoCrew(crypto_name.lower())
return crypto_crew.run()
# Input section
col1, col2 = st.columns([3, 1])
with col1:
crypto = st.text_input("Enter cryptocurrency name:", placeholder="bitcoin, ethereum, solana, cardano...")
with col2:
st.markdown("
", unsafe_allow_html=True)
analyze_btn = st.button("🚀 Analyze", type="primary", use_container_width=True)
if analyze_btn and crypto:
start_time = time.time()
with st.spinner("🔍 Performing comprehensive analysis... This may take 30-60 seconds for detailed results!"):
try:
result = analyze_crypto(crypto)
end_time = time.time()
# Enhanced header metrics
st.markdown("## 📊 Analysis Dashboard")
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric("Analysis Time", f"{end_time - start_time:.1f}s", "✅ Complete")
with col2:
rec = result.get("recommendation", {}).get("action", "HOLD")
confidence = result.get("recommendation", {}).get("confidence", "Medium")
st.metric("Recommendation", rec, f"Confidence: {confidence}")
with col3:
risk = result.get("risk_assessment", "Moderate Risk")
st.metric("Risk Level", risk)
with col4:
last_updated = result.get("last_updated", "Unknown")
st.metric("Last Updated", last_updated.split()[1] if " " in last_updated else "N/A")
# Market Data Section
st.markdown("## 💰 Market Metrics")
market_data = result.get("market_data", {})
col1, col2, col3 = st.columns(3)
with col1:
price = market_data.get("current_price", "N/A")
price_change_24h = market_data.get("price_change_24h", "N/A")
st.metric("Current Price", price, price_change_24h)
with col2:
market_cap = market_data.get("market_cap", "N/A")
st.metric("Market Cap", market_cap)
with col3:
volume_24h = market_data.get("volume_24h", "N/A")
st.metric("24h Volume", volume_24h)
col4, col5, col6 = st.columns(3)
with col4:
price_change_7d = market_data.get("price_change_7d", "N/A")
st.metric("7-Day Change", price_change_7d)
with col5:
dominance = market_data.get("market_dominance", "N/A")
st.metric("Market Dominance", dominance)
with col6:
st.metric("Analysis Depth", "Advanced", "🎯 Multi-Agent")
# Technical Analysis Section
st.markdown("## 📈 Technical Analysis")
technical_data = result.get("technical_data", {})
col1, col2 = st.columns(2)
with col1:
rsi = technical_data.get("rsi", "N/A")
rsi_signal = technical_data.get("rsi_signal", "Neutral")
st.metric("RSI (14)", rsi, rsi_signal)
trend = technical_data.get("trend", "Neutral")
st.metric("Current Trend", trend)
with col2:
ma_7d = technical_data.get("moving_average_7d", "N/A")
st.metric("7-Day MA", ma_7d)
support = technical_data.get("support_level", "N/A")
resistance = technical_data.get("resistance_level", "N/A")
st.metric("Support | Resistance", f"{support} | {resistance}")
# Enhanced Sentiment Analysis with Fixed Chart
st.markdown("## 💭 Multi-Source Sentiment Analysis")
sentiment_data = result.get("sentiment", {})
# Create properly differentiated sentiment chart
categories = list(sentiment_data.keys())
values = []
colors = []
sentiment_texts = []
for category, sentiment in sentiment_data.items():
sentiment_texts.append(sentiment)
if sentiment == "Positive":
values.append(1)
colors.append('#00C851') # Green
elif sentiment == "Negative":
values.append(-1)
colors.append('#FF4444') # Red
else:
values.append(0)
colors.append('#FFBB33') # Orange for neutral
# Create sentiment visualization
fig = go.Figure(data=[go.Bar(
x=categories,
y=values,
marker_color=colors,
text=sentiment_texts,
textposition='auto',
hovertemplate='%{x}
Sentiment: %{text}
Score: %{y}
Confidence Level: {confidence}
Reasoning: {reasoning}