Spaces:
Runtime error
Runtime error
File size: 1,250 Bytes
3665715 95d1255 668ba9a 95d1255 668ba9a 95d1255 3665715 668ba9a 95d1255 668ba9a 95d1255 668ba9a 95d1255 668ba9a 95d1255 668ba9a 95d1255 668ba9a 3665715 95d1255 |
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 42 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Inicializa o modelo e tokenizer
model_name = "Orenguteng/Llama-3-8B-Lexi-Uncensored"
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Carregando em CPU com precisΓ£o reduzida
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
low_cpu_mem_usage=True,
device_map="cpu"
)
def generate_text(prompt):
inputs = tokenizer(prompt, return_tensors="pt")
# Ajustando parΓ’metros para economizar memΓ³ria
outputs = model.generate(
inputs["input_ids"],
max_new_tokens=50, # Reduzido para economizar memΓ³ria
temperature=0.7,
pad_token_id=tokenizer.eos_token_id,
num_beams=1, # Beam search simples para economizar memΓ³ria
do_sample=True
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Cria a interface com tempo limite maior
iface = gr.Interface(
fn=generate_text,
inputs="text",
outputs="text",
title="LLama Chat",
examples=["Hello, how are you?"],
cache_examples=False,
)
# Aumentando o tempo limite devido ao processamento mais lento em CPU
iface.launch(share=True, server_timeout=180) |