Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig | |
import torch | |
# Configuração da quantização | |
quantization_config = BitsAndBytesConfig( | |
load_in_4bit=True, # ou use True para 4-bit | |
bnb_4bit_compute_dtype=torch.float16, | |
bnb_4bit_use_double_quant=True, | |
bnb_4bit_quant_type="nf4" | |
) | |
# Inicializa o modelo e tokenizer | |
model_name = "Orenguteng/Llama-3-8B-Lexi-Uncensored" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained( | |
model_name, | |
torch_dtype=torch.float16, | |
device_map="auto", | |
quantization_config=quantization_config | |
) | |
def generate_text(prompt): | |
inputs = tokenizer(prompt, return_tensors="pt") | |
outputs = model.generate( | |
inputs["input_ids"], | |
max_new_tokens=100, | |
temperature=0.7, | |
pad_token_id=tokenizer.eos_token_id | |
) | |
return tokenizer.decode(outputs[0], skip_special_tokens=True) | |
# Cria a interface | |
iface = gr.Interface( | |
fn=generate_text, | |
inputs="text", | |
outputs="text", | |
title="LLama Chat" | |
) | |
iface.launch() |