keivalya commited on
Commit
9bcab22
·
1 Parent(s): f790b7b

Update space

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -4,8 +4,16 @@ from huggingface_hub import InferenceClient
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
  """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
 
 
 
 
 
 
 
9
 
10
  def respond(
11
  message,
@@ -37,7 +45,9 @@ def respond(
37
  token = message.choices[0].delta.content
38
 
39
  response += token
40
- yield response
 
 
41
 
42
 
43
  """
@@ -46,7 +56,7 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
46
  demo = gr.ChatInterface(
47
  respond,
48
  additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
  gr.Slider(
@@ -59,6 +69,5 @@ demo = gr.ChatInterface(
59
  ],
60
  )
61
 
62
-
63
  if __name__ == "__main__":
64
  demo.launch()
 
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
  """
7
+ client = InferenceClient("mistralai/Mistral-7B-v0.1")
8
 
9
+ def yodaify_text(text):
10
+ """
11
+ Convert the assistant's response to Yoda-style speech.
12
+ """
13
+ words = text.split()
14
+ if len(words) > 4:
15
+ return f"{' '.join(words[2:])}, {words[0]} {words[1]}"
16
+ return f"{' '.join(words[::-1])}"
17
 
18
  def respond(
19
  message,
 
45
  token = message.choices[0].delta.content
46
 
47
  response += token
48
+ # Modify assistant response to Yoda-style speech
49
+ yoda_response = yodaify_text(response)
50
+ yield yoda_response
51
 
52
 
53
  """
 
56
  demo = gr.ChatInterface(
57
  respond,
58
  additional_inputs=[
59
+ gr.Textbox(value="You are a wise and cryptic assistant who speaks like Yoda.", label="System message"),
60
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
61
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
62
  gr.Slider(
 
69
  ],
70
  )
71
 
 
72
  if __name__ == "__main__":
73
  demo.launch()