Rahatara commited on
Commit
c77f74c
1 Parent(s): 6807d54

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
5
+
6
+ def respond(
7
+ message,
8
+ history: list[tuple[str, str]],
9
+ system_message,
10
+ max_tokens,
11
+ temperature,
12
+ top_p,
13
+ ):
14
+ messages = [{"role": "system", "content": system_message + " I'm here to help you relax. You can talk to me about anything that's on your mind or ask for relaxation tips."}]
15
+
16
+ for val in history:
17
+ if val[0]:
18
+ messages.append({"role": "user", "content": val[0]})
19
+ if val[1]:
20
+ messages.append({"role": "assistant", "content": val[1]})
21
+
22
+ messages.append({"role": "user", "content": message})
23
+
24
+ response = ""
25
+
26
+ for message in client.chat_completion(
27
+ messages,
28
+ max_tokens=max_tokens,
29
+ stream=True,
30
+ temperature=temperature,
31
+ top_p=top_p,
32
+ ):
33
+ token = message.choices[0].delta.content
34
+
35
+ response += token
36
+ yield response
37
+
38
+ demo = gr.ChatInterface(
39
+ respond,
40
+ additional_inputs=[
41
+ gr.Textbox(value="Remember to breathe and take things one step at a time.", label="System message"),
42
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
43
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
44
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
45
+ ],
46
+ examples=[
47
+ ["I'm feeling stressed about work."],
48
+ ["Can you give me a relaxation tip?"],
49
+ ["I need help winding down after a long day."]
50
+ ],
51
+ title="Calm Mate" # Setting the title of the app
52
+ )
53
+
54
+ if __name__ == "__main__":
55
+ demo.launch()