Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import traceback
|
| 3 |
import gradio as gr
|
| 4 |
-
from gradio_client import Client
|
| 5 |
|
| 6 |
def fusionar_cosplay_bridge(imagen_real, imagen_ref):
|
| 7 |
hf_token = os.getenv("HF_TOKEN")
|
|
@@ -10,7 +10,7 @@ def fusionar_cosplay_bridge(imagen_real, imagen_ref):
|
|
| 10 |
raise gr.Error("Falta el token HF_TOKEN en el servidor.")
|
| 11 |
|
| 12 |
try:
|
| 13 |
-
print("[+] Petición recibida desde Android. Conectando al clúster...")
|
| 14 |
hf_client = Client("joyfox/Qwen-Image-Edit-Cosplay", token=hf_token)
|
| 15 |
|
| 16 |
# Aseguramos los prefijos Data URI limpios
|
|
@@ -19,15 +19,20 @@ def fusionar_cosplay_bridge(imagen_real, imagen_ref):
|
|
| 19 |
|
| 20 |
prompt_texto = "把图2中动漫人物中的发型,服饰和装扮道具迁移到图1的真实人物,图1真实人物保持高度人脸一致性"
|
| 21 |
|
| 22 |
-
print("[+]
|
| 23 |
|
| 24 |
-
# 🌟
|
| 25 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
resultado = hf_client.predict(
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
prompt_texto, #
|
| 30 |
-
fn_index=0
|
| 31 |
)
|
| 32 |
|
| 33 |
print("[+] Fusión completada con éxito.")
|
|
@@ -39,7 +44,7 @@ def fusionar_cosplay_bridge(imagen_real, imagen_ref):
|
|
| 39 |
print("=====================================================\n")
|
| 40 |
raise gr.Error(f"Crash interno en el cliente del modelo: {str(e)}")
|
| 41 |
|
| 42 |
-
# Mapeamos la interfaz
|
| 43 |
demo = gr.Interface(
|
| 44 |
fn=fusionar_cosplay_bridge,
|
| 45 |
inputs=[gr.Textbox(label="Real"), gr.Textbox(label="Ref")],
|
|
|
|
| 1 |
import os
|
| 2 |
import traceback
|
| 3 |
import gradio as gr
|
| 4 |
+
from gradio_client import Client, handle_file
|
| 5 |
|
| 6 |
def fusionar_cosplay_bridge(imagen_real, imagen_ref):
|
| 7 |
hf_token = os.getenv("HF_TOKEN")
|
|
|
|
| 10 |
raise gr.Error("Falta el token HF_TOKEN en el servidor.")
|
| 11 |
|
| 12 |
try:
|
| 13 |
+
print("[+] Petición recibida desde Android. Conectando al clúster de Qwen...")
|
| 14 |
hf_client = Client("joyfox/Qwen-Image-Edit-Cosplay", token=hf_token)
|
| 15 |
|
| 16 |
# Aseguramos los prefijos Data URI limpios
|
|
|
|
| 19 |
|
| 20 |
prompt_texto = "把图2中动漫人物中的发型,服饰和装扮道具迁移到图1的真实人物,图1真实人物保持高度人脸一致性"
|
| 21 |
|
| 22 |
+
print("[+] Empaquetando strings Base64 con el formateador de archivos nativo de Gradio 6...")
|
| 23 |
|
| 24 |
+
# 🌟 LA SOLUCIÓN DEFINITIVA:
|
| 25 |
+
# Usamos handle_file para envolver el string Base64 en el objeto JSON estructurado que gr.Image
|
| 26 |
+
# espera recibir, evitando el fallo de decodificación y mapeo del endpoint.
|
| 27 |
+
input_real = handle_file(data_uri_real)
|
| 28 |
+
input_ref = handle_file(data_uri_ref)
|
| 29 |
+
|
| 30 |
+
print("[+] Ejecutando inferencia en el pipeline (fn_index=0)...")
|
| 31 |
resultado = hf_client.predict(
|
| 32 |
+
input_real, # Imagen Real (gr.Image estructurada)
|
| 33 |
+
input_ref, # Imagen Referencia (gr.Image estructurada)
|
| 34 |
+
prompt_texto, # Texto Prompt (gr.Textbox)
|
| 35 |
+
fn_index=0
|
| 36 |
)
|
| 37 |
|
| 38 |
print("[+] Fusión completada con éxito.")
|
|
|
|
| 44 |
print("=====================================================\n")
|
| 45 |
raise gr.Error(f"Crash interno en el cliente del modelo: {str(e)}")
|
| 46 |
|
| 47 |
+
# Mapeamos la interfaz universal para Android
|
| 48 |
demo = gr.Interface(
|
| 49 |
fn=fusionar_cosplay_bridge,
|
| 50 |
inputs=[gr.Textbox(label="Real"), gr.Textbox(label="Ref")],
|