CoolFace
Apppublic

asad2662/face-type-classifier

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py39 linesDownload Raw Back to root
1import gradio as gr2from inference import predict3 4 5def gradio_predict(image):6    # Gradio gives you a PIL Image, so convert to bytes7    import io8 9    buf = io.BytesIO()10    image.save(buf, format="PNG")11    image_bytes = buf.getvalue()12 13    result = predict(image_bytes)14 15    if "error" in result:16        return f"โŒ Error: {result['error']}", None, None17 18    face_type = result["face_type"]19    confidence = f"{result['confidence']}%"20    glasses = ", ".join(result["suggested_glasses"])21    return face_type, confidence, glasses22 23 24demo = gr.Interface(25    fn=gradio_predict,26    inputs=gr.Image(type="pil", label="Upload Face Image"),27    outputs=[28        gr.Textbox(label="Predicted Face Type"),29        gr.Textbox(label="Confidence"),30        gr.Textbox(label="Suggested Sunglasses"),31    ],32    title="Face Type Classifier + Sunglasses Recommender ๐Ÿ˜Ž",33    description="Upload an image and get face type + sunglasses recommendations using MobileNetV2.",34)35 36 37if __name__ == "__main__":38    demo.launch(server_name="0.0.0.0", server_port=7860, share=True)39