Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,21 @@ from langchain_huggingface import HuggingFaceEndpoint
|
|
8 |
from langchain.prompts import PromptTemplate
|
9 |
from langchain.schema.runnable import RunnablePassthrough
|
10 |
from langchain.chains import LLMChain
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
from huggingface_hub import login
|
13 |
login(token=st.secrets["HF_TOKEN"])
|
@@ -80,6 +95,11 @@ def chatbot_response(user_input):
|
|
80 |
response = qa.run(user_input)
|
81 |
return response
|
82 |
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
# Create columns for logos
|
85 |
col1, col2, col3 = st.columns([2, 3, 2])
|
@@ -89,21 +109,13 @@ with col1:
|
|
89 |
|
90 |
with col3:
|
91 |
st.image("Altereo logo 2023 original - eau et territoires durables.png", width=150, use_column_width=True) # Adjust image path and size as needed
|
|
|
92 |
# Streamlit components
|
93 |
-
# Ajouter un peu de CSS pour centrer le texte
|
94 |
-
# Ajouter un peu de CSS pour centrer le texte et le colorer en orange foncé
|
95 |
st.markdown("""
|
96 |
<style>
|
97 |
.centered-text {
|
98 |
text-align: center;
|
99 |
}
|
100 |
-
</style>
|
101 |
-
""", unsafe_allow_html=True)
|
102 |
-
|
103 |
-
# Utiliser la classe CSS pour centrer et colorer le texte
|
104 |
-
st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖 </h3>', unsafe_allow_html=True)
|
105 |
-
st.markdown("""
|
106 |
-
<style>
|
107 |
.centered-orange-text {
|
108 |
text-align: center;
|
109 |
color: darkorange;
|
@@ -111,23 +123,43 @@ st.markdown("""
|
|
111 |
</style>
|
112 |
""", unsafe_allow_html=True)
|
113 |
|
114 |
-
#
|
115 |
-
|
116 |
st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique "</p>', unsafe_allow_html=True)
|
117 |
-
# Input and button for user interaction
|
118 |
-
user_input = st.text_input("You:", "")
|
119 |
-
submit_button = st.button("Ask 📨")
|
120 |
-
|
121 |
-
# Handle user input
|
122 |
-
if submit_button:
|
123 |
-
if user_input.strip() != "":
|
124 |
-
bot_response = chatbot_response(user_input)
|
125 |
-
st.markdown("### Bot:")
|
126 |
-
st.text_area("", value=bot_response, height=600)
|
127 |
-
else:
|
128 |
-
st.warning("⚠️ Please enter a message.")
|
129 |
-
|
130 |
-
# Motivational quote at the bottom
|
131 |
-
st.markdown("---")
|
132 |
-
st.markdown("La collaboration est la clé du succès. Chaque question trouve sa réponse, chaque défi devient une opportunité.")
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
from langchain.prompts import PromptTemplate
|
9 |
from langchain.schema.runnable import RunnablePassthrough
|
10 |
from langchain.chains import LLMChain
|
11 |
+
# Load Google service account credentials from Hugging Face secrets
|
12 |
+
GOOGLE_SERVICE_ACCOUNT_JSON = st.secrets["GOOGLE_SERVICE_ACCOUNT_JSON"]
|
13 |
+
|
14 |
+
# Google Sheets API v4 setup
|
15 |
+
scope = ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive"]
|
16 |
+
service_account_info = json.loads(GOOGLE_SERVICE_ACCOUNT_JSON)
|
17 |
+
creds = ServiceAccountCredentials.from_json_keyfile_dict(service_account_info, scope)
|
18 |
+
client = gspread.authorize(creds)
|
19 |
+
spreadsheet_id = '1Jf1k7Q71ihsxBf-XQYyucamMy14q7IjhUDlU8ZzR_Nc' # Replace with your actual spreadsheet ID
|
20 |
+
sheet = client.open_by_key(spreadsheet_id).sheet1
|
21 |
+
|
22 |
+
# Function to save user feedback to Google Sheets
|
23 |
+
def save_feedback(user_input, bot_response, rating, comment):
|
24 |
+
feedback = [user_input, bot_response, rating, comment]
|
25 |
+
sheet.append_row(feedback)
|
26 |
|
27 |
from huggingface_hub import login
|
28 |
login(token=st.secrets["HF_TOKEN"])
|
|
|
95 |
response = qa.run(user_input)
|
96 |
return response
|
97 |
|
98 |
+
# Session state to hold user input and chatbot response
|
99 |
+
if 'user_input' not in st.session_state:
|
100 |
+
st.session_state.user_input = ""
|
101 |
+
if 'bot_response' not in st.session_state:
|
102 |
+
st.session_state.bot_response = ""
|
103 |
|
104 |
# Create columns for logos
|
105 |
col1, col2, col3 = st.columns([2, 3, 2])
|
|
|
109 |
|
110 |
with col3:
|
111 |
st.image("Altereo logo 2023 original - eau et territoires durables.png", width=150, use_column_width=True) # Adjust image path and size as needed
|
112 |
+
|
113 |
# Streamlit components
|
|
|
|
|
114 |
st.markdown("""
|
115 |
<style>
|
116 |
.centered-text {
|
117 |
text-align: center;
|
118 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
.centered-orange-text {
|
120 |
text-align: center;
|
121 |
color: darkorange;
|
|
|
123 |
</style>
|
124 |
""", unsafe_allow_html=True)
|
125 |
|
126 |
+
# Use CSS classes to style the text
|
127 |
+
st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖 </h3>', unsafe_allow_html=True)
|
128 |
st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique "</p>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
+
# Input form for user interaction
|
131 |
+
with st.form(key='interaction_form'):
|
132 |
+
st.session_state.user_input = st.text_input("You:", key="user_input_input")
|
133 |
+
ask_button = st.form_submit_button("Ask 📨") # Button to submit the question
|
134 |
+
|
135 |
+
if ask_button and st.session_state.user_input.strip():
|
136 |
+
st.session_state.bot_response = chatbot_response(st.session_state.user_input)
|
137 |
+
|
138 |
+
# Display the bot response if available
|
139 |
+
if st.session_state.bot_response:
|
140 |
+
st.markdown("### Bot:")
|
141 |
+
st.text_area("", value=st.session_state.bot_response, height=600)
|
142 |
+
|
143 |
+
# Separate form for feedback submission
|
144 |
+
with st.form(key='feedback_form'):
|
145 |
+
st.markdown("### Rate the response:")
|
146 |
+
rating = st.slider("Select a rating:", min_value=1, max_value=5, value=1, key="rating")
|
147 |
+
|
148 |
+
st.markdown("### Leave a comment:")
|
149 |
+
comment = st.text_area("", key="comment")
|
150 |
+
|
151 |
+
# Separate submit button for feedback
|
152 |
+
feedback_submit_button = st.form_submit_button("Submit Feedback")
|
153 |
+
|
154 |
+
if feedback_submit_button:
|
155 |
+
if comment.strip():
|
156 |
+
save_feedback(st.session_state.user_input, st.session_state.bot_response, rating, comment)
|
157 |
+
st.success("Thank you for your feedback!")
|
158 |
+
# Clear the session state after submission
|
159 |
+
st.session_state.user_input = ""
|
160 |
+
st.session_state.bot_response = ""
|
161 |
+
else:
|
162 |
+
st.warning("Please provide a comment before submitting feedback.")
|
163 |
+
|
164 |
+
st.markdown("---")
|
165 |
+
st.markdown("Collaboration is the key to success. Each question finds its answer, each challenge becomes an opportunity.")
|