Chad commited on
Commit
d8dc558
·
1 Parent(s): bd095b8

lanewhfhweifqwiurn3rtun3q4tg togglwdwdwdeeefefefdwdwdwdwd

Browse files
Files changed (1) hide show
  1. app.py +33 -38
app.py CHANGED
@@ -43,7 +43,6 @@ 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
-
47
  def toggle_language(language):
48
  """Toggle UI elements between English and French."""
49
  if language == "english":
@@ -53,14 +52,8 @@ def toggle_language(language):
53
  "EN", # New language button label
54
  "Entrez votre question ici...", # New placeholder text
55
  "Envoyer", # New send button label
56
- [ # New examples
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,16 +62,10 @@ def toggle_language(language):
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
 
@@ -90,30 +77,38 @@ with gr.Blocks() as interface:
90
  chatbot = gr.Chatbot(type="messages")
91
  state = gr.State([])
92
 
93
- # Create examples dynamically
94
- example_container = gr.Column()
95
- with example_container:
96
- example_component = gr.Examples(
97
- examples=[
98
- "How did the Leaning Tower of Pisa start leaning?",
99
- "Who built the Colosseum?",
100
- "What caused the fall of the Roman Empire?",
101
- "When did World War II begin and end?",
102
- "What was the significance of the Magna Carta?",
103
- "Who was the first person to step on the moon?"
104
- ],
105
- inputs=user_input
106
- )
107
 
108
- # Toggle language and update all necessary elements
109
- def update_ui(language):
110
- new_language, new_title, new_button_text, new_placeholder, new_send_label, new_examples = toggle_language(language)
111
- return new_language, new_title, new_button_text, new_placeholder, new_send_label, gr.Examples(examples=new_examples, inputs=user_input)
 
 
 
 
 
 
 
 
112
 
 
113
  lang_button.click(
114
- fn=update_ui,
115
  inputs=[language_state],
116
- outputs=[language_state, title, lang_button, user_input, send_button, example_container]
117
  )
118
 
119
  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
  def toggle_language(language):
47
  """Toggle UI elements between English and French."""
48
  if language == "english":
 
52
  "EN", # New language button label
53
  "Entrez votre question ici...", # New placeholder text
54
  "Envoyer", # New send button label
55
+ gr.update(visible=False), # Hide English examples
56
+ gr.update(visible=True) # Show French examples
 
 
 
 
 
 
57
  )
58
  else:
59
  return (
 
62
  "FR",
63
  "Enter your question here...",
64
  "Send",
65
+ gr.update(visible=True), # Show English examples
66
+ gr.update(visible=False) # Hide French examples
 
 
 
 
 
 
67
  )
68
+
69
  with gr.Blocks() as interface:
70
  language_state = gr.State("english") # Store current language
71
 
 
77
  chatbot = gr.Chatbot(type="messages")
78
  state = gr.State([])
79
 
80
+ # Predefine English and French examples (hidden by default)
81
+ english_examples = gr.Examples(
82
+ examples=[
83
+ "How did the Leaning Tower of Pisa start leaning?",
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=toggle_language,
110
  inputs=[language_state],
111
+ outputs=[language_state, title, lang_button, user_input, send_button, english_examples, french_examples]
112
  )
113
 
114
  send_button.click(