timbosssds commited on
Commit
e23d8ec
·
verified ·
1 Parent(s): ab3a416

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -3
app.py CHANGED
@@ -1,5 +1,5 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
 
4
  # def form_fn(name, email):
5
  # return f"Name: {name}, Email: {email}"
@@ -14,8 +14,58 @@ from huggingface_hub import InferenceClient
14
  #)
15
  # demo.launch()
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
 
 
 
18
  demo = gr.ChatInterface(
 
19
  additional_inputs=[
20
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
21
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
@@ -32,4 +82,4 @@ demo = gr.ChatInterface(
32
 
33
 
34
  if __name__ == "__main__":
35
- demo.launch()
 
1
+ # import gradio as gr
2
+ # from huggingface_hub import InferenceClient
3
 
4
  # def form_fn(name, email):
5
  # return f"Name: {name}, Email: {email}"
 
14
  #)
15
  # demo.launch()
16
 
17
+ # ------------
18
+
19
+
20
+
21
+ # ------------------ Below works ------------------
22
+
23
+ import gradio as gr
24
+ from huggingface_hub import InferenceClient
25
+
26
+ """
27
+ 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
28
+ """
29
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
30
+
31
+
32
+ def respond(
33
+ message,
34
+ history: list[tuple[str, str]],
35
+ system_message,
36
+ max_tokens,
37
+ temperature,
38
+ top_p,
39
+ ):
40
+ messages = [{"role": "system", "content": system_message}]
41
+
42
+ for val in history:
43
+ if val[0]:
44
+ messages.append({"role": "user", "content": val[0]})
45
+ if val[1]:
46
+ messages.append({"role": "assistant", "content": val[1]})
47
+
48
+ messages.append({"role": "user", "content": message})
49
+
50
+ response = ""
51
+
52
+ for message in client.chat_completion(
53
+ messages,
54
+ max_tokens=max_tokens,
55
+ stream=True,
56
+ temperature=temperature,
57
+ top_p=top_p,
58
+ ):
59
+ token = message.choices[0].delta.content
60
+
61
+ response += token
62
+ yield response
63
 
64
+ """
65
+ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
66
+ """
67
  demo = gr.ChatInterface(
68
+ respond,
69
  additional_inputs=[
70
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
71
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
 
82
 
83
 
84
  if __name__ == "__main__":
85
+ demo.launch()