Spaces:
Runtime error
Runtime error
Create ui/components.py
Browse files- ui/components.py +80 -0
ui/components.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# src/ui/components.py
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from ..config.settings import CHART_PATTERNS, TECHNICAL_INDICATORS
|
| 5 |
+
|
| 6 |
+
def create_sidebar():
|
| 7 |
+
"""Create the sidebar with analysis options"""
|
| 8 |
+
with st.sidebar:
|
| 9 |
+
st.title("🚀 Chart Analysis AI")
|
| 10 |
+
upload_option = st.radio(
|
| 11 |
+
"Choose input method:",
|
| 12 |
+
("Upload Image", "Take Screenshot", "Ask Question"),
|
| 13 |
+
key="sidebar_upload_method"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
uploaded_file = None
|
| 17 |
+
if upload_option == "Upload Image":
|
| 18 |
+
uploaded_file = st.file_uploader(
|
| 19 |
+
"Upload your chart",
|
| 20 |
+
type=["png", "jpg", "jpeg"],
|
| 21 |
+
key="sidebar_file_uploader"
|
| 22 |
+
)
|
| 23 |
+
elif upload_option == "Take Screenshot":
|
| 24 |
+
if st.button("Take Screenshot", key="sidebar_screenshot_btn"):
|
| 25 |
+
st.info("Feature coming soon! For now, please use the Upload Image option.")
|
| 26 |
+
|
| 27 |
+
st.subheader("Analysis Options")
|
| 28 |
+
patterns = st.multiselect(
|
| 29 |
+
"Patterns to Look For",
|
| 30 |
+
CHART_PATTERNS,
|
| 31 |
+
key="sidebar_patterns"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
indicators = st.multiselect(
|
| 35 |
+
"Technical Indicators",
|
| 36 |
+
TECHNICAL_INDICATORS,
|
| 37 |
+
key="sidebar_indicators"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
return upload_option, uploaded_file, patterns, indicators
|
| 41 |
+
|
| 42 |
+
def show_analysis_section(uploaded_file):
|
| 43 |
+
"""Show the main analysis section"""
|
| 44 |
+
if uploaded_file is not None:
|
| 45 |
+
st.image(uploaded_file, caption="Uploaded Chart", use_container_width=True)
|
| 46 |
+
|
| 47 |
+
analyze_btn = st.button("Analyze Chart", key="main_analyze_btn")
|
| 48 |
+
return analyze_btn
|
| 49 |
+
|
| 50 |
+
def show_chat_history(chat_history):
|
| 51 |
+
"""Display chat history"""
|
| 52 |
+
st.subheader("Chat History")
|
| 53 |
+
for idx, chat in enumerate(chat_history):
|
| 54 |
+
with st.expander(
|
| 55 |
+
f"Analysis {idx + 1} - {chat.get('timestamp', 'No date')}",
|
| 56 |
+
key=f"chat_expander_{idx}"
|
| 57 |
+
):
|
| 58 |
+
st.write(chat.get('analysis', ''))
|
| 59 |
+
if chat.get('question'):
|
| 60 |
+
st.write(f"Follow-up: {chat['question']}")
|
| 61 |
+
|
| 62 |
+
def show_follow_up_section(current_analysis):
|
| 63 |
+
"""Show the follow-up question section"""
|
| 64 |
+
st.subheader("Continue Analysis")
|
| 65 |
+
follow_up = st.text_input(
|
| 66 |
+
"Ask a follow-up question:",
|
| 67 |
+
key="followup_input"
|
| 68 |
+
)
|
| 69 |
+
send_btn = st.button("Send", key="followup_send_btn")
|
| 70 |
+
return follow_up if send_btn else None
|
| 71 |
+
|
| 72 |
+
def show_save_options():
|
| 73 |
+
"""Show save chat options"""
|
| 74 |
+
st.subheader("Save Analysis")
|
| 75 |
+
save_name = st.text_input(
|
| 76 |
+
"Save chat as (optional):",
|
| 77 |
+
key="save_chat_name"
|
| 78 |
+
)
|
| 79 |
+
save_btn = st.button("Save", key="save_chat_btn")
|
| 80 |
+
return save_name if save_btn else None
|