Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
|
5 |
+
# Load the model and tokenizer
|
6 |
+
MODEL_NAME = "deepseek-ai/deepseek-coder-1.3b-instruct"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16, device_map="auto")
|
9 |
+
|
10 |
+
# Function to generate responses
|
11 |
+
def generate_response(prompt):
|
12 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
13 |
+
input_ids = inputs["input_ids"]
|
14 |
+
attention_mask = inputs["attention_mask"]
|
15 |
+
|
16 |
+
outputs = model.generate(input_ids=input_ids, attention_mask=attention_mask, max_new_tokens=200, pad_token_id=tokenizer.eos_token_id)
|
17 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
+
|
19 |
+
# Create a Gradio UI
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=generate_response,
|
22 |
+
inputs=gr.Textbox(label="Enter your prompt"),
|
23 |
+
outputs=gr.Textbox(label="Generated Response"),
|
24 |
+
title="DeepSeek Coder Chatbot",
|
25 |
+
description="A chatbot powered by DeepSeek Coder 1.3B"
|
26 |
+
)
|
27 |
+
|
28 |
+
iface.launch()
|