File size: 993 Bytes
7a047e7
2998bd1
7a047e7
2998bd1
902a9ef
2998bd1
902a9ef
 
2998bd1
 
 
7a047e7
 
 
2998bd1
 
7a047e7
 
 
 
 
2998bd1
902a9ef
7a047e7
 
 
 
 
 
 
2998bd1
7a047e7
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
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()