davidberenstein1957 HF staff commited on
Commit
af275df
1 Parent(s): 6ea04d8

add language dropdown

Browse files
Files changed (1) hide show
  1. app/app.py +16 -4
app/app.py CHANGED
@@ -13,7 +13,7 @@ from gradio.components.chatbot import Option
13
  from huggingface_hub import InferenceClient
14
  from pandas import DataFrame
15
 
16
- LANGUAGES = ["English", "Spanish", "Hebrew", "Dutch"]
17
 
18
  client = InferenceClient(
19
  token=os.getenv("HF_TOKEN"),
@@ -34,6 +34,17 @@ def add_user_message(history, message):
34
  return history, gr.MultimodalTextbox(value=None, interactive=False)
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
37
  def format_system_message(language: str, history: list):
38
  if history:
39
  if history[0]["role"] == "system":
@@ -41,7 +52,7 @@ def format_system_message(language: str, history: list):
41
  system_message = [
42
  {
43
  "role": "system",
44
- "content": f"You are a helpful assistant that speaks {language}.",
45
  }
46
  ]
47
  history = system_message + history
@@ -286,8 +297,9 @@ with gr.Blocks(css=css) as demo:
286
  language = gr.Dropdown(
287
  label="Language",
288
  choices=LANGUAGES,
289
- # value="English",
290
  interactive=True,
 
291
  )
292
 
293
  chatbot = gr.Chatbot(
@@ -297,7 +309,7 @@ with gr.Blocks(css=css) as demo:
297
  value=[
298
  {
299
  "role": "system",
300
- "content": "You are a helpful assistant that speaks English.",
301
  }
302
  ],
303
  type="messages",
 
13
  from huggingface_hub import InferenceClient
14
  from pandas import DataFrame
15
 
16
+ LANGUAGES: list[str] = ["English", "Spanish", "Hebrew", "Dutch"]
17
 
18
  client = InferenceClient(
19
  token=os.getenv("HF_TOKEN"),
 
34
  return history, gr.MultimodalTextbox(value=None, interactive=False)
35
 
36
 
37
+ def get_system_message(language: str) -> str:
38
+ if language == "English":
39
+ return "You are a helpful assistant that speaks English."
40
+ elif language == "Spanish":
41
+ return "Tu eres un asistente 煤til que habla espa帽ol."
42
+ elif language == "Hebrew":
43
+ return "讗转讛 注讜讝专 讟讜讘 砖诪驻讙砖 讘注讘专讬转."
44
+ elif language == "Dutch":
45
+ return "Je bent een handige assistent die Nederlands spreekt."
46
+
47
+
48
  def format_system_message(language: str, history: list):
49
  if history:
50
  if history[0]["role"] == "system":
 
52
  system_message = [
53
  {
54
  "role": "system",
55
+ "content": get_system_message(language),
56
  }
57
  ]
58
  history = system_message + history
 
297
  language = gr.Dropdown(
298
  label="Language",
299
  choices=LANGUAGES,
300
+ value=LANGUAGES[0],
301
  interactive=True,
302
+ max_choices=1,
303
  )
304
 
305
  chatbot = gr.Chatbot(
 
309
  value=[
310
  {
311
  "role": "system",
312
+ "content": get_system_message(language.value),
313
  }
314
  ],
315
  type="messages",