Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
)
|
9 |
|
10 |
def chat(prompt):
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
return
|
15 |
|
16 |
-
gr.Interface(
|
17 |
-
fn=chat,
|
18 |
-
inputs="text",
|
19 |
-
outputs="text",
|
20 |
-
title="DeepSeek Coder 6.7B",
|
21 |
-
description="Free ChatGPT-style coding assistant",
|
22 |
-
theme="soft"
|
23 |
-
).launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
|
5 |
+
model_id = "deepseek-ai/deepseek-coder-6.7b-instruct"
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
9 |
+
model_id,
|
10 |
+
device_map="auto",
|
11 |
+
torch_dtype=torch.float16,
|
12 |
+
trust_remote_code=True
|
13 |
)
|
14 |
|
15 |
def chat(prompt):
|
16 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
17 |
+
outputs = model.generate(**inputs, max_new_tokens=256, do_sample=True)
|
18 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
19 |
+
return response
|
20 |
|
21 |
+
gr.Interface(fn=chat, inputs="text", outputs="text", title="DeepSeek Coder 6.7B Chatbot").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|