sufian7755 commited on
Commit
3338976
·
verified ·
1 Parent(s): 92eaa32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -1,25 +1,27 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
4
- # Load DeepSeek-R1 model
5
- model_name = "deepseek-ai/DeepSeek-R1"
 
 
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
- model = AutoModelForCausalLM.from_pretrained(model_name)
 
 
 
8
 
9
- # Chat function
10
  def chat_with_ai(prompt):
11
- inputs = tokenizer(prompt, return_tensors="pt")
12
- outputs = model.generate(**inputs, max_new_tokens=250)
13
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
14
- return response
15
 
16
- # Gradio UI
17
  ui = gr.Interface(
18
  fn=chat_with_ai,
19
- inputs=gr.Textbox(label="Ask me anything..."),
20
  outputs="text",
21
- title="💬 DeepSeek-R1 AI",
22
- description="Chat with your own DeepSeek-R1 model hosted on Hugging Face Cloud!"
23
  )
24
 
25
  ui.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
3
 
4
+ # Smaller DeepSeek model that runs on CPU
5
+ model_name = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
6
+
7
+ # Load tokenizer & model
8
  tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto")
10
+
11
+ # Create a text generation pipeline
12
+ chatbot = pipeline("text-generation", model=model, tokenizer=tokenizer)
13
 
 
14
  def chat_with_ai(prompt):
15
+ response = chatbot(prompt, max_new_tokens=200, do_sample=True, temperature=0.7)
16
+ return response[0]["generated_text"]
 
 
17
 
18
+ # Gradio interface
19
  ui = gr.Interface(
20
  fn=chat_with_ai,
21
+ inputs=gr.Textbox(label="Ask DeepSeek something..."),
22
  outputs="text",
23
+ title="🤖 DeepSeek-R1 (Distilled Version)",
24
+ description="Chat with the smaller DeepSeek-R1 that runs even without a GPU!"
25
  )
26
 
27
  ui.launch()