Spaces:
Runtime error
Runtime error
File size: 1,105 Bytes
3665715 041e5ac 668ba9a 041e5ac 668ba9a 041e5ac 3665715 668ba9a 3665715 668ba9a |
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 34 35 36 37 38 39 40 41 |
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() |