Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,77 +71,45 @@ def chatbot_response(user_input):
|
|
| 71 |
response = qa.run(user_input)
|
| 72 |
return response
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
def save_feedback(user_input, bot_response, rating, comment):
|
| 76 |
-
feedback =
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 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("
|
| 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.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|