ApiEndPointDemo / app.py
Gajendra5490's picture
Update app.py
902a9ef verified
raw
history blame
993 Bytes
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Model name
model_name = "MONAI/Llama3-VILA-M3-8B"
# Load tokenizer and model with trust_remote_code=True
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map="auto",
trust_remote_code=True
)
def generate_response(prompt):
inputs = tokenizer(prompt, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
with torch.no_grad():
output = model.generate(**inputs, max_length=200)
return tokenizer.decode(output[0], skip_special_tokens=True)
# Gradio Interface
iface = gr.Interface(
fn=generate_response,
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt..."),
outputs="text",
title="MONAI Llama3-VILA-M3-8B Chatbot",
description="A chatbot powered by MONAI/Llama3-VILA-M3-8B",
)
iface.launch()