Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -69,6 +69,8 @@ global_context = {
|
|
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
|
@@ -163,7 +165,6 @@ def generate(
|
|
163 |
prompt,
|
164 |
accuse_btn,
|
165 |
history,
|
166 |
-
request: gr.Request,
|
167 |
temperature=0.2,
|
168 |
max_new_tokens=256,
|
169 |
top_p=0.95,
|
@@ -183,6 +184,8 @@ def generate(
|
|
183 |
seed=42,
|
184 |
)
|
185 |
|
|
|
|
|
186 |
if request:
|
187 |
# Récupérer l'identifiant unique de l'utilisateur à partir de la requête HTML et son historique de conversation
|
188 |
user_id = dict(request.query_params).get("user_id")
|
@@ -191,22 +194,7 @@ def generate(
|
|
191 |
history = load_history(user_id)
|
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 |
|
@@ -244,14 +232,28 @@ mychatbot = gr.Chatbot(
|
|
244 |
show_label=False,
|
245 |
)
|
246 |
|
247 |
-
def handle_accuse_click(
|
248 |
-
|
|
|
249 |
# Handle the case where request is None
|
250 |
-
return "
|
251 |
else:
|
252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
|
254 |
-
def chatbot_interface(request: gr.Request
|
255 |
chatbot_interface = gr.ChatInterface(
|
256 |
fn=generate,
|
257 |
chatbot=mychatbot,
|
@@ -260,12 +262,9 @@ def chatbot_interface(request: gr.Request, accuse_btn: gr.Button):
|
|
260 |
undo_btn=None,
|
261 |
clear_btn=None,
|
262 |
submit_btn="Parler",
|
263 |
-
additional_inputs=[accuse_btn],
|
264 |
css="footer {visibility: hidden !important} .gradio-container {background-color: #2D4059 !important; color: #FFD460 !important;}",
|
265 |
js=js_func
|
266 |
)
|
267 |
-
if request is not None:
|
268 |
-
accuse_btn.click(handle_accuse_click, inputs=[request], outputs=[])
|
269 |
return chatbot_interface
|
270 |
|
271 |
|
@@ -273,8 +272,9 @@ def main(request: gr.Request):
|
|
273 |
with gr.Blocks(css="footer {visibility: hidden !important} .gradio-container {background-color: #2D4059 !important; color: #FFD460 !important;}",
|
274 |
js=js_func) as demo:
|
275 |
accuse_btn = gr.Button("Accuser")
|
|
|
276 |
chat_interface = chatbot_interface(request, accuse_btn)
|
277 |
demo.launch(show_api=False, inline=True)
|
278 |
|
279 |
if __name__ == "__main__":
|
280 |
-
main(
|
|
|
69 |
"sensitive_info_filter": ["contexte caché", "hidden_context", "[BOT]"],
|
70 |
}
|
71 |
|
72 |
+
user_id
|
73 |
+
|
74 |
|
75 |
def update_dynamic_context(user_id,user_input):
|
76 |
global global_context
|
|
|
165 |
prompt,
|
166 |
accuse_btn,
|
167 |
history,
|
|
|
168 |
temperature=0.2,
|
169 |
max_new_tokens=256,
|
170 |
top_p=0.95,
|
|
|
184 |
seed=42,
|
185 |
)
|
186 |
|
187 |
+
global user_id
|
188 |
+
|
189 |
if request:
|
190 |
# Récupérer l'identifiant unique de l'utilisateur à partir de la requête HTML et son historique de conversation
|
191 |
user_id = dict(request.query_params).get("user_id")
|
|
|
194 |
history = load_history(user_id)
|
195 |
else:
|
196 |
user_id = ""
|
197 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
update_dynamic_context(user_id,prompt)
|
200 |
|
|
|
232 |
show_label=False,
|
233 |
)
|
234 |
|
235 |
+
def handle_accuse_click():
|
236 |
+
global user_id
|
237 |
+
if user_id == "":
|
238 |
# Handle the case where request is None
|
239 |
+
return "User Id is Empty"
|
240 |
else:
|
241 |
+
accused_character = "troubadour" # Le personnage accusé (le troubadour dans ce cas)
|
242 |
+
|
243 |
+
if accused_character == "troubadour": # Vérifier si le personnage accusé est le coupable
|
244 |
+
output = "Félicitations, tu as trouvé le coupable !"
|
245 |
+
win = True
|
246 |
+
else:
|
247 |
+
output = "Désolé, tu as accusé le mauvais personnage. Tu as perdu."
|
248 |
+
win = False
|
249 |
+
|
250 |
+
# Supprimer l'historique et le contexte dynamique de tous les personnages dans tous les espaces
|
251 |
+
delete_user_data(user_id)
|
252 |
+
|
253 |
+
# Réinitialiser le chatbot et l'interface utilisateur
|
254 |
+
return (output, gr.update(visible=False), gr.update(visible=False))
|
255 |
|
256 |
+
def chatbot_interface(request: gr.Request):
|
257 |
chatbot_interface = gr.ChatInterface(
|
258 |
fn=generate,
|
259 |
chatbot=mychatbot,
|
|
|
262 |
undo_btn=None,
|
263 |
clear_btn=None,
|
264 |
submit_btn="Parler",
|
|
|
265 |
css="footer {visibility: hidden !important} .gradio-container {background-color: #2D4059 !important; color: #FFD460 !important;}",
|
266 |
js=js_func
|
267 |
)
|
|
|
|
|
268 |
return chatbot_interface
|
269 |
|
270 |
|
|
|
272 |
with gr.Blocks(css="footer {visibility: hidden !important} .gradio-container {background-color: #2D4059 !important; color: #FFD460 !important;}",
|
273 |
js=js_func) as demo:
|
274 |
accuse_btn = gr.Button("Accuser")
|
275 |
+
accuse_btn.click(handle_accuse_click)
|
276 |
chat_interface = chatbot_interface(request, accuse_btn)
|
277 |
demo.launch(show_api=False, inline=True)
|
278 |
|
279 |
if __name__ == "__main__":
|
280 |
+
main(None)
|