hhh / pages /step2.py
github-actions[bot]
Deploy from GitHub Actions (commit: 8b247ffacd77c0672965b8378f1d52a7dcd187ae)
9366995
"""
Step 2: File Upload
"""
import streamlit as st
def render_step2():
"""Render Step 2: Upload Your Chat File"""
st.header("Step 2: Upload Your Chat File")
st.markdown("Upload a conversation file in JSON, TXT, or CSV format.")
from parsers.conversation_parser import parse_conversation
uploaded_file = st.file_uploader(
"Choose a conversation file",
type=['json', 'txt', 'csv'],
help="Supported formats: JSON, TXT, CSV"
)
if uploaded_file is not None:
# Parse file
file_content = uploaded_file.read().decode('utf-8')
file_type = uploaded_file.name.split('.')[-1]
with st.spinner("Parsing conversation file..."):
utterances = parse_conversation(file_content, file_type)
if utterances:
st.session_state.utterances = utterances
st.session_state.conversation_uploaded = True
st.success(f"βœ… Successfully parsed {len(utterances)} utterances")
# Show conversation preview
with st.expander("Preview Conversation"):
for i, utterance in enumerate(utterances[:5]): # Show first 5
st.write(f"**{utterance['speaker']}:** {utterance['text']}")
if len(utterances) > 5:
st.write(f"... and {len(utterances) - 5} more utterances")
else:
st.error("Failed to parse conversation file. Please check the format.")
else:
st.session_state.conversation_uploaded = False
st.info("πŸ‘† Please upload a conversation file to proceed.")
col1, col2 = st.columns(2)
with col1:
if st.button("← Back", use_container_width=True):
st.session_state.step = 1
st.rerun()
with col2:
if st.button("Next: Select Metrics β†’", type="primary", use_container_width=True, disabled=not st.session_state.conversation_uploaded):
st.session_state.step = 3
st.rerun()