arshadrana commited on
Commit
78d74d3
·
verified ·
1 Parent(s): 2a98d25

Upload appa_py.py

Browse files
Files changed (1) hide show
  1. appa_py.py +75 -0
appa_py.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """appa.py
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1Q8Cg2gzxOElv-iafacXTGyDyYTBVxX3U
8
+ """
9
+
10
+
11
+
12
+ !pip install gradio
13
+ import gradio as gr
14
+ from huggingface_hub import InferenceClient
15
+
16
+ """
17
+ 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
18
+ """
19
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
20
+
21
+
22
+ def respond(
23
+ message,
24
+ history: list[tuple[str, str]],
25
+ system_message,
26
+ max_tokens,
27
+ temperature,
28
+ top_p,
29
+ ):
30
+ messages = [{"role": "system", "content": system_message}]
31
+
32
+ for val in history:
33
+ if val[0]:
34
+ messages.append({"role": "user", "content": val[0]})
35
+ if val[1]:
36
+ messages.append({"role": "assistant", "content": val[1]})
37
+
38
+ messages.append({"role": "user", "content": message})
39
+
40
+ response = ""
41
+
42
+ for message in client.chat_completion(
43
+ messages,
44
+ max_tokens=max_tokens,
45
+ stream=True,
46
+ temperature=temperature,
47
+ top_p=top_p,
48
+ ):
49
+ token = message.choices[0].delta.content
50
+
51
+ response += token
52
+ yield response
53
+
54
+ """
55
+ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
56
+ """
57
+ demo = gr.ChatInterface(
58
+ respond,
59
+ additional_inputs=[
60
+ gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
61
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
62
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
63
+ gr.Slider(
64
+ minimum=0.1,
65
+ maximum=1.0,
66
+ value=0.95,
67
+ step=0.05,
68
+ label="Top-p (nucleus sampling)",
69
+ ),
70
+ ],
71
+ )
72
+
73
+
74
+ if __name__ == "__main__":
75
+ demo.launch()