Chad commited on
Commit ·
c6a8aac
1
Parent(s): 9f99078
lang togglwdwdwde
Browse files
app.py
CHANGED
|
@@ -9,8 +9,6 @@ if not api_key:
|
|
| 9 |
|
| 10 |
client = Groq(api_key=api_key)
|
| 11 |
|
| 12 |
-
language = 'english' # Default UI language
|
| 13 |
-
|
| 14 |
def generate_reply(user_input, chat_history):
|
| 15 |
if chat_history is None:
|
| 16 |
chat_history = []
|
|
@@ -46,48 +44,55 @@ def generate_reply(user_input, chat_history):
|
|
| 46 |
chat_history.append({"role": "assistant", "content": reply})
|
| 47 |
return chat_history, chat_history, ""
|
| 48 |
|
| 49 |
-
def toggle_language():
|
| 50 |
-
|
| 51 |
if language == "english":
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
else:
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
title = gr.Markdown("## History Chatbot")
|
| 60 |
lang_button = gr.Button("FR")
|
|
|
|
|
|
|
| 61 |
chatbot = gr.Chatbot(type="messages")
|
| 62 |
state = gr.State([])
|
| 63 |
-
user_input = gr.Textbox(placeholder="Enter your question here...")
|
| 64 |
send_button = gr.Button("Send")
|
| 65 |
|
| 66 |
-
lang_button.click(fn=toggle_language, inputs=[], outputs=[title, lang_button])
|
| 67 |
-
|
| 68 |
-
examples_english = [
|
| 69 |
-
"How did the Leaning Tower of Pisa start leaning?",
|
| 70 |
-
"Who built the Colosseum?",
|
| 71 |
-
"What caused the fall of the Roman Empire?",
|
| 72 |
-
"When did World War II begin and end?",
|
| 73 |
-
"What was the significance of the Magna Carta?",
|
| 74 |
-
"Who was the first person to step on the moon?"
|
| 75 |
-
]
|
| 76 |
-
|
| 77 |
-
examples_french = [
|
| 78 |
-
"Comment la tour de Pise a-t-elle commencé à pencher ?",
|
| 79 |
-
"Qui a construit le Colisée ?",
|
| 80 |
-
"Quelles sont les causes de la chute de l'Empire romain ?",
|
| 81 |
-
"Quand la Seconde Guerre mondiale a-t-elle commencé et terminé ?",
|
| 82 |
-
"Quelle est l'importance de la Magna Carta ?",
|
| 83 |
-
"Qui était la première personne à marcher sur la lune?"
|
| 84 |
-
]
|
| 85 |
-
|
| 86 |
examples = gr.Examples(
|
| 87 |
-
examples=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
inputs=user_input
|
| 89 |
)
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
send_button.click(
|
| 92 |
fn=generate_reply,
|
| 93 |
inputs=[user_input, state],
|
|
@@ -98,4 +103,4 @@ with gr.Blocks() as interface:
|
|
| 98 |
reset_button.click(lambda: [], outputs=[state])
|
| 99 |
|
| 100 |
if __name__ == "__main__":
|
| 101 |
-
|
|
|
|
| 9 |
|
| 10 |
client = Groq(api_key=api_key)
|
| 11 |
|
|
|
|
|
|
|
| 12 |
def generate_reply(user_input, chat_history):
|
| 13 |
if chat_history is None:
|
| 14 |
chat_history = []
|
|
|
|
| 44 |
chat_history.append({"role": "assistant", "content": reply})
|
| 45 |
return chat_history, chat_history, ""
|
| 46 |
|
| 47 |
+
def toggle_language(language):
|
| 48 |
+
"""Toggle language between English and French and update UI elements."""
|
| 49 |
if language == "english":
|
| 50 |
+
return "french", "## Chatbot d'histoire", "EN", "Entrez votre question ici...", [
|
| 51 |
+
"Comment la tour de Pise a-t-elle commencé à pencher ?",
|
| 52 |
+
"Qui a construit le Colisée ?",
|
| 53 |
+
"Quelles sont les causes de la chute de l'Empire romain ?",
|
| 54 |
+
"Quand la Seconde Guerre mondiale a-t-elle commencé et terminé ?",
|
| 55 |
+
"Quelle est l'importance de la Magna Carta ?",
|
| 56 |
+
"Qui était la première personne à marcher sur la lune?"
|
| 57 |
+
]
|
| 58 |
else:
|
| 59 |
+
return "english", "## History Chatbot", "FR", "Enter your question here...", [
|
| 60 |
+
"How did the Leaning Tower of Pisa start leaning?",
|
| 61 |
+
"Who built the Colosseum?",
|
| 62 |
+
"What caused the fall of the Roman Empire?",
|
| 63 |
+
"When did World War II begin and end?",
|
| 64 |
+
"What was the significance of the Magna Carta?",
|
| 65 |
+
"Who was the first person to step on the moon?"
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
with gr.Blocks() as demo:
|
| 69 |
+
language_state = gr.State("english")
|
| 70 |
title = gr.Markdown("## History Chatbot")
|
| 71 |
lang_button = gr.Button("FR")
|
| 72 |
+
user_input = gr.Textbox(placeholder="Enter your question here...")
|
| 73 |
+
|
| 74 |
chatbot = gr.Chatbot(type="messages")
|
| 75 |
state = gr.State([])
|
|
|
|
| 76 |
send_button = gr.Button("Send")
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
examples = gr.Examples(
|
| 79 |
+
examples=[
|
| 80 |
+
"How did the Leaning Tower of Pisa start leaning?",
|
| 81 |
+
"Who built the Colosseum?",
|
| 82 |
+
"What caused the fall of the Roman Empire?",
|
| 83 |
+
"When did World War II begin and end?",
|
| 84 |
+
"What was the significance of the Magna Carta?",
|
| 85 |
+
"Who was the first person to step on the moon?"
|
| 86 |
+
],
|
| 87 |
inputs=user_input
|
| 88 |
)
|
| 89 |
|
| 90 |
+
lang_button.click(
|
| 91 |
+
fn=toggle_language,
|
| 92 |
+
inputs=[language_state],
|
| 93 |
+
outputs=[language_state, title, lang_button, user_input, examples]
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
send_button.click(
|
| 97 |
fn=generate_reply,
|
| 98 |
inputs=[user_input, state],
|
|
|
|
| 103 |
reset_button.click(lambda: [], outputs=[state])
|
| 104 |
|
| 105 |
if __name__ == "__main__":
|
| 106 |
+
demo.launch(share=True)
|