Garvitj commited on
Commit
3c9e8cf
·
verified ·
1 Parent(s): f5a2edd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -13
app.py CHANGED
@@ -1,19 +1,49 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Load the DeepSeek model
5
- # pipe = pipeline("text-generation", model="deepseek-ai/deepseek-llm-7b", trust_remote_code=True)
 
6
 
7
- pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1", trust_remote_code=True)
8
 
9
- # Function to interact with the chatbot
10
- def chat_with_bot(message, chat_history):
11
- messages = [{"role": "user", "content": message}]
12
- response = pipe(messages, max_length=512)
13
- return response[0]["generated_text"]
14
 
15
- # Create Gradio UI
16
- interface = gr.ChatInterface(fn=chat_with_bot, title="DeepSeek AI Chatbot")
 
 
 
17
 
18
- # Launch the chatbot
19
- interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
 
4
+ # Using Zephyr-7B Beta
5
+ MODEL_NAME = "HuggingFaceH4/zephyr-7b-beta"
6
+ client = InferenceClient(MODEL_NAME)
7
 
 
8
 
9
+ def respond(message, history, system_message, max_tokens, temperature, top_p):
10
+ messages = [{"role": "system", "content": system_message}]
 
 
 
11
 
12
+ for val in history:
13
+ if val[0]:
14
+ messages.append({"role": "user", "content": val[0]})
15
+ if val[1]:
16
+ messages.append({"role": "assistant", "content": val[1]})
17
 
18
+ messages.append({"role": "user", "content": message})
19
+
20
+ response = ""
21
+
22
+ try:
23
+ for message in client.chat_completion(
24
+ messages,
25
+ max_tokens=max_tokens,
26
+ stream=True,
27
+ temperature=temperature,
28
+ top_p=top_p,
29
+ ):
30
+ token = message.choices[0].delta.content if message.choices[0].delta else ""
31
+ response += token
32
+ yield response
33
+ except Exception as e:
34
+ yield f"Error: {str(e)}"
35
+
36
+
37
+ # Gradio UI with adjustable settings
38
+ demo = gr.ChatInterface(
39
+ respond,
40
+ additional_inputs=[
41
+ gr.Textbox(value="You are a friendly chatbot.", label="System message"),
42
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max Tokens"),
43
+ gr.Slider(minimum=0.1, maximum=2.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"),
45
+ ],
46
+ )
47
+
48
+ if __name__ == "__main__":
49
+ demo.launch()