|
import os |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
import gradio as gr |
|
|
|
|
|
hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN") |
|
|
|
|
|
model_name = "meta-llama/Llama-3.2-3B-Instruct" |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_token) |
|
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=hf_token) |
|
|
|
def predict(input_text): |
|
|
|
inputs = tokenizer(input_text, return_tensors="pt") |
|
outputs = model.generate(**inputs) |
|
return tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict, |
|
inputs=gr.Textbox(label="Input Text"), |
|
outputs=gr.Textbox(label="Generated Output"), |
|
title="Meta-LLaMA-3.1-8B-Instruct", |
|
description="Generate text using the meta-llama/Llama-3.1-8B-Instruct model." |
|
) |
|
|
|
|
|
interface.launch() |