Chad commited on
Commit ·
0207153
1
Parent(s): d8dc558
lanewhfhweifqwiurn3rtun3q4tg togglwdwdwdeeefefefdwdwdwdwddwdwdwd
Browse files
app.py
CHANGED
|
@@ -43,6 +43,7 @@ def generate_reply(user_input, chat_history):
|
|
| 43 |
chat_history.append({"role": "user", "content": user_input})
|
| 44 |
chat_history.append({"role": "assistant", "content": reply})
|
| 45 |
return chat_history, chat_history, ""
|
|
|
|
| 46 |
def toggle_language(language):
|
| 47 |
"""Toggle UI elements between English and French."""
|
| 48 |
if language == "english":
|
|
@@ -52,8 +53,14 @@ def toggle_language(language):
|
|
| 52 |
"EN", # New language button label
|
| 53 |
"Entrez votre question ici...", # New placeholder text
|
| 54 |
"Envoyer", # New send button label
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
else:
|
| 59 |
return (
|
|
@@ -62,12 +69,26 @@ def toggle_language(language):
|
|
| 62 |
"FR",
|
| 63 |
"Enter your question here...",
|
| 64 |
"Send",
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
with gr.Blocks() as interface:
|
| 70 |
language_state = gr.State("english") # Store current language
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
title = gr.Markdown("## History Chatbot")
|
| 73 |
lang_button = gr.Button("FR")
|
|
@@ -77,38 +98,21 @@ with gr.Blocks() as interface:
|
|
| 77 |
chatbot = gr.Chatbot(type="messages")
|
| 78 |
state = gr.State([])
|
| 79 |
|
| 80 |
-
#
|
| 81 |
-
|
| 82 |
-
examples=
|
| 83 |
-
|
| 84 |
-
"Who built the Colosseum?",
|
| 85 |
-
"What caused the fall of the Roman Empire?",
|
| 86 |
-
"When did World War II begin and end?",
|
| 87 |
-
"What was the significance of the Magna Carta?",
|
| 88 |
-
"Who was the first person to step on the moon?"
|
| 89 |
-
],
|
| 90 |
-
inputs=user_input,
|
| 91 |
-
visible=True
|
| 92 |
-
)
|
| 93 |
-
|
| 94 |
-
french_examples = gr.Examples(
|
| 95 |
-
examples=[
|
| 96 |
-
"Comment la tour de Pise a-t-elle commencé à pencher ?",
|
| 97 |
-
"Qui a construit le Colisée ?",
|
| 98 |
-
"Quelles sont les causes de la chute de l'Empire romain ?",
|
| 99 |
-
"Quand la Seconde Guerre mondiale a-t-elle commencé et terminé ?",
|
| 100 |
-
"Quelle est l'importance de la Magna Carta ?",
|
| 101 |
-
"Qui était la première personne à marcher sur la lune?"
|
| 102 |
-
],
|
| 103 |
-
inputs=user_input,
|
| 104 |
-
visible=False # Initially hidden
|
| 105 |
)
|
| 106 |
|
| 107 |
# Toggle language and update all necessary elements
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
lang_button.click(
|
| 109 |
-
fn=
|
| 110 |
inputs=[language_state],
|
| 111 |
-
outputs=[language_state, title, lang_button, user_input, send_button,
|
| 112 |
)
|
| 113 |
|
| 114 |
send_button.click(
|
|
|
|
| 43 |
chat_history.append({"role": "user", "content": user_input})
|
| 44 |
chat_history.append({"role": "assistant", "content": reply})
|
| 45 |
return chat_history, chat_history, ""
|
| 46 |
+
|
| 47 |
def toggle_language(language):
|
| 48 |
"""Toggle UI elements between English and French."""
|
| 49 |
if language == "english":
|
|
|
|
| 53 |
"EN", # New language button label
|
| 54 |
"Entrez votre question ici...", # New placeholder text
|
| 55 |
"Envoyer", # New send button label
|
| 56 |
+
[
|
| 57 |
+
"Comment la tour de Pise a-t-elle commencé à pencher ?",
|
| 58 |
+
"Qui a construit le Colisée ?",
|
| 59 |
+
"Quelles sont les causes de la chute de l'Empire romain ?",
|
| 60 |
+
"Quand la Seconde Guerre mondiale a-t-elle commencé et terminé ?",
|
| 61 |
+
"Quelle est l'importance de la Magna Carta ?",
|
| 62 |
+
"Qui était la première personne à marcher sur la lune?"
|
| 63 |
+
]
|
| 64 |
)
|
| 65 |
else:
|
| 66 |
return (
|
|
|
|
| 69 |
"FR",
|
| 70 |
"Enter your question here...",
|
| 71 |
"Send",
|
| 72 |
+
[
|
| 73 |
+
"How did the Leaning Tower of Pisa start leaning?",
|
| 74 |
+
"Who built the Colosseum?",
|
| 75 |
+
"What caused the fall of the Roman Empire?",
|
| 76 |
+
"When did World War II begin and end?",
|
| 77 |
+
"What was the significance of the Magna Carta?",
|
| 78 |
+
"Who was the first person to step on the moon?"
|
| 79 |
+
]
|
| 80 |
)
|
| 81 |
|
| 82 |
with gr.Blocks() as interface:
|
| 83 |
language_state = gr.State("english") # Store current language
|
| 84 |
+
example_state = gr.State([ # Store examples dynamically
|
| 85 |
+
"How did the Leaning Tower of Pisa start leaning?",
|
| 86 |
+
"Who built the Colosseum?",
|
| 87 |
+
"What caused the fall of the Roman Empire?",
|
| 88 |
+
"When did World War II begin and end?",
|
| 89 |
+
"What was the significance of the Magna Carta?",
|
| 90 |
+
"Who was the first person to step on the moon?"
|
| 91 |
+
])
|
| 92 |
|
| 93 |
title = gr.Markdown("## History Chatbot")
|
| 94 |
lang_button = gr.Button("FR")
|
|
|
|
| 98 |
chatbot = gr.Chatbot(type="messages")
|
| 99 |
state = gr.State([])
|
| 100 |
|
| 101 |
+
# Use `example_state` to update examples dynamically
|
| 102 |
+
examples = gr.Examples(
|
| 103 |
+
examples=example_state.value,
|
| 104 |
+
inputs=user_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
)
|
| 106 |
|
| 107 |
# Toggle language and update all necessary elements
|
| 108 |
+
def update_ui(language):
|
| 109 |
+
new_language, new_title, new_button_text, new_placeholder, new_send_label, new_examples = toggle_language(language)
|
| 110 |
+
return new_language, new_title, new_button_text, new_placeholder, new_send_label, gr.update(value=new_examples)
|
| 111 |
+
|
| 112 |
lang_button.click(
|
| 113 |
+
fn=update_ui,
|
| 114 |
inputs=[language_state],
|
| 115 |
+
outputs=[language_state, title, lang_button, user_input, send_button, example_state]
|
| 116 |
)
|
| 117 |
|
| 118 |
send_button.click(
|