Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
|
4 |
-
#
|
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 |
-
|
12 |
-
|
13 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
14 |
-
return response
|
15 |
|
16 |
-
# Gradio
|
17 |
ui = gr.Interface(
|
18 |
fn=chat_with_ai,
|
19 |
-
inputs=gr.Textbox(label="Ask
|
20 |
outputs="text",
|
21 |
-
title="
|
22 |
-
description="Chat with
|
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()
|