Spaces:
Runtime error
Runtime error
wowww
Browse files- app.py +18 -31
- requirements.txt +3 -0
app.py
CHANGED
|
@@ -1,42 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
-
import torch
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 9 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
|
| 10 |
-
|
| 11 |
-
# Inference function
|
| 12 |
def generate(prompt, max_new_tokens=256, temperature=0.7, top_p=0.95):
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
**inputs,
|
| 16 |
max_new_tokens=max_new_tokens,
|
| 17 |
temperature=temperature,
|
| 18 |
-
top_p=top_p
|
| 19 |
-
do_sample=True,
|
| 20 |
-
pad_token_id=tokenizer.eos_token_id
|
| 21 |
)
|
| 22 |
-
|
| 23 |
-
return response
|
| 24 |
|
| 25 |
-
# Gradio UI
|
| 26 |
with gr.Blocks() as demo:
|
| 27 |
-
gr.Markdown("## 🚀 DeepSeek
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
with gr.Row():
|
| 33 |
-
max_tokens = gr.Slider(64, 1024, value=256, step=16, label="Max new tokens")
|
| 34 |
-
temperature = gr.Slider(0.1, 1.5, value=0.7, step=0.1, label="Temperature")
|
| 35 |
-
top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p")
|
| 36 |
-
|
| 37 |
output = gr.Textbox(label="Generated Text")
|
| 38 |
-
|
| 39 |
-
generate_btn = gr.Button("Generate")
|
| 40 |
-
generate_btn.click(fn=generate, inputs=[prompt, max_tokens, temperature, top_p], outputs=output)
|
| 41 |
-
|
| 42 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
+
# Load using CPU-only settings
|
| 5 |
+
pipe = pipeline(
|
| 6 |
+
"text-generation",
|
| 7 |
+
model="deepseek-ai/DeepSeek-R1",
|
| 8 |
+
device=-1, # Force CPU usage
|
| 9 |
+
trust_remote_code=True # Support custom model code
|
| 10 |
+
)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def generate(prompt, max_new_tokens=256, temperature=0.7, top_p=0.95):
|
| 13 |
+
outputs = pipe(
|
| 14 |
+
prompt,
|
|
|
|
| 15 |
max_new_tokens=max_new_tokens,
|
| 16 |
temperature=temperature,
|
| 17 |
+
top_p=top_p
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
+
return outputs[0]["generated_text"]
|
|
|
|
| 20 |
|
|
|
|
| 21 |
with gr.Blocks() as demo:
|
| 22 |
+
gr.Markdown("## 🚀 DeepSeek‑R1 (CPU Gradio Demo)")
|
| 23 |
+
prompt = gr.Textbox(label="Prompt")
|
| 24 |
+
max_tokens = gr.Slider(64, 1024, value=256, step=16, label="Max new tokens")
|
| 25 |
+
temperature = gr.Slider(0.1, 1.5, value=0.7, step=0.1, label="Temperature")
|
| 26 |
+
top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top‑p")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
output = gr.Textbox(label="Generated Text")
|
| 28 |
+
demo.Button("Generate").click(fn=generate, inputs=[prompt, max_tokens, temperature, top_p], outputs=output)
|
|
|
|
|
|
|
|
|
|
| 29 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers[torch]
|
| 2 |
+
torch
|
| 3 |
+
gradio
|