Spaces:
Runtime error
Runtime error
File size: 6,633 Bytes
313e8dd 1a4a9b5 313e8dd ab4b772 1a4a9b5 073f7c3 1a4a9b5 8dce2fb 1a4a9b5 8dce2fb 1a4a9b5 073f7c3 1a4a9b5 8dce2fb 1a4a9b5 8dce2fb 1a4a9b5 8dce2fb 1a4a9b5 8dce2fb 1a4a9b5 8dce2fb 1a4a9b5 8dce2fb 1a4a9b5 8dce2fb 1a4a9b5 ab4b772 8d20b92 6e94685 ab4b772 6e94685 ab4b772 58046c9 1a4a9b5 18310bf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# ui/components.py
import streamlit as st
from config.settings import CHART_PATTERNS, TECHNICAL_INDICATORS
# ui/components.py
import streamlit as st
from datetime import datetime
from config.settings import CHART_PATTERNS, TECHNICAL_INDICATORS
def create_sidebar():
"""Create the sidebar with analysis options"""
with st.sidebar:
st.title("🚀 Chart Analysis AI")
# Add New Chat button at the top
if st.button("📝 New Chat", key="new_chat_button", type="primary"):
# Save current chat if it exists
if st.session_state.chat_history:
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
st.session_state['last_saved_chat'] = f"chat_{timestamp}"
return "new_chat", None, [], [], "Individual Analysis"
upload_option = st.radio(
"Choose input method:",
("Upload Images", "Take Screenshot", "Ask Question"),
key="sidebar_upload_method"
)
uploaded_files = None
if upload_option == "Upload Images":
uploaded_files = st.file_uploader(
"Upload your charts",
type=["png", "jpg", "jpeg"],
accept_multiple_files=True,
key="sidebar_file_uploader"
)
if uploaded_files:
st.info(f"Uploaded {len(uploaded_files)} charts")
elif upload_option == "Take Screenshot":
if st.button("Take Screenshot", key="sidebar_screenshot_btn"):
st.info("Feature coming soon! For now, please use the Upload Images option.")
st.subheader("Analysis Options")
patterns = st.multiselect(
"Patterns to Look For",
CHART_PATTERNS,
key="sidebar_patterns"
)
indicators = st.multiselect(
"Technical Indicators",
TECHNICAL_INDICATORS,
key="sidebar_indicators"
)
# Add comparison options
if uploaded_files and len(uploaded_files) > 1:
st.subheader("Comparison Options")
comparison_type = st.selectbox(
"Comparison Type",
["Individual Analysis", "Correlated Analysis", "Market Trend Analysis"],
key="comparison_type"
)
st.info("""
- Individual Analysis: Analyze each chart separately
- Correlated Analysis: Find relationships between charts
- Market Trend Analysis: Identify broader market patterns
""")
else:
comparison_type = "Individual Analysis"
return upload_option, uploaded_files, patterns, indicators, comparison_type
def show_analysis_section(uploaded_files):
"""Show the main analysis section"""
if uploaded_files:
# Create a grid layout for multiple images
cols = st.columns(min(len(uploaded_files), 2)) # Max 2 columns
for idx, uploaded_file in enumerate(uploaded_files):
with cols[idx % 2]:
st.image(uploaded_file, caption=f"Chart {idx + 1}", use_container_width=True)
analyze_btn = st.button("Analyze Charts", key="main_analyze_btn")
return analyze_btn
def show_chat_history(chat_history):
"""Display chat history"""
st.subheader("Current Chat History")
for idx, chat in enumerate(chat_history):
timestamp = chat.get('timestamp', datetime.now().isoformat())
analysis_type = chat.get('analysis_type', 'Analysis')
with st.container():
if analysis_type in ['Individual', 'Correlated Analysis']:
st.markdown("**Initial Analysis:**")
elif 'question' in chat:
st.markdown(f"**Follow-up Question:** {chat['question']}")
st.markdown(chat.get('analysis', ''))
st.markdown("---")
def show_follow_up_section(key_suffix="", previous_response=None):
"""Show the follow-up question section with enhanced chat UI"""
# Show previous response if provided
if previous_response:
with st.container():
st.markdown("**Previous Response:**")
st.markdown(previous_response)
st.markdown("---")
# Input section
col1, col2 = st.columns([4, 1])
with col1:
follow_up = st.text_input(
"Ask a follow-up question:",
key=f"followup_input_{key_suffix}",
placeholder="Type your question here..."
)
with col2:
send_btn = st.button("Send", key=f"followup_send_btn_{key_suffix}")
return follow_up if send_btn else None
def show_save_options():
"""Show save chat options"""
st.subheader("Save Analysis")
save_name = st.text_input(
"Save chat as (optional):",
key="save_chat_name"
)
save_btn = st.button("Save", key="save_chat_btn")
return save_name if save_btn else None
def display_conversation_group(conversation):
"""Display a group of related chat messages"""
if not conversation:
return
# Use the first message timestamp for the expander label
timestamp = conversation[0].get('timestamp', 'No date')
analysis_type = conversation[0].get('analysis_type', 'Analysis')
with st.expander(f"{analysis_type} from {timestamp[:16]}", expanded=True):
for message in conversation:
if message.get('analysis_type') in ['Individual', 'Correlated Analysis']:
st.markdown("**Initial Analysis:**")
elif message.get('question'):
st.markdown(f"**Follow-up Question:** {message['question']}")
st.markdown(message.get('analysis', ''))
def create_expertise_selector():
"""Create expertise level selector"""
if 'expertise_level' not in st.session_state:
st.session_state.expertise_level = "Novice"
expertise_descriptions = {
"Novice": "New to trading, explain concepts in simple terms",
"Intermediate": "Familiar with basic concepts, can handle some technical terms",
"Expert": "Experienced trader, use full technical analysis terminology"
}
with st.sidebar:
st.subheader("Expertise Level")
expertise_level = st.selectbox(
"Select your trading knowledge level:",
list(expertise_descriptions.keys()),
key="expertise_selector"
)
st.info(expertise_descriptions[expertise_level])
st.session_state.expertise_level = expertise_level
return expertise_level |