mery22 commited on
Commit
0d51287
·
verified ·
1 Parent(s): 6161e06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -69
app.py CHANGED
@@ -71,77 +71,45 @@ def chatbot_response(user_input):
71
  response = qa.run(user_input)
72
  return response
73
 
74
- # Function to save user feedback
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  def save_feedback(user_input, bot_response, rating, comment):
76
- feedback = {
77
- "user_input": user_input,
78
- "bot_response": bot_response,
79
- "rating": rating,
80
- "comment": comment
81
- }
82
-
83
- # Check if the feedback file exists
84
- feedback_file = "feedback.csv"
85
- if os.path.exists(feedback_file):
86
- # Load existing feedback and append new feedback
87
- feedback_df = pd.read_csv(feedback_file)
88
- feedback_df = feedback_df.append(feedback, ignore_index=True)
89
- else:
90
- # Create a new dataframe for the feedback
91
- feedback_df = pd.DataFrame([feedback])
92
-
93
- # Save feedback to CSV
94
- feedback_df.to_csv(feedback_file, index=False)
95
-
96
- # Create columns for logos
97
- col1, col2, col3 = st.columns([2, 3, 2])
98
-
99
- with col1:
100
- st.image("Design 3_22.png", width=150, use_column_width=True)
101
-
102
- with col3:
103
- st.image("Altereo logo 2023 original - eau et territoires durables.png", width=150, use_column_width=True)
104
-
105
- # Adding centered header and subtitle
106
- st.markdown("""
107
- <style>
108
- .centered-text { text-align: center; }
109
- .centered-orange-text { text-align: center; color: darkorange; }
110
- </style>
111
- """, unsafe_allow_html=True)
112
- st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖 </h3>', unsafe_allow_html=True)
113
- st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique "</p>', unsafe_allow_html=True)
114
-
115
- # Input and button for user interaction
116
- user_input = st.text_input("You:", "")
117
- submit_button = st.button("Ask 📨")
118
-
119
- # Handle user input and display response
120
- if submit_button and user_input.strip():
121
- bot_response = chatbot_response(user_input)
122
- st.markdown("### Bot:")
123
- st.text_area("", value=bot_response, height=300)
124
-
125
- # Star rating system
126
- st.markdown("### How would you rate the response?")
127
- rating = st.slider("Rate from 1 star to 5 stars", min_value=1, max_value=5, value=3)
128
-
129
- # Comment section
130
- comment = st.text_area("Any comments or suggestions for improvement?", "")
131
-
132
- # Save feedback when the user submits a rating and comment
133
- if st.button("Submit Feedback"):
134
  save_feedback(user_input, bot_response, rating, comment)
135
  st.success("Thank you for your feedback!")
 
 
136
 
137
- # Motivational quote at the bottom
138
  st.markdown("---")
139
- st.markdown("La collaboration est la clé du succès. Chaque question trouve sa réponse, chaque défi devient une opportunité.")
140
-
141
- # Section for the developer to review feedback
142
- if st.checkbox("Show Feedback (Developer Only)"):
143
- if os.path.exists("feedback.csv"):
144
- feedback_df = pd.read_csv("feedback.csv")
145
- st.dataframe(feedback_df)
146
- else:
147
- st.warning("No feedback available yet.")
 
71
  response = qa.run(user_input)
72
  return response
73
 
74
+ import gspread
75
+ from oauth2client.service_account import ServiceAccountCredentials
76
+ import json
77
+
78
+ # Load Google service account credentials from Hugging Face secrets
79
+ GOOGLE_SERVICE_ACCOUNT_JSON = st.secrets["GOOGLE_SERVICE_ACCOUNT_JSON"]
80
+
81
+ # Google Sheets setup
82
+ scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
83
+ service_account_info = json.loads(GOOGLE_SERVICE_ACCOUNT_JSON)
84
+ creds = ServiceAccountCredentials.from_json_keyfile_dict(service_account_info, scope)
85
+ client = gspread.authorize(creds)
86
+ sheet = client.open("Streamlit Feedback").sheet1 # Replace with your Google Sheet name
87
+
88
+ # Function to save user feedback to Google Sheets
89
  def save_feedback(user_input, bot_response, rating, comment):
90
+ feedback = [user_input, bot_response, rating, comment]
91
+ sheet.append_row(feedback)
92
+
93
+ # Streamlit app layout
94
+ st.set_page_config(page_title="Feedback App", page_icon="🤖")
95
+
96
+ st.markdown("<h3 style='text-align: center;'>🤖 Chatbot Feedback 🤖</h3>", unsafe_allow_html=True)
97
+
98
+ user_input = st.text_input("You:")
99
+ bot_response = "This is a bot response." # Replace this with your chatbot's response logic
100
+
101
+ st.markdown("### Rate the response:")
102
+ rating = st.selectbox("", [1, 2, 3, 4, 5])
103
+
104
+ st.markdown("### Leave a comment:")
105
+ comment = st.text_area("")
106
+
107
+ if st.button("Submit"):
108
+ if user_input.strip() and comment.strip():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  save_feedback(user_input, bot_response, rating, comment)
110
  st.success("Thank you for your feedback!")
111
+ else:
112
+ st.warning("Please provide both input and comment.")
113
 
 
114
  st.markdown("---")
115
+ st.markdown("Collaboration is the key to success. Each question finds its answer, each challenge becomes an opportunity.")