File size: 1,994 Bytes
9366995
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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()