| """ |
| Sima Face Shape API — Hugging Face Space |
| Loads metadome/face_shape_classification (ViT, ~85% accuracy on 5 classes) |
| and exposes a Gradio API endpoint that the Sima web app calls. |
| """ |
|
|
| import gradio as gr |
| from transformers import pipeline |
| from PIL import Image |
|
|
| |
| classifier = pipeline( |
| "image-classification", |
| model="metadome/face_shape_classification", |
| ) |
|
|
|
|
| def classify(image): |
| """Resmi alır, yüz tipi olasılıklarını döndürür. |
| Çıktı: {'Heart': 0.12, 'Oval': 0.71, ...} |
| """ |
| if image is None: |
| return {} |
| |
| if not isinstance(image, Image.Image): |
| image = Image.fromarray(image) |
| results = classifier(image) |
| return {r["label"]: float(r["score"]) for r in results} |
|
|
|
|
| demo = gr.Interface( |
| fn=classify, |
| inputs=gr.Image(type="pil", label="Yüz fotoğrafı"), |
| outputs=gr.Label(num_top_classes=5, label="Yüz tipi olasılıkları"), |
| title="Sîma — Yüz Tipi Sınıflandırması", |
| description=( |
| "ViT tabanlı yüz tipi sınıflandırıcısı. 5 sınıf: " |
| "Heart, Oblong, Oval, Round, Square. Sîma web uygulaması " |
| "bu Space'in API'sini çağırarak yüz tipi tahmini alır." |
| ), |
| api_name="classify", |
| allow_flagging="never", |
| ) |
|
|
|
|
| if __name__ == "__main__": |
| |
| demo.launch() |
|
|