Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,59 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
if __name__ == "__main__":
|
| 9 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import yaml
|
| 4 |
+
import os
|
| 5 |
+
from tools.infer import main as run_inference
|
| 6 |
|
| 7 |
+
# Ruta base del modelo
|
| 8 |
+
MODEL_DIR = "./model_weights"
|
| 9 |
+
CONFIG_PATH = "./configs/voyager.yaml"
|
| 10 |
|
| 11 |
+
# Carga de configuración
|
| 12 |
+
if os.path.exists(CONFIG_PATH):
|
| 13 |
+
with open(CONFIG_PATH, "r") as f:
|
| 14 |
+
config = yaml.safe_load(f)
|
| 15 |
+
else:
|
| 16 |
+
config = {}
|
| 17 |
+
|
| 18 |
+
# Definir función de inferencia
|
| 19 |
+
def generate_scene(prompt, steps=20, seed=42):
|
| 20 |
+
"""
|
| 21 |
+
Genera una imagen o escena usando el modelo HunyuanWorld-Voyager.
|
| 22 |
+
"""
|
| 23 |
+
os.makedirs("outputs", exist_ok=True)
|
| 24 |
+
input_args = {
|
| 25 |
+
"config": CONFIG_PATH,
|
| 26 |
+
"ckpt": os.path.join(MODEL_DIR, "pytorch_model.bin"),
|
| 27 |
+
"prompt": prompt,
|
| 28 |
+
"steps": steps,
|
| 29 |
+
"seed": seed,
|
| 30 |
+
"out_dir": "outputs/"
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
# Ejecutar el script de inferencia del repo original
|
| 34 |
+
try:
|
| 35 |
+
run_inference(**input_args)
|
| 36 |
+
result_files = [f for f in os.listdir("outputs") if f.endswith((".png", ".jpg"))]
|
| 37 |
+
if result_files:
|
| 38 |
+
latest = os.path.join("outputs", result_files[-1])
|
| 39 |
+
return latest
|
| 40 |
+
else:
|
| 41 |
+
return "No se generó ninguna imagen."
|
| 42 |
+
except Exception as e:
|
| 43 |
+
return f"Error al generar: {str(e)}"
|
| 44 |
+
|
| 45 |
+
# Interfaz Gradio
|
| 46 |
+
demo = gr.Interface(
|
| 47 |
+
fn=generate_scene,
|
| 48 |
+
inputs=[
|
| 49 |
+
gr.Textbox(label="Prompt de escena o descripción"),
|
| 50 |
+
gr.Slider(1, 50, value=20, step=1, label="Steps de inferencia"),
|
| 51 |
+
gr.Number(value=42, label="Seed (aleatorio)")
|
| 52 |
+
],
|
| 53 |
+
outputs=gr.Image(label="Resultado"),
|
| 54 |
+
title="🎨 HunyuanWorld-Voyager — Tencent",
|
| 55 |
+
description="Generador de escenas 3D e imágenes a partir de texto usando el modelo HunyuanWorld-Voyager."
|
| 56 |
+
)
|
| 57 |
|
| 58 |
if __name__ == "__main__":
|
| 59 |
demo.launch()
|