ukzada's picture
Update README.md
f7aec63 verified
|
Raw
History Blame Contribute Delete
3.53 kB

A newer version of the Gradio SDK is available: 6.20.0

Upgrade
metadata
title: HairStyle Recomendation
emoji: 🏃
colorFrom: pink
colorTo: indigo
sdk: gradio
sdk_version: 6.5.1
app_file: app.py
pinned: false

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

HairStyle Recommendation

A men's hairstyle recommendation system powered by OpenRouter API and Nvidia Nemotron vision model. Available as both a CLI tool and a Gradio web interface.

Features

  • Vision Analysis: Analyzes uploaded photos to recommend suitable hairstyles
  • Multiple Interfaces: CLI tool and modern Gradio web app
  • 10 Hairstyle Options: Buzz Cut, Crew Cut, Fade, Undercut, Slick Back, Side Part, Quiff, Pompadour, French Crop, Textured Fringe
  • Smart Extraction: Intelligently extracts recommendations from API responses

Setup

  1. Install dependencies:

ash pip install -r requirements.txt

CLI Usage (HairStyle.py)

Run the script with an image path:

ash python HairStyle.py --image "path/to/photo.jpg" --n 3

Arguments:

  • --image or -i: Path to image file
  • --n or -n: Number of recommendations (default: 1)

Output: JSON array of recommended hairstyle names

json ["Fade", "Undercut", "Crew Cut"]

Web App Usage (app.py)

Run the Gradio application:

ash python app.py

The Gradio interface will open at http://localhost:7860 and allows you to:

  • Upload images in multiple formats (.jpg, .jpeg, .png, .bmp)
  • Adjust number of recommendations with an interactive slider (1-10)
  • Get instant AI-powered hairstyle suggestions
  • View results in an easy-to-read format

Deploy to Hugging Face Spaces

  1. Create a new Space on Hugging Face

    • License: MIT
    • Select "Docker" OR "Gradio" as the Space SDK
  2. Upload these files to your Space repository: - pp.py

    equirements.txt

  3. The Space will automatically install dependencies and run the app

Note: The API key is embedded in the code. For production, use Hugging Face Secrets for secure storage.

Configuration

  • API Provider: OpenRouter (https://openrouter.ai)
  • Model: nvidia/nemotron-nano-12b-v2-vl:free
  • API Key: Already configured in the code (sk-or-v1-...)

How It Works

  1. Image Upload: Select a hair photo from your device
  2. Processing: The image is encoded and sent to the OpenRouter API with Nvidia Nemotron vision model
  3. Analysis: The AI analyzes the person's features and selects matching hairstyles
  4. Results: Returns 1-10 hairstyle recommendations based on your selection

Supported Image Formats

  • PNG (.png)
  • JPEG (.jpg, .jpeg)
  • BMP (.bmp)

API Response Handling

The app uses advanced extraction logic to:

  • Parse JSON arrays from API responses
  • Handle reasoning-based outputs
  • Extract hairstyle names from various text formats
  • Return accurate recommendations even with complex responses

Notes

  • The application uses a free OpenRouter model
  • Responses are optimized for hairstyle recommendations
  • Graceful error handling with informative messages
  • Debug logs available in terminal output

Troubleshooting

If you see "No valid recommendations found":

  1. Make sure the image contains a person's face
  2. Try a different image with better lighting
  3. Check your API key is valid
  4. Verify network connectivity to openrouter.ai

License

MIT

Files

  • pp.py - Gradio web interface
  • HairStyle.py - CLI tool
  • equirements.txt - Python dependencies
  • est_api.py - API testing utility
    
  • README.md - This documentation