Ashar086 commited on
Commit
59fa620
1 Parent(s): ebafa87

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +112 -0
app.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+ import pandas as pd
4
+ from datetime import datetime
5
+
6
+ # Load or initialize CSVs for logging interactions and survey responses
7
+ try:
8
+ interactions_df = pd.read_csv("interactions.csv")
9
+ except FileNotFoundError:
10
+ interactions_df = pd.DataFrame(columns=["timestamp", "participant_id", "chatbot_type", "interaction", "response"])
11
+
12
+ try:
13
+ survey_df = pd.read_csv("survey_responses.csv")
14
+ except FileNotFoundError:
15
+ survey_df = pd.DataFrame(columns=["timestamp", "participant_id", "chatbot_type", "emotional_response", "feedback"])
16
+
17
+ # Initialize session state for participant assignment and interactions
18
+ if "participant_id" not in st.session_state:
19
+ st.session_state.participant_id = str(random.randint(1000, 9999))
20
+
21
+ if "chatbot_type" not in st.session_state:
22
+ st.session_state.chatbot_type = random.choice(["Positive", "Critical"])
23
+
24
+ if "idea_count" not in st.session_state:
25
+ st.session_state.idea_count = 0
26
+
27
+ # Display Welcome Message
28
+ st.title("Welcome to the Chatbot Study")
29
+ st.write("""
30
+ Thank you for participating in our study. You will interact with a chatbot
31
+ and brainstorm ideas for a marketing campaign. Please press "Start" below to begin.
32
+ """)
33
+
34
+ if st.button("Start Study") or "start" in st.session_state:
35
+ st.session_state.start = True
36
+
37
+ # Chatbot Interaction Section
38
+ if "start" in st.session_state:
39
+ st.subheader("Chatbot Interaction")
40
+
41
+ # Display participant information and assigned chatbot type
42
+ st.write(f"Participant ID: {st.session_state.participant_id}")
43
+ st.write(f"Assigned Chatbot Type: {st.session_state.chatbot_type}")
44
+
45
+ # Pre-programmed responses for each chatbot type
46
+ if st.session_state.chatbot_type == "Positive":
47
+ responses = [
48
+ "Great idea! I love where you’re going with this.",
49
+ "Awesome suggestion! Here’s another thought: what if we add a new twist?",
50
+ "You're on fire! That’s a really promising direction.",
51
+ "Keep up the creativity! This is really going somewhere.",
52
+ ]
53
+ else:
54
+ responses = [
55
+ "I don’t think that will work very well. Maybe try something different?",
56
+ "Are you sure about that idea? It seems a bit weak.",
57
+ "This doesn’t sound very innovative. Try another angle.",
58
+ "Not quite there yet. What else do you have in mind?",
59
+ ]
60
+
61
+ # User input for submitting an idea
62
+ user_input = st.text_input("Enter your idea here:")
63
+
64
+ if st.button("Submit Idea"):
65
+ if st.session_state.idea_count < 10:
66
+ response = random.choice(responses)
67
+ st.write(f"Chatbot: {response}")
68
+
69
+ # Record the interaction
70
+ interaction_data = {
71
+ "timestamp": datetime.now(),
72
+ "participant_id": st.session_state.participant_id,
73
+ "chatbot_type": st.session_state.chatbot_type,
74
+ "interaction": user_input,
75
+ "response": response
76
+ }
77
+ interactions_df = interactions_df.append(interaction_data, ignore_index=True)
78
+ interactions_df.to_csv("interactions.csv", index=False)
79
+
80
+ # Increment idea count
81
+ st.session_state.idea_count += 1
82
+ st.write(f"Ideas Submitted: {st.session_state.idea_count}/10")
83
+ else:
84
+ st.warning("You have reached the maximum of 10 ideas.")
85
+
86
+ # Option to end interaction and proceed to the survey
87
+ if st.button("Proceed to Survey"):
88
+ st.session_state.end_interaction = True
89
+
90
+ # Survey Page
91
+ if "end_interaction" in st.session_state:
92
+ st.subheader("Post-Interaction Survey")
93
+
94
+ emotional_response = st.radio(
95
+ "How did interacting with the chatbot make you feel?",
96
+ ("Very Positive", "Positive", "Neutral", "Negative", "Very Negative")
97
+ )
98
+ feedback = st.text_area("Any feedback on the chatbot interaction?")
99
+
100
+ if st.button("Submit Survey"):
101
+ # Record survey data
102
+ survey_data = {
103
+ "timestamp": datetime.now(),
104
+ "participant_id": st.session_state.participant_id,
105
+ "chatbot_type": st.session_state.chatbot_type,
106
+ "emotional_response": emotional_response,
107
+ "feedback": feedback
108
+ }
109
+ survey_df = survey_df.append(survey_data, ignore_index=True)
110
+ survey_df.to_csv("survey_responses.csv", index=False)
111
+
112
+ st.write("Thank you for completing the study! Your responses have been recorded.")