Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# La ruta al modelo ahora apunta a tu repositorio en Hugging Face Hub
|
6 |
+
model_path = "TaraxaPulse/asciiartgenerator"
|
7 |
+
|
8 |
+
# Carga el tokenizador y el modelo preentrenados
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(model_path)
|
11 |
+
|
12 |
+
def generate_ascii_art(prompt):
|
13 |
+
"""
|
14 |
+
Genera arte ASCII a partir de un prompt de texto.
|
15 |
+
"""
|
16 |
+
if not prompt:
|
17 |
+
return "Por favor, introduce un prompt de texto."
|
18 |
+
|
19 |
+
try:
|
20 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
21 |
+
outputs = model.generate(
|
22 |
+
**inputs,
|
23 |
+
max_length=200,
|
24 |
+
do_sample=True,
|
25 |
+
top_k=50,
|
26 |
+
top_p=0.95,
|
27 |
+
temperature=0.7,
|
28 |
+
num_return_sequences=1
|
29 |
+
)
|
30 |
+
ascii_art = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
31 |
+
return ascii_art
|
32 |
+
|
33 |
+
except Exception as e:
|
34 |
+
return f"Error al generar el arte ASCII: {e}"
|
35 |
+
|
36 |
+
demo = gr.Interface(
|
37 |
+
fn=generate_ascii_art,
|
38 |
+
inputs=gr.Text(label="Prompt"),
|
39 |
+
outputs=gr.Text(label="ASCII Art"),
|
40 |
+
title="Generador de ASCII Art para Taraxa Pulse",
|
41 |
+
description="Escribe un prompt de texto para generar arte ASCII con tu propio modelo."
|
42 |
+
)
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
demo.launch()
|