Spaces:
Sleeping
Sleeping
Update app.py
Browse files70 unmodified lines717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614770 unmodified linesresponse = qa.run(user_input)return response# Function to save user feedbackdef save_feedback(user_input, bot_response, rating, comment):feedback = {"user_input": user_input,"bot_response": bot_response,"rating": rating,"comment": comment}# Check if the feedback file existsfeedback_file = "feedback.csv"if os.path.exists(feedback_file):# Load existing feedback and append new feedbackfeedback_df = pd.read_csv(feedback_file)feedback_df = feedback_df.append(feedback, ignore_index=True)else:# Create a new dataframe for the feedbackfeedback_df = pd.DataFrame([feedback])# Save feedback to CSVfeedback_df.to_csv(feedback_file, index=False)# Create columns for logoscol1, col2, col3 = st.columns([2, 3, 2])with col1:st.image("Design 3_22.png", width=150, use_column_width=True)with col3:st.image("Altereo logo 2023 original - eau et territoires durables.png", width=150, use_column_width=True)# Adding centered header and subtitlest.markdown("""<style>.centered-text { text-align: center; }.centered-orange-text { text-align: center; color: darkorange; }</style>""", unsafe_allow_html=True)st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖 </h3>', unsafe_allow_html=True)st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique "</p>', unsafe_allow_html=True)# Input and button for user interactionuser_input = st.text_input("You:", "")submit_button = st.button("Ask 📨")# Handle user input and display responseif submit_button and user_input.strip():bot_response = chatbot_response(user_input)st.markdown("### Bot:")st.text_area("", value=bot_response, height=300)# Star rating systemst.markdown("### How would you rate the response?")rating = st.slider("Rate from 1 star to 5 stars", min_value=1, max_value=5, value=3)# Comment sectioncomment = st.text_area("Any comments or suggestions for improvement?", "")# Save feedback when the user submits a rating and commentif st.button("Submit Feedback"):save_feedback(user_input, bot_response, rating, comment)st.success("Thank you for your feedback!")# Motivational quote at the bottomst.markdown("---")st.markdown("La collaboration est la clé du succès. Chaque question trouve sa réponse, chaque défi devient une opportunité.")# Section for the developer to review feedbackif st.checkbox("Show Feedback (Developer Only)"):if os.path.exists("feedback.csv"):feedback_df = pd.read_csv("feedback.csv")st.dataframe(feedback_df)else:st.warning("No feedback available yet.")70 unmodified lines717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411570 unmodified linesresponse = qa.run(user_input)return responseimport gspreadfrom oauth2client.service_account import ServiceAccountCredentialsimport json# Load Google service account credentials from Hugging Face secretsGOOGLE_SERVICE_ACCOUNT_JSON = st.secrets["GOOGLE_SERVICE_ACCOUNT_JSON"]# Google Sheets setupscope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]service_account_info = json.loads(GOOGLE_SERVICE_ACCOUNT_JSON)creds = ServiceAccountCredentials.from_json_keyfile_dict(service_account_info, scope)client = gspread.authorize(creds)sheet = client.open("Streamlit Feedback").sheet1 # Replace with your Google Sheet name# Function to save user feedback to Google Sheetsdef save_feedback(user_input, bot_response, rating, comment):feedback = [user_input, bot_response, rating, comment]sheet.append_row(feedback)# Streamlit app layoutst.set_page_config(page_title="Feedback App", page_icon="🤖")st.markdown("<h3 style='text-align: center;'>🤖 Chatbot Feedback 🤖</h3>", unsafe_allow_html=True)user_input = st.text_input("You:")bot_response = "This is a bot response." # Replace this with your chatbot's response logicst.markdown("### Rate the response:")rating = st.selectbox("", [1, 2, 3, 4, 5])st.markdown("### Leave a comment:")comment = st.text_area("")if st.button("Submit"):if user_input.strip() and comment.strip():save_feedback(user_input, bot_response, rating, comment)st.success("Thank you for your feedback!")else:st.warning("Please provide both input and comment.")st.markdown("---")st.markdown("Collaboration is the key to success. Each question finds its answer, each challenge becomes an opportunity.")
app.py+37-69