Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
# URL de tu modelo en Hugging Face Spaces (ajústala si cambia)
|
| 5 |
MODEL_URL = "https://crisdeyvid-gema-ai-model.hf.space/predict"
|
| 6 |
|
| 7 |
def bridge_predict(features_text):
|
| 8 |
try:
|
| 9 |
-
# Limpiar y transformar el texto a lista de floats
|
| 10 |
features = [float(x.strip()) for x in features_text.split(",")]
|
| 11 |
except Exception as e:
|
| 12 |
-
return f"Error
|
| 13 |
-
|
| 14 |
-
# Preparar el JSON para el modelo
|
| 15 |
payload = {"features": features}
|
| 16 |
-
|
| 17 |
-
# Hacer POST al modelo
|
| 18 |
try:
|
| 19 |
resp = requests.post(MODEL_URL, json=payload, timeout=10)
|
| 20 |
result = resp.json()
|
|
@@ -22,30 +16,13 @@ def bridge_predict(features_text):
|
|
| 22 |
except Exception as e:
|
| 23 |
return f"Error al consultar modelo: {e}", ""
|
| 24 |
|
| 25 |
-
# Interfaz Gradio mínima solo para pruebas web (puedes ignorar si solo usas la API)
|
| 26 |
iface = gr.Interface(
|
| 27 |
fn=bridge_predict,
|
| 28 |
-
inputs=gr.Textbox(label="Features separados por coma
|
| 29 |
outputs=[gr.Textbox(label="Respuesta JSON"), gr.Textbox(label="Señal")],
|
| 30 |
-
title="
|
| 31 |
)
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
def predict_api(features_text: str = ""):
|
| 35 |
-
return bridge_predict(features_text)
|
| 36 |
|
| 37 |
-
app = gr.mount_gradio_app(iface, path="/")
|
| 38 |
-
|
| 39 |
-
# Para API REST:
|
| 40 |
-
import fastapi
|
| 41 |
-
api = fastapi.FastAPI()
|
| 42 |
-
|
| 43 |
-
@api.post("/predict")
|
| 44 |
-
async def predict_post(data: dict):
|
| 45 |
-
features_text = data.get("features_text", "")
|
| 46 |
-
result, _ = bridge_predict(features_text)
|
| 47 |
-
return {"result": result}
|
| 48 |
-
|
| 49 |
-
# Llama a ambos: Gradio para pruebas visuales y API para peticiones
|
| 50 |
-
app = gr.mount_gradio_app(api, app, path="/api")
|
| 51 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
|
|
|
| 4 |
MODEL_URL = "https://crisdeyvid-gema-ai-model.hf.space/predict"
|
| 5 |
|
| 6 |
def bridge_predict(features_text):
|
| 7 |
try:
|
|
|
|
| 8 |
features = [float(x.strip()) for x in features_text.split(",")]
|
| 9 |
except Exception as e:
|
| 10 |
+
return f"Error: {e}", ""
|
|
|
|
|
|
|
| 11 |
payload = {"features": features}
|
|
|
|
|
|
|
| 12 |
try:
|
| 13 |
resp = requests.post(MODEL_URL, json=payload, timeout=10)
|
| 14 |
result = resp.json()
|
|
|
|
| 16 |
except Exception as e:
|
| 17 |
return f"Error al consultar modelo: {e}", ""
|
| 18 |
|
|
|
|
| 19 |
iface = gr.Interface(
|
| 20 |
fn=bridge_predict,
|
| 21 |
+
inputs=gr.Textbox(label="Features separados por coma"),
|
| 22 |
outputs=[gr.Textbox(label="Respuesta JSON"), gr.Textbox(label="Señal")],
|
| 23 |
+
title="Bridge - Puente hacia el Modelo IA"
|
| 24 |
)
|
| 25 |
|
| 26 |
+
iface.launch() # <--- SOLO ESTO al final
|
|
|
|
|
|
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|