3v324v23 commited on
Commit
dfcc1ef
·
1 Parent(s): cac699e
Files changed (1) hide show
  1. app.py +76 -6
app.py CHANGED
@@ -1,8 +1,78 @@
1
- # Use a pipeline as a high-level helper
 
2
  from transformers import pipeline
3
 
4
- pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1-Distill-Qwen-14B")
5
- messages = [
6
- {"role": "user", "content": "Who are you?"},
7
- ]
8
- pipe(messages)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
  from transformers import pipeline
4
 
5
+
6
+ def respond(
7
+ message,
8
+ history: list[dict[str, str]],
9
+ system_message,
10
+ max_tokens,
11
+ temperature,
12
+ top_p,
13
+ hf_token: gr.OAuthToken,
14
+ ):
15
+ """
16
+ 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
17
+ """
18
+ client = InferenceClient(token=hf_token.token, model="deepseek-ai/DeepSeek-R1-Distill-Qwen-14B")
19
+
20
+ messages = [{"role": "system", "content": system_message}]
21
+
22
+ messages.extend(history)
23
+
24
+ messages.append({"role": "user", "content": message})
25
+
26
+ response = ""
27
+
28
+ for message in client.chat_completion(
29
+ messages,
30
+ max_tokens=max_tokens,
31
+ stream=True,
32
+ temperature=temperature,
33
+ top_p=top_p,
34
+ ):
35
+ choices = message.choices
36
+ token = ""
37
+ if len(choices) and choices[0].delta.content:
38
+ token = choices[0].delta.content
39
+
40
+ response += token
41
+ yield response
42
+
43
+
44
+ """
45
+ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
46
+ """
47
+ chatbot = gr.ChatInterface(
48
+ respond,
49
+ type="messages",
50
+ additional_inputs=[
51
+ gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
52
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
53
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
54
+ gr.Slider(
55
+ minimum=0.1,
56
+ maximum=1.0,
57
+ value=0.95,
58
+ step=0.05,
59
+ label="Top-p (nucleus sampling)",
60
+ ),
61
+ ],
62
+ )
63
+
64
+ with gr.Blocks() as demo:
65
+ with gr.Sidebar():
66
+ gr.LoginButton()
67
+ chatbot.render()
68
+
69
+
70
+ if __name__ == "__main__":
71
+ # Use a pipeline as a high-level helper
72
+
73
+ pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1-Distill-Qwen-14B")
74
+ messages = [
75
+ {"role": "user", "content": "Who are you?"},
76
+ ]
77
+ pipe(messages)
78
+ demo.launch()