Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,12 +12,12 @@ import json
|
|
12 |
# Load Google service account credentials from Hugging Face secrets
|
13 |
GOOGLE_SERVICE_ACCOUNT_JSON = st.secrets["GOOGLE_SERVICE_ACCOUNT_JSON"]
|
14 |
|
15 |
-
# Google Sheets setup
|
16 |
scope = ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive"]
|
17 |
service_account_info = json.loads(GOOGLE_SERVICE_ACCOUNT_JSON)
|
18 |
creds = ServiceAccountCredentials.from_json_keyfile_dict(service_account_info, scope)
|
19 |
client = gspread.authorize(creds)
|
20 |
-
spreadsheet_id = '
|
21 |
sheet = client.open_by_key(spreadsheet_id).sheet1
|
22 |
|
23 |
# Function to save user feedback to Google Sheets
|
@@ -61,7 +61,7 @@ prompt = PromptTemplate(
|
|
61 |
template=prompt_template,
|
62 |
)
|
63 |
|
64 |
-
# Create
|
65 |
llm_chain = LLMChain(llm=mistral_llm, prompt=prompt)
|
66 |
|
67 |
# Create RetrievalQA chain
|
@@ -95,6 +95,13 @@ st.markdown("""
|
|
95 |
.centered-text {
|
96 |
text-align: center;
|
97 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
.centered-orange-text {
|
99 |
text-align: center;
|
100 |
color: darkorange;
|
@@ -102,32 +109,52 @@ st.markdown("""
|
|
102 |
</style>
|
103 |
""", unsafe_allow_html=True)
|
104 |
|
105 |
-
|
106 |
-
st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique"</p>', unsafe_allow_html=True)
|
107 |
|
108 |
# Input and button for user interaction
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Load Google service account credentials from Hugging Face secrets
|
13 |
GOOGLE_SERVICE_ACCOUNT_JSON = st.secrets["GOOGLE_SERVICE_ACCOUNT_JSON"]
|
14 |
|
15 |
+
# Google Sheets API v4 setup
|
16 |
scope = ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive"]
|
17 |
service_account_info = json.loads(GOOGLE_SERVICE_ACCOUNT_JSON)
|
18 |
creds = ServiceAccountCredentials.from_json_keyfile_dict(service_account_info, scope)
|
19 |
client = gspread.authorize(creds)
|
20 |
+
spreadsheet_id = '1A2B3C4D5E6F7G8H9I0J' # Replace with your actual spreadsheet ID
|
21 |
sheet = client.open_by_key(spreadsheet_id).sheet1
|
22 |
|
23 |
# Function to save user feedback to Google Sheets
|
|
|
61 |
template=prompt_template,
|
62 |
)
|
63 |
|
64 |
+
# Create llm chain
|
65 |
llm_chain = LLMChain(llm=mistral_llm, prompt=prompt)
|
66 |
|
67 |
# Create RetrievalQA chain
|
|
|
95 |
.centered-text {
|
96 |
text-align: center;
|
97 |
}
|
98 |
+
</style>
|
99 |
+
""", unsafe_allow_html=True)
|
100 |
+
|
101 |
+
# Utiliser la classe CSS pour centrer et colorer le texte
|
102 |
+
st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖 </h3>', unsafe_allow_html=True)
|
103 |
+
st.markdown("""
|
104 |
+
<style>
|
105 |
.centered-orange-text {
|
106 |
text-align: center;
|
107 |
color: darkorange;
|
|
|
109 |
</style>
|
110 |
""", unsafe_allow_html=True)
|
111 |
|
112 |
+
# Centrer et colorer en orange foncé le texte spécifique
|
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 |
+
import streamlit as st
|
120 |
+
import gspread
|
121 |
+
from oauth2client.service_account import ServiceAccountCredentials
|
122 |
+
import json
|
123 |
+
|
124 |
+
# Load Google service account credentials from Hugging Face secrets
|
125 |
+
GOOGLE_SERVICE_ACCOUNT_JSON = st.secrets["GOOGLE_SERVICE_ACCOUNT_JSON"]
|
126 |
+
|
127 |
+
# Google Sheets API v4 setup
|
128 |
+
scope = ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive"]
|
129 |
+
service_account_info = json.loads(GOOGLE_SERVICE_ACCOUNT_JSON)
|
130 |
+
creds = ServiceAccountCredentials.from_json_keyfile_dict(service_account_info, scope)
|
131 |
+
client = gspread.authorize(creds)
|
132 |
+
sheet = client.open("users feedback").sheet1 # Replace with your Google Sheet name
|
133 |
+
|
134 |
+
# Function to save user feedback to Google Sheets
|
135 |
+
def save_feedback(user_input, bot_response, rating, comment):
|
136 |
+
feedback = [user_input, bot_response, rating, comment]
|
137 |
+
sheet.append_row(feedback)
|
138 |
+
|
139 |
+
# Streamlit app layout
|
140 |
+
|
141 |
+
|
142 |
+
user_input = st.text_input("You:")
|
143 |
+
bot_response = "This is a bot response." # Replace this with your chatbot's response logic
|
144 |
+
|
145 |
+
st.markdown("### Rate the response:")
|
146 |
+
rating = st.selectbox("", [1, 2, 3, 4, 5])
|
147 |
+
|
148 |
+
st.markdown("### Leave a comment:")
|
149 |
+
comment = st.text_area("")
|
150 |
+
|
151 |
+
if st.button("Submit"):
|
152 |
+
if user_input.strip() and comment.strip():
|
153 |
+
save_feedback(user_input, bot_response, rating, comment)
|
154 |
+
st.success("Thank you for your feedback!")
|
155 |
+
else:
|
156 |
+
st.warning("Please provide both input and comment.")
|
157 |
+
|
158 |
+
st.markdown("---")
|
159 |
+
st.markdown("Collaboration is the key to success. Each question finds its answer, each challenge becomes an opportunity.")
|
160 |
+
|