Spaces:
Sleeping
Sleeping
Download app.py from alezsd/clasificacion-api: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/alezsd/clasificacion-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/alezsd/clasificacion-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/alezsd/clasificacion-api/resolve/main/app.py
1.3 kB
| #!/usr/bin/env python3 | |
| # 🔧 FIX asyncio warnings HF Spaces | |
| import asyncio | |
| def patched_del(self): | |
| try: self._close() | |
| except: pass | |
| try: | |
| asyncio.base_events.BaseEventLoop.__del__ = patched_del | |
| except: pass | |
| import gradio as gr | |
| from predictor import CaligrafiaPredictor | |
| predictor = CaligrafiaPredictor("best_caligrafia_model.pth") | |
| def predict_image(img): | |
| resultado = predictor.predict(img) # ← Gradio pasa PIL.Image | |
| if "error" in resultado: | |
| return resultado["error"] | |
| return f" **{resultado['caligrafia']}** ({resultado['confidence']:.1%}) Probs: {resultado['probs']}" | |
| # Interfaz Gradio | |
| #demo = gr.Interface( | |
| # fn=predict_image, | |
| # inputs=gr.Image(type="pil"), # ← type="pil" = PIL.Image object | |
| # outputs=gr.Textbox(label="Predicción"), | |
| # title="🖋️ Clasificador Caligrafía CRNN", | |
| # examples=None # Agrega ejemplos después | |
| #) | |
| demo = gr.Interface( | |
| fn=predict_image, # Tu función que espera image_path (str) | |
| inputs=gr.Image( | |
| type="filepath", # ← DEVUELVE RUTA ARCHIVO (string) | |
| image_mode="RGB", # ← Fuerza RGB exacto | |
| label="🖼️ Imagen" | |
| ), | |
| outputs=gr.Textbox(label="Predicción"), | |
| title="🖋️ Clasificador Caligrafía CRNN" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |