windows / app.py
Gervacius's picture
Update app.py
fc6062c verified
raw
history blame
796 Bytes
from transformers import AutoModelForCausalLM, AutoTokenizer
import gradio as gr
# Load the model and tokenizer
model_name = "meta-llama/Llama-3.1-8B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
def predict(input_text):
# Tokenize input and generate text
inputs = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**inputs)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Create a Gradio interface
interface = gr.Interface(
fn=predict,
inputs=gr.Textbox(label="Input Text"),
outputs=gr.Textbox(label="Generated Output"),
title="Phi-4 Model",
description="Generate text using the microsoft/phi-4 model."
)
# Launch the interface
interface.launch()