Download app.py from Mapakashi/glintgpt: direct link, hf CLI and curl.
- Browser
- Download file 9.67 kB
-
https://huggingface.co/spaces/Mapakashi/glintgpt/resolve/main/app.py
- Command line
-
hf download hf://spaces/Mapakashi/glintgpt/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Mapakashi/glintgpt/resolve/main/app.py
9.67 kB
| from fastai.vision.all import * | |
| import gradio as gr | |
| # Define makeup recommendations mapping | |
| makeup_recommendations = { | |
| 'Porcelain': { | |
| 'Foundation Shade': 'Porcelain', | |
| 'Lipstick Shade': 'Pink', | |
| 'Powder Shade': 'Ivory', | |
| 'Brands': { | |
| 'Foundation': 'Maybelline Fit Me - 110 Porcelain', | |
| 'Lipstick': 'MAC Lipstick - Creme Cup', | |
| 'Powder': 'Laura Mercier Translucent Setting Powder' | |
| } | |
| }, | |
| 'Ivory': { | |
| 'Foundation Shade': 'Ivory', | |
| 'Lipstick Shade': 'Nude Pink', | |
| 'Powder Shade': 'Fair', | |
| 'Brands': { | |
| 'Foundation': 'L\'Oréal True Match - W2 Light Ivory', | |
| 'Lipstick': 'Revlon Super Lustrous - Bare It All', | |
| 'Powder': 'Maybelline Fit Me Matte + Poreless Powder - Ivory' | |
| } | |
| }, | |
| 'Light Fair': { | |
| 'Foundation Shade': 'Light Fair', | |
| 'Lipstick Shade': 'Coral', | |
| 'Powder Shade': 'Natural', | |
| 'Brands': { | |
| 'Foundation': 'NYX Can\'t Stop Won\'t Stop - Light Fair', | |
| 'Lipstick': 'NYX Soft Matte Lip Cream - Antwerp', | |
| 'Powder': 'Rimmel Stay Matte Pressed Powder - Natural' | |
| } | |
| }, | |
| 'Fair': { | |
| 'Foundation Shade': 'Fair', | |
| 'Lipstick Shade': 'Peach', | |
| 'Powder Shade': 'Fair Beige', | |
| 'Brands': { | |
| 'Foundation': 'Fenty Beauty Pro Filt\'r Soft Matte - 120 Fair', | |
| 'Lipstick': 'NARS Lipstick - Niagara', | |
| 'Powder': 'Charlotte Tilbury Airbrush Flawless Finish - Fair' | |
| } | |
| }, | |
| 'Beige': { | |
| 'Foundation Shade': 'Beige', | |
| 'Lipstick Shade': 'Rose', | |
| 'Powder Shade': 'Medium Beige', | |
| 'Brands': { | |
| 'Foundation': 'Clinique Even Better - CN 28 Ivory', | |
| 'Lipstick': 'MAC Lipstick - Twig', | |
| 'Powder': 'MAC Studio Fix Powder Plus - C4 Medium Beige' | |
| } | |
| }, | |
| 'Sand': { | |
| 'Foundation Shade': 'Sand', | |
| 'Lipstick Shade': 'Nude', | |
| 'Powder Shade': 'Medium', | |
| 'Brands': { | |
| 'Foundation': 'NARS Natural Radiant Longwear - Vallauris', | |
| 'Lipstick': 'MAC Matte Lipstick - Honeylove', | |
| 'Powder': 'Bobbi Brown Sheer Finish Pressed Powder - Warm Natural' | |
| } | |
| }, | |
| 'Medium': { | |
| 'Foundation Shade': 'Medium', | |
| 'Lipstick Shade': 'Berry', | |
| 'Powder Shade': 'Tan', | |
| 'Brands': { | |
| 'Foundation': 'Maybelline Fit Me - 220 Natural Beige', | |
| 'Lipstick': 'Fenty Beauty Stunna Lip Paint - Uncensored', | |
| 'Powder': 'BareMinerals Original Loose Powder Foundation - Medium Tan' | |
| } | |
| }, | |
| 'Golden': { | |
| 'Foundation Shade': 'Golden', | |
| 'Lipstick Shade': 'Terracotta', | |
| 'Powder Shade': 'Golden', | |
| 'Brands': { | |
| 'Foundation': 'Estée Lauder Double Wear - 4W1 Honey Bronze', | |
| 'Lipstick': 'MAC Lipstick - Chili', | |
| 'Powder': 'Sephora MicroSmooth Baked Powder Foundation - Golden' | |
| } | |
| }, | |
| 'Almond': { | |
| 'Foundation Shade': 'Almond', | |
| 'Lipstick Shade': 'Red', | |
| 'Powder Shade': 'Golden Almond', | |
| 'Brands': { | |
| 'Foundation': 'Fenty Beauty Pro Filt\'r Soft Matte - 385', | |
| 'Lipstick': 'Huda Beauty Power Bullet - El Cinco De Mayo', | |
| 'Powder': 'Laura Mercier Loose Setting Powder - Translucent Medium Deep' | |
| } | |
| }, | |
| 'Honey': { | |
| 'Foundation Shade': 'Honey', | |
| 'Lipstick Shade': 'Plum', | |
| 'Powder Shade': 'Warm Honey', | |
| 'Brands': { | |
| 'Foundation': 'NARS Sheer Glow Foundation - Syracuse', | |
| 'Lipstick': 'NYX Soft Matte Lip Cream - Copenhagen', | |
| 'Powder': 'Maybelline Fit Me Matte + Poreless Powder - Toffee' | |
| } | |
| }, | |
| 'Caramel': { | |
| 'Foundation Shade': 'Caramel', | |
| 'Lipstick Shade': 'Mocha', | |
| 'Powder Shade': 'Warm Caramel', | |
| 'Brands': { | |
| 'Foundation': 'Bobbi Brown Skin Long-Wear Weightless Foundation - Golden Honey', | |
| 'Lipstick': 'MAC Lipstick - Paramount', | |
| 'Powder': 'Sephora Matte Perfection Powder Foundation - Mocha' | |
| } | |
| }, | |
| 'Bronze': { | |
| 'Foundation Shade': 'Bronze', | |
| 'Lipstick Shade': 'Brown', | |
| 'Powder Shade': 'Bronze', | |
| 'Brands': { | |
| 'Foundation': 'Fenty Beauty Pro Filt\'r Soft Matte - 420', | |
| 'Lipstick': 'Huda Beauty Power Bullet - Board Meeting', | |
| 'Powder': 'Urban Decay Naked Skin Ultra Definition Powder Foundation - Medium Dark' | |
| } | |
| }, | |
| 'Sienna': { | |
| 'Foundation Shade': 'Sienna', | |
| 'Lipstick Shade': 'Mahogany', | |
| 'Powder Shade': 'Deep Sienna', | |
| 'Brands': { | |
| 'Foundation': 'Estée Lauder Double Wear - 6W1 Sandalwood', | |
| 'Lipstick': 'MAC Lipstick - Sin', | |
| 'Powder': 'Laura Mercier Loose Setting Powder - Translucent Medium Deep' | |
| } | |
| }, | |
| 'Chestnut': { | |
| 'Foundation Shade': 'Chestnut', | |
| 'Lipstick Shade': 'Aubergine', | |
| 'Powder Shade': 'Chestnut Brown', | |
| 'Brands': { | |
| 'Foundation': 'Lancome Teint Idole Ultra Wear - 550 Suede C', | |
| 'Lipstick': 'Maybelline Color Sensational - Burgundy Blush', | |
| 'Powder': 'Fenty Beauty Pro Filt\'r Soft Matte Powder Foundation - 445' | |
| } | |
| }, | |
| 'Chocolate': { | |
| 'Foundation Shade': 'Chocolate', | |
| 'Lipstick Shade': 'Burgundy', | |
| 'Powder Shade': 'Dark Chocolate', | |
| 'Brands': { | |
| 'Foundation': 'MAC Studio Fix Fluid - NW58', | |
| 'Lipstick': 'Pat McGrath MatteTrance Lipstick - McMenamy', | |
| 'Powder': 'Fenty Beauty Pro Filt\'r Soft Matte Powder Foundation - 495' | |
| } | |
| }, | |
| 'Espresso': { | |
| 'Foundation Shade': 'Espresso', | |
| 'Lipstick Shade': 'Crimson', | |
| 'Powder Shade': 'Espresso Brown', | |
| 'Brands': { | |
| 'Foundation': 'NARS Natural Radiant Longwear - New Guinea', | |
| 'Lipstick': 'MAC Retro Matte Lipstick - Ruby Woo', | |
| 'Powder': 'NYX Can\'t Stop Won\'t Stop Powder Foundation - Deep Espresso' | |
| } | |
| }, | |
| 'Coffee': { | |
| 'Foundation Shade': 'Coffee', | |
| 'Lipstick Shade': 'Deep Red', | |
| 'Powder Shade': 'Coffee Brown', | |
| 'Brands': { | |
| 'Foundation': 'Fenty Beauty Pro Filt\'r Soft Matte - 490', | |
| 'Lipstick': 'Huda Beauty Liquid Matte Lipstick - Famous', | |
| 'Powder': 'Bobbi Brown Sheer Finish Loose Powder - Coffee' | |
| } | |
| }, | |
| 'Ebony': { | |
| 'Foundation Shade': 'Ebony', | |
| 'Lipstick Shade': 'Maroon', | |
| 'Powder Shade': 'Ebony', | |
| 'Brands': { | |
| 'Foundation': 'Fenty Beauty Pro Filt\'r Soft Matte - 498', | |
| 'Lipstick': 'MAC Lipstick - Diva', | |
| 'Powder': 'Sephora MicroSmooth Baked Powder Foundation - Ebony' | |
| } | |
| }, | |
| 'Black': { | |
| 'Foundation Shade': 'Black', | |
| 'Lipstick Shade': 'Dark Plum', | |
| 'Powder Shade': 'Deep Black', | |
| 'Brands': { | |
| 'Foundation': 'Black Opal True Color Pore Perfecting - Ebony Brown', | |
| 'Lipstick': 'MAC Lipstick - Smoked Purple', | |
| 'Powder': 'Fenty Beauty Pro Filt\'r Soft Matte Powder Foundation - 500' | |
| } | |
| } | |
| } | |
| # Function to get makeup recommendations | |
| def get_makeup_recommendation(skin_tone): | |
| if skin_tone in makeup_recommendations: | |
| return makeup_recommendations[skin_tone] | |
| return {'Foundation Shade': '', 'Lipstick Shade': '', 'Powder Shade': '', 'Brands': {}} | |
| # Load the trained model | |
| learn = load_learner('export.pkl') | |
| # Prediction and recommendation function | |
| def classify_and_recommend(img): | |
| pred, _, probs = learn.predict(img) | |
| result = {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))} | |
| top_pred = pred | |
| recommendation = get_makeup_recommendation(top_pred) | |
| return result, recommendation | |
| # Add a logo and a welcome message | |
| logo = "https://upload.wikimedia.org/wikipedia/commons/4/42/Makeup_Brushes.jpg" # Replace with your logo URL | |
| welcome_message = """ | |
| # Skin Tone Classification and Makeup Recommendations | |
| Upload an image to classify your skin tone and receive personalized makeup recommendations. Find the perfect foundation, lipstick, and powder shades from your favorite brands! | |
| """ | |
| # Gradio interface | |
| gr_interface = gr.Interface( | |
| fn=classify_and_recommend, | |
| inputs=gr.Image(type="pil", label="Upload Image"), | |
| outputs=[ | |
| gr.Label(num_top_classes=3, label='Classification Results'), | |
| gr.JSON(label='Makeup Recommendations') | |
| ], | |
| title="Skin Tone Classification and Makeup Recommendations", | |
| description="Upload an image to classify skin tone and receive personalized makeup recommendations.", | |
| article=welcome_message, | |
| theme="default", | |
| allow_flagging="never", | |
| css=""" | |
| body { | |
| background-color: #f3f3f3; | |
| margin: 0; | |
| padding: 0; | |
| } | |
| .gradio-container { | |
| background-color: #ffffff; | |
| border-radius: 15px; | |
| box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | |
| overflow: hidden; | |
| margin: 20px; | |
| } | |
| .gradio-container h1 { | |
| font-family: 'Arial', sans-serif; | |
| font-size: 28px; | |
| color: #333; | |
| margin-bottom: 10px; | |
| } | |
| .gradio-container h2 { | |
| font-family: 'Arial', sans-serif; | |
| font-size: 22px; | |
| color: #555; | |
| margin-bottom: 5px; | |
| } | |
| .gradio-container .block-markdown { | |
| margin: 10px 0; | |
| font-family: 'Arial', sans-serif; | |
| } | |
| """ | |
| ) | |
| if __name__ == "__main__": | |
| gr_interface.launch() | |