bosha-ai / app.py
Bosha25's picture
Update app.py
fbd5b13 verified
raw
history blame contribute delete
702 Bytes
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "Qwen/Qwen2.5-Coder-1.5B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map="auto",
torch_dtype="auto"
)
def chat_fn(message, history):
inputs = tokenizer.apply_chat_template(
history + [{"role": "user", "content": message}],
return_tensors="pt"
).to(model.device)
outputs = model.generate(inputs, max_new_tokens=350)
reply = tokenizer.decode(outputs[0], skip_special_tokens=True)
return reply
iface = gr.ChatInterface(fn=chat_fn, title="AI Coder Chatbot")
iface.launch()