Utsav2001 commited on
Commit
31902be
·
verified ·
1 Parent(s): 9e7b3d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -53
app.py CHANGED
@@ -1,48 +1,4 @@
1
  import streamlit as st
2
- import json
3
- import os
4
-
5
- # Initialize results file
6
- filename = "results.json"
7
-
8
- if not os.path.exists(filename):
9
- with open(filename, "w") as file:
10
- json.dump([], file)
11
-
12
- # Function to load existing data
13
- def load_existing_data():
14
- with open(filename, "r") as file:
15
- try:
16
- return json.load(file)
17
- except json.JSONDecodeError:
18
- return []
19
-
20
- # Function to save feedback
21
- def save_feedback(prompt, response, feedback_comment, feedback_value):
22
- existing_data = load_existing_data()
23
-
24
- # Check for existing feedback for the same prompt-response pair
25
- found = False
26
- for data in existing_data:
27
- if data.get("prompt") == prompt and data.get("response") == response:
28
- data["feedback"] = feedback_comment
29
- data["positiveORnegative"] = "Positive" if feedback_value == 1 else "Negative"
30
- found = True
31
- break
32
-
33
- if not found:
34
- # Add new feedback entry
35
- new_entry = {
36
- "prompt": prompt,
37
- "response": response,
38
- "feedback": feedback_comment,
39
- "positiveORnegative": "Positive" if feedback_value == 1 else "Negative"
40
- }
41
- existing_data.append(new_entry)
42
-
43
- # Save updated data
44
- with open(filename, "w") as file:
45
- json.dump(existing_data, file, indent=4)
46
 
47
  # Streamlit UI
48
  st.title("Feedback-enabled Chatbot")
@@ -71,22 +27,16 @@ if st.session_state.show_feedback and len(st.session_state.prompts) > 0 and len(
71
  col1, col2 = st.columns(2)
72
  with col1:
73
  if st.button("👍 Thumbs Up"):
74
- st.session_state.feedback_value = 1
75
  st.session_state.show_feedback_box = True
76
  with col2:
77
  if st.button("👎 Thumbs Down"):
78
- st.session_state.feedback_value = 0
79
  st.session_state.show_feedback_box = True
80
 
81
  if "show_feedback_box" in st.session_state and st.session_state.show_feedback_box:
82
  feedback_comment = st.text_area("Your Feedback:")
83
  if st.button("Submit Feedback"):
84
- save_feedback(
85
- st.session_state.prompts[-1],
86
- st.session_state.responses[-1],
87
- feedback_comment,
88
- st.session_state.feedback_value,
89
- )
90
- st.success("Feedback saved successfully!")
91
  st.session_state.show_feedback_box = False
92
  st.session_state.show_feedback = False
 
1
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  # Streamlit UI
4
  st.title("Feedback-enabled Chatbot")
 
27
  col1, col2 = st.columns(2)
28
  with col1:
29
  if st.button("👍 Thumbs Up"):
30
+ st.session_state.feedback_value = "Positive"
31
  st.session_state.show_feedback_box = True
32
  with col2:
33
  if st.button("👎 Thumbs Down"):
34
+ st.session_state.feedback_value = "Negative"
35
  st.session_state.show_feedback_box = True
36
 
37
  if "show_feedback_box" in st.session_state and st.session_state.show_feedback_box:
38
  feedback_comment = st.text_area("Your Feedback:")
39
  if st.button("Submit Feedback"):
40
+ st.success("Feedback submitted successfully!")
 
 
 
 
 
 
41
  st.session_state.show_feedback_box = False
42
  st.session_state.show_feedback = False