Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
import re
|
4 |
-
import random
|
5 |
-
import string
|
6 |
import firebase_admin
|
7 |
from firebase_admin import credentials, firestore
|
8 |
from datetime import datetime
|
@@ -71,11 +69,6 @@ global_context = {
|
|
71 |
"sensitive_info_filter": ["contexte caché", "hidden_context", "[BOT]"],
|
72 |
}
|
73 |
|
74 |
-
# Créer une interface avec un champ de texte pour le contexte caché
|
75 |
-
context_input = gr.Textbox(
|
76 |
-
label="Contexte caché", value=global_context["static_context"]
|
77 |
-
)
|
78 |
-
|
79 |
|
80 |
def update_dynamic_context(user_id,user_input):
|
81 |
global global_context
|
@@ -151,15 +144,24 @@ def format_prompt(message, history, user_id=""):
|
|
151 |
|
152 |
return prompt
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
-
def
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
|
160 |
|
161 |
def generate(
|
162 |
prompt,
|
|
|
163 |
history,
|
164 |
request: gr.Request,
|
165 |
temperature=0.2,
|
@@ -190,6 +192,22 @@ def generate(
|
|
190 |
else:
|
191 |
user_id = ""
|
192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
update_dynamic_context(user_id,prompt)
|
194 |
|
195 |
formatted_prompt = format_prompt(prompt, history, user_id)
|
@@ -234,10 +252,23 @@ def chatbot_interface(request: gr.Request):
|
|
234 |
title=chat_name,
|
235 |
retry_btn=None,
|
236 |
undo_btn=None,
|
|
|
237 |
submit_btn="Parler",
|
|
|
238 |
css="footer {visibility: hidden !important} .gradio-container {background-color: #2D4059 !important; color: #FFD460 !important;}",
|
239 |
js=js_func
|
240 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
return chatbot_interface
|
242 |
|
243 |
|
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
import re
|
|
|
|
|
4 |
import firebase_admin
|
5 |
from firebase_admin import credentials, firestore
|
6 |
from datetime import datetime
|
|
|
69 |
"sensitive_info_filter": ["contexte caché", "hidden_context", "[BOT]"],
|
70 |
}
|
71 |
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
def update_dynamic_context(user_id,user_input):
|
74 |
global global_context
|
|
|
144 |
|
145 |
return prompt
|
146 |
|
147 |
+
# Liste des noms des collections Firestore pour chaque espace
|
148 |
+
collections = [
|
149 |
+
"conversations-tavernier",
|
150 |
+
"conversations-guerisseuse",
|
151 |
+
"conversations-troubadour",
|
152 |
+
"conversations-forgeron",
|
153 |
+
"conversations-pretre"
|
154 |
+
]
|
155 |
|
156 |
+
def delete_user_data(user_id):
|
157 |
+
for collection in collections:
|
158 |
+
doc_ref = db.collection(collection).document(user_id)
|
159 |
+
doc_ref.delete()
|
160 |
|
161 |
|
162 |
def generate(
|
163 |
prompt,
|
164 |
+
accuse_btn,
|
165 |
history,
|
166 |
request: gr.Request,
|
167 |
temperature=0.2,
|
|
|
192 |
else:
|
193 |
user_id = ""
|
194 |
|
195 |
+
if accuse_btn: # Vérifier si le bouton "Accuser" a été cliqué
|
196 |
+
accused_character = "troubadour" # Le personnage accusé (le troubadour dans ce cas)
|
197 |
+
|
198 |
+
if accused_character == "troubadour": # Vérifier si le personnage accusé est le coupable
|
199 |
+
output = "Félicitations, tu as trouvé le coupable !"
|
200 |
+
win = True
|
201 |
+
else:
|
202 |
+
output = "Désolé, tu as accusé le mauvais personnage. Tu as perdu."
|
203 |
+
win = False
|
204 |
+
|
205 |
+
# Supprimer l'historique et le contexte dynamique de tous les personnages dans tous les espaces
|
206 |
+
delete_user_data(user_id)
|
207 |
+
|
208 |
+
# Réinitialiser le chatbot et l'interface utilisateur
|
209 |
+
return (output, gr.update(visible=False), gr.update(visible=False))
|
210 |
+
|
211 |
update_dynamic_context(user_id,prompt)
|
212 |
|
213 |
formatted_prompt = format_prompt(prompt, history, user_id)
|
|
|
252 |
title=chat_name,
|
253 |
retry_btn=None,
|
254 |
undo_btn=None,
|
255 |
+
clear_btn=None,
|
256 |
submit_btn="Parler",
|
257 |
+
inputs=[gr.Textbox(label="Message"), gr.Button("Accuser")],
|
258 |
css="footer {visibility: hidden !important} .gradio-container {background-color: #2D4059 !important; color: #FFD460 !important;}",
|
259 |
js=js_func
|
260 |
)
|
261 |
+
|
262 |
+
def handle_output(output, chatbot, textbox, accuse_btn):
|
263 |
+
if isinstance(output, tuple):
|
264 |
+
output, chatbot_visible, accuse_btn_visible = output
|
265 |
+
chatbot.visible = chatbot_visible
|
266 |
+
accuse_btn.visible = accuse_btn_visible
|
267 |
+
|
268 |
+
return output, chatbot, textbox, accuse_btn
|
269 |
+
|
270 |
+
chatbot_interface.process(fn=handle_output, inputs=[chatbot_interface, chatbot_interface.inputs[0], chatbot_interface.inputs[1]])
|
271 |
+
|
272 |
return chatbot_interface
|
273 |
|
274 |
|