LeoWalker commited on
Commit
5847b80
Β·
1 Parent(s): 97f672f

basic streamlit app is working

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # Set Streamlit to wide mode
4
+ st.set_page_config(layout="wide")
5
+
6
+ # Define the function to process the question
7
+ def ProcessQuestion(question):
8
+ # Placeholder for the actual implementation
9
+ # This should return answers from two models, A and B
10
+ answer_a = "Answer from Model A"
11
+ answer_b = "Answer from Model B"
12
+ return answer_a, answer_b
13
+
14
+ # Initialize session state if not already done
15
+ if 'results_displayed' not in st.session_state:
16
+ st.session_state['results_displayed'] = False
17
+ if 'answer_a' not in st.session_state:
18
+ st.session_state['answer_a'] = ""
19
+ if 'answer_b' not in st.session_state:
20
+ st.session_state['answer_b'] = ""
21
+ if 'selected_model' not in st.session_state:
22
+ st.session_state['selected_model'] = ""
23
+ if 'question' not in st.session_state:
24
+ st.session_state['question'] = ""
25
+
26
+ # Streamlit app layout
27
+ st.title("Chatbot Comparison")
28
+
29
+ # Create columns for the input and model selection
30
+ input_col, control_col = st.columns([4, 1])
31
+
32
+ with input_col:
33
+ # Text box for user input with character limit
34
+ question = st.text_area("Enter your question here (max 1000 characters):", max_chars=1000)
35
+
36
+ with control_col:
37
+ # Submit button
38
+ submit_button = st.button("Submit")
39
+
40
+ if submit_button:
41
+ if question:
42
+ if len(question) <= 1000:
43
+ # Process the question and get answers
44
+ answer_a, answer_b = ProcessQuestion(question)
45
+
46
+ # Save answers and state to session state
47
+ st.session_state['answer_a'] = answer_a
48
+ st.session_state['answer_b'] = answer_b
49
+ # st.session_state['selected_model'] = selected_model
50
+ st.session_state['question'] = question
51
+ st.session_state['results_displayed'] = True
52
+ else:
53
+ st.error("Your question exceeds the 1,000 character limit. Please shorten your question.")
54
+ else:
55
+ st.error("Please enter a question and select a model.")
56
+
57
+ # Display results if available in session state
58
+ if st.session_state['results_displayed']:
59
+ col1, col2 = st.columns(2)
60
+
61
+ with col1:
62
+ st.write(f"### Output A from {st.session_state['selected_model']}")
63
+ st.write(st.session_state['answer_a'])
64
+
65
+ with col2:
66
+ st.write(f"### Output B from {st.session_state['selected_model']}")
67
+ st.write(st.session_state['answer_b'])
68
+
69
+ feedback_col = st.columns([1, 1, 1, 1])
70
+
71
+ with feedback_col[0]:
72
+ if st.button("A is better πŸ₯‡"):
73
+ st.write("You selected: A is better")
74
+
75
+ with feedback_col[1]:
76
+ if st.button("B is better πŸ₯ˆ"):
77
+ st.write("You selected: B is better")
78
+
79
+ with feedback_col[2]:
80
+ if st.button("It's a Tie 🀝"):
81
+ st.write("You selected: It's a Tie")
82
+
83
+ with feedback_col[3]:
84
+ if st.button("Both are bad πŸ‘Ž"):
85
+ st.write("You selected: Both are bad")