Failed_Model / app.py
hacer201145's picture
Create app.py
097cb0f verified
raw
history blame contribute delete
678 Bytes
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
MODEL_NAME = "hacer201145/Failed_Model"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16, device_map="auto")
def chat(message, history):
input_text = message
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(**inputs, max_new_tokens=100, pad_token_id=tokenizer.eos_token_id)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response
iface = gr.ChatInterface(chat)
iface.launch()