|
import gradio as gr |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
|
|
model_name = "meta-llama/LLaMA-3.2" |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
model = AutoModelForCausalLM.from_pretrained(model_name) |
|
|
|
|
|
def generate_text(prompt, max_length=100, temperature=0.7): |
|
inputs = tokenizer(prompt, return_tensors="pt") |
|
output = model.generate(inputs['input_ids'], max_length=max_length, temperature=temperature) |
|
return tokenizer.decode(output[0], skip_special_tokens=True) |
|
|
|
|
|
iface = gr.Interface( |
|
fn=generate_text, |
|
inputs=[ |
|
gr.inputs.Textbox(label="Enter your prompt", placeholder="Start typing..."), |
|
gr.inputs.Slider(minimum=50, maximum=200, default=100, label="Max Length"), |
|
gr.inputs.Slider(minimum=0.1, maximum=1.0, default=0.7, label="Temperature"), |
|
], |
|
outputs="text", |
|
title="LLaMA 3.2 Text Generator", |
|
description="Enter a prompt to generate text using the LLaMA 3.2 model.", |
|
theme="compact", |
|
) |
|
|
|
|
|
iface.launch() |
|
|