Spaces:
Sleeping
Sleeping
File size: 1,920 Bytes
6181597 574567c 17bea6b d5324b6 17bea6b 6181597 17bea6b f91c1eb 6181597 f91c1eb 6181597 574567c 6181597 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct
# model_id = "deepseek-ai/deepseek-coder-1.3b-instruct"
model_id = "deepseek-ai/deepseek-coder-6.7b-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id) # Or your own!
model = AutoModelForCausalLM.from_pretrained(model_id,
# device_map=None,
# torch_dtype=torch.float32,
device_map="auto",
torch_dtype=torch.float16,
trust_remote_code=True)
# model.to("cpu")
def generate_code(prompt, style="Clean & Pythonic"):
if style == "Verbose like a 15th-century manuscript":
prompt = "In a manner most detailed, write code that... " + prompt
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs,
# max_new_tokens=100,
max_new_tokens=500,
do_sample=True,
temperature=1.0,
top_p=0.95,
# eos_token_id=tokenizer.eos_token_id
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
demo = gr.Interface(
fn=generate_code,
inputs=[
gr.Textbox(label="How shall Codice Da Vinci help today?", lines=3),
gr.Dropdown(["Clean & Pythonic", "Verbose like a 15th-century manuscript"], label="Code Style")
],
outputs=gr.Code(label="π§Ύ Leonardo's Work"),
title="Codice Da Vinci ππ»",
description="Your Renaissance coding assistant. Fluent in algorithms and Latin. Powered by LLM."
)
demo.launch()
|