Spaces:
Running on Zero
Running on Zero
Download app.py from ultrazcode/face-service: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/ultrazcode/face-service/resolve/main/app.py
- Command line
-
hf download hf://spaces/ultrazcode/face-service/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ultrazcode/face-service/resolve/main/app.py
1.15 kB
| """ | |
| Entrypoint untuk Hugging Face Spaces (SDK Gradio / ZeroGPU gratis). | |
| Space gratis hanya menyediakan ZeroGPU, yang mensyaratkan Gradio dijalankan lewat | |
| demo.launch() dan ada fungsi @spaces.GPU. Fungsi GPU itu tidak pernah dipanggil | |
| (kuota GPU tidak terpakai); ekstraksi wajah jalan di CPU lewat endpoint Gradio | |
| `extract`, yang dipanggil Laravel via /gradio_api/call/extract. | |
| """ | |
| import gradio as gr | |
| try: | |
| import spaces | |
| gpu = spaces.GPU | |
| except ImportError: # menjalankan di luar Hugging Face | |
| def gpu(fn): | |
| return fn | |
| from main import embed_from_url, key_ok | |
| def ping() -> str: | |
| return "ok" | |
| def extract(image_url: str, key: str) -> dict: | |
| if not key_ok(key): | |
| return {"error": "Face key tidak valid."} | |
| try: | |
| return {"embedding": embed_from_url(image_url)} | |
| except ValueError as e: | |
| return {"error": str(e)} | |
| with gr.Blocks(title="Face Embedding Service") as demo: | |
| gr.Markdown("Face Embedding Service - API: `extract`") | |
| gr.api(extract, api_name="extract") | |
| gr.api(ping, api_name="ping") | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) | |