Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load the model
|
| 6 |
+
model_id = "deepseek-ai/deepseek-coder-1.3b-base"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
model_id,
|
| 10 |
+
torch_dtype=torch.float16,
|
| 11 |
+
device_map="auto"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
def generate_code(prompt):
|
| 15 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.cuda()
|
| 16 |
+
outputs = model.generate(input_ids, max_new_tokens=300)
|
| 17 |
+
code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
+
return code
|
| 19 |
+
|
| 20 |
+
gr.Interface(
|
| 21 |
+
fn=generate_code,
|
| 22 |
+
inputs=gr.Textbox(lines=4, label="Describe what code you want"),
|
| 23 |
+
outputs=gr.Code(label="Generated Code"),
|
| 24 |
+
title="Text to Code Generator",
|
| 25 |
+
description="Describe what you want in natural language, and get code!"
|
| 26 |
+
).launch()
|