Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,22 +23,7 @@ def on_submit(user_msg: str, chat_history: list[tuple[str, str]]):
|
|
| 23 |
assistant_reply = "Ceci est une réponse de démonstration.\n\nConfirmez-vous l’action ?"
|
| 24 |
chat_history = chat_history + [(user_msg, assistant_reply)]
|
| 25 |
|
| 26 |
-
|
| 27 |
-
open_popup_js = """
|
| 28 |
-
(function openWhenReady(){
|
| 29 |
-
var start = Date.now();
|
| 30 |
-
(function tick(){
|
| 31 |
-
var modal = document.getElementById('confirm-modal');
|
| 32 |
-
if (modal) {
|
| 33 |
-
modal.style.display = 'flex';
|
| 34 |
-
document.body.style.overflow = 'hidden';
|
| 35 |
-
return;
|
| 36 |
-
}
|
| 37 |
-
if (Date.now() - start < 5000) { setTimeout(tick, 60); }
|
| 38 |
-
})();
|
| 39 |
-
})();
|
| 40 |
-
"""
|
| 41 |
-
return chat_history, "", {"js": open_popup_js} # clear textbox
|
| 42 |
|
| 43 |
# 3) Injection au chargement : HTML/CSS + helper setGradioValue (pas de showModal requis)
|
| 44 |
def inject_assets():
|
|
@@ -111,8 +96,23 @@ with gr.Blocks(title="Démo Chat + Popup", fill_height=True) as demo:
|
|
| 111 |
bridge_choice = gr.Textbox(visible=True, elem_id="bridge-choice")
|
| 112 |
|
| 113 |
# A) Soumission -> affiche (user, question) + demande au client d'ouvrir la popup
|
| 114 |
-
user_in.submit(fn=on_submit,
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
# B) Clic Oui/Non -> ajoute (Oui/Non, confirmation)
|
| 118 |
bridge_choice.change(fn=handle_choice, inputs=[bridge_choice, chat],
|
|
|
|
| 23 |
assistant_reply = "Ceci est une réponse de démonstration.\n\nConfirmez-vous l’action ?"
|
| 24 |
chat_history = chat_history + [(user_msg, assistant_reply)]
|
| 25 |
|
| 26 |
+
return chat_history, ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# 3) Injection au chargement : HTML/CSS + helper setGradioValue (pas de showModal requis)
|
| 29 |
def inject_assets():
|
|
|
|
| 96 |
bridge_choice = gr.Textbox(visible=True, elem_id="bridge-choice")
|
| 97 |
|
| 98 |
# A) Soumission -> affiche (user, question) + demande au client d'ouvrir la popup
|
| 99 |
+
user_in.submit(fn=on_submit,
|
| 100 |
+
inputs=[user_in, chat],
|
| 101 |
+
outputs=[chat, user_in],
|
| 102 |
+
js="""
|
| 103 |
+
() => {
|
| 104 |
+
const start = Date.now();
|
| 105 |
+
(function tick(){
|
| 106 |
+
const modal = document.getElementById('confirm-modal');
|
| 107 |
+
if (modal) {
|
| 108 |
+
modal.style.display = 'flex';
|
| 109 |
+
document.body.style.overflow = 'hidden';
|
| 110 |
+
return;
|
| 111 |
+
}
|
| 112 |
+
if (Date.now() - start < 3000) setTimeout(tick, 60);
|
| 113 |
+
})();
|
| 114 |
+
}
|
| 115 |
+
""")
|
| 116 |
|
| 117 |
# B) Clic Oui/Non -> ajoute (Oui/Non, confirmation)
|
| 118 |
bridge_choice.change(fn=handle_choice, inputs=[bridge_choice, chat],
|