rvdbra commited on
Commit
1daa389
·
verified ·
1 Parent(s): b30eab9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -24
app.py CHANGED
@@ -163,8 +163,8 @@ workflow.add_edge("generate", END)
163
  workflow.set_entry_point("query_or_respond")
164
  graph = workflow.compile()
165
 
166
- #Gradio UI
167
  import gradio as gr
 
168
  # Global chat history (for demo purposes)
169
  chat_histories = {}
170
 
@@ -175,27 +175,21 @@ def stream_response(user_input, user_id):
175
  "messages": [{"role": "user", "content": user_input}],
176
  "user_id": user_id,
177
  }
178
-
179
  collected = ""
180
  for step in graph.stream(state, stream_mode="values"):
181
  message = step["messages"][-1].content
182
- # Stream response token by token
183
  for token in message:
184
  collected += token
185
  yield collected
186
 
187
-
188
-
189
  def respond(user_message, chat_history, user_id):
190
  if user_id not in chat_histories:
191
  chat_histories[user_id] = []
192
-
193
  response_generator = stream_response(user_message, user_id)
194
  full_response = ""
195
  for partial in response_generator:
196
  full_response = partial
197
  yield chat_history + [[user_message, full_response]]
198
-
199
  chat_histories[user_id].append([user_message, full_response])
200
 
201
  def clear_history():
@@ -204,9 +198,10 @@ def clear_history():
204
  # Multilingual description
205
  description = """
206
  ### Was ist **Einbürgerungs-Helfer**?
207
- **Deutsch:** Einbürgerungs-Helfer hilft dir, den Weg zur deutschen Staatsangehörigkeit zu verstehen – einfach, mehrsprachig, datenschutzfreundlich.
208
 
209
- **English:** Einbürgerungs-Helfer helps you understand how to get German citizenship – simple, multilingual, and privacy-friendly.
 
 
210
 
211
  **Türkçe:** Einbürgerungs-Helfer, Almanya vatandaşlığına giden yolu anlamanıza yardımcı olur – basit, çok dilli ve gizliliğe saygılı.
212
 
@@ -217,26 +212,23 @@ with gr.Blocks(
217
  theme=gr.themes.Soft(primary_hue="blue"),
218
  css="""
219
  @import url('https://fonts.googleapis.com/css2?family=Noto+Sans&display=swap');
220
-
221
- * {
222
- font-family: 'Noto Sans', sans-serif !important;
223
- }
224
  """
225
  ) as iface:
226
- gr.Markdown(f"# Einbürgerungs-Helfer\n{description}")
227
 
228
  with gr.Row():
229
  user_id_input = gr.Textbox(label="Benutzer-ID (User ID)", placeholder="z.B. user_123", lines=1)
230
  clear_btn = gr.Button("🗑️ Verlauf löschen")
231
 
232
  chatbot = gr.Chatbot(
233
- label="Chat",
234
- show_copy_button=True,
235
- value=[[None,
236
- "Ich bin hier, um Ihnen bei allen Fragen zur Einbürgerung in Deutschland zu helfen.\n"
237
- "Sie können Ihre Frage auf Deutsch, Englisch, Türkisch oder Arabisch stellen.\n"
238
- "Lassen Sie uns loslegen – wie kann ich Ihnen heute helfen?"]]
239
- )
240
 
241
  msg_input = gr.Textbox(placeholder="Frage eingeben...", label="Deine Nachricht")
242
 
@@ -247,10 +239,10 @@ with gr.Blocks(
247
  fn=respond,
248
  inputs=[msg_input, chatbot, user_id_input],
249
  outputs=chatbot,
 
250
  )
251
 
252
  clear_btn.click(fn=clear_history, inputs=[], outputs=[user_id_input, chatbot])
253
- if __name__ == "__main__":
254
- iface.launch(share=True)
255
-
256
 
 
 
 
163
  workflow.set_entry_point("query_or_respond")
164
  graph = workflow.compile()
165
 
 
166
  import gradio as gr
167
+
168
  # Global chat history (for demo purposes)
169
  chat_histories = {}
170
 
 
175
  "messages": [{"role": "user", "content": user_input}],
176
  "user_id": user_id,
177
  }
 
178
  collected = ""
179
  for step in graph.stream(state, stream_mode="values"):
180
  message = step["messages"][-1].content
 
181
  for token in message:
182
  collected += token
183
  yield collected
184
 
 
 
185
  def respond(user_message, chat_history, user_id):
186
  if user_id not in chat_histories:
187
  chat_histories[user_id] = []
 
188
  response_generator = stream_response(user_message, user_id)
189
  full_response = ""
190
  for partial in response_generator:
191
  full_response = partial
192
  yield chat_history + [[user_message, full_response]]
 
193
  chat_histories[user_id].append([user_message, full_response])
194
 
195
  def clear_history():
 
198
  # Multilingual description
199
  description = """
200
  ### Was ist **Einbürgerungs-Helfer**?
 
201
 
202
+ **Deutsch:** Einbürgerungs-Helfer hilft dir, den Weg zur deutschen Staatsangehörigkeit zu verstehen – einfach, mehrsprachig, datenschutzfreundlich.
203
+
204
+ **English:** Einbürgerungs-Helfer helps you understand how to get German citizenship – simple, multilingual, and privacy-friendly.
205
 
206
  **Türkçe:** Einbürgerungs-Helfer, Almanya vatandaşlığına giden yolu anlamanıza yardımcı olur – basit, çok dilli ve gizliliğe saygılı.
207
 
 
212
  theme=gr.themes.Soft(primary_hue="blue"),
213
  css="""
214
  @import url('https://fonts.googleapis.com/css2?family=Noto+Sans&display=swap');
215
+ * { font-family: 'Noto Sans', sans-serif !important; }
 
 
 
216
  """
217
  ) as iface:
218
+ gr.Markdown(f"# Einbürgerungs-Helfer\n{description}")
219
 
220
  with gr.Row():
221
  user_id_input = gr.Textbox(label="Benutzer-ID (User ID)", placeholder="z.B. user_123", lines=1)
222
  clear_btn = gr.Button("🗑️ Verlauf löschen")
223
 
224
  chatbot = gr.Chatbot(
225
+ label="Chat",
226
+ show_copy_button=True,
227
+ value=[[None,
228
+ "Ich bin hier, um Ihnen bei allen Fragen zur Einbürgerung in Deutschland zu helfen.\n"
229
+ "Sie können Ihre Frage auf Deutsch, Englisch, Türkisch oder Arabisch stellen.\n"
230
+ "Lassen Sie uns loslegen – wie kann ich Ihnen heute helfen?"]]
231
+ )
232
 
233
  msg_input = gr.Textbox(placeholder="Frage eingeben...", label="Deine Nachricht")
234
 
 
239
  fn=respond,
240
  inputs=[msg_input, chatbot, user_id_input],
241
  outputs=chatbot,
242
+ queue=True
243
  )
244
 
245
  clear_btn.click(fn=clear_history, inputs=[], outputs=[user_id_input, chatbot])
 
 
 
246
 
247
+ if __name__ == "__main__":
248
+ iface.launch(share=True)