File size: 1,091 Bytes
251623f
cf47d83
251623f
85ec4d4
 
 
 
251623f
c51c637
251623f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import AutoModelForCausalLM, AutoTokenizer
import streamlit as st

# Token Secret of Hugging Face
huggingface_token = st.secrets["HUGGINGFACEHUB_API_TOKEN"]
login(huggingface_token)

# Cargar el modelo y el tokenizer
model_name = "meta-llama/Llama-3.2-1B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Texto de entrada para la generación
input_text = "Tu texto aquí"
input_ids = tokenizer.encode(input_text, return_tensors='pt')

# Generación de texto con temperatura
outputs = model.generate(
    input_ids, 
    max_length=100,       # Longitud máxima del texto generado
    temperature=0.7,      # Ajustar la temperatura aquí
    top_k=50,             # Ajuste opcional para limitar las opciones de palabras
    top_p=0.9,            # Ajuste opcional para el muestreo por núcleo
    do_sample=True        # Habilitar el muestreo para aplicar la temperatura
)

# Decodificar el texto generado
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_text)