HarshitX's picture
Update README.md
8619eb9 verified

A newer version of the Gradio SDK is available: 6.5.1

Upgrade
metadata
license: mit
title: FaceDetectionwithGradio
sdk: gradio
emoji: πŸ‘€
colorFrom: indigo
colorTo: yellow
pinned: true
short_description: This project provides a web-based face detection application

Face Detection with Gradio - Phone Camera Access

This project provides a web-based face detection application optimized for accessing your phone's camera.

Features

  • Phone Camera Access: Direct camera access through web browser on mobile devices
  • Image Upload: Alternative option to upload existing images
  • Real-time Face Detection: Uses OpenCV's Haar Cascade Classifier
  • Mobile-Optimized UI: Responsive design that works great on phones
  • Easy Sharing: Can create shareable links to access from any device

Why Gradio?

Gradio is better for phone camera access because:

  • βœ… Works seamlessly with mobile browsers (Chrome, Safari)
  • βœ… Automatically requests camera permissions
  • βœ… No complex mobile configuration needed
  • βœ… Can create public shareable links
  • βœ… Responsive design out of the box

Setup Instructions

1. Activate the Virtual Environment

On Windows:

.camera\Scripts\activate

On Mac/Linux:

source .camera/bin/activate

2. Install Dependencies

pip install -r requirements.txt

This will install:

  • opencv-python (face detection)
  • pillow (image processing)
  • numpy (array operations)
  • gradio (web UI)

3. Run the Application

python ui.py

The app will:

  • Start a local web server (default: http://localhost:7860)
  • Automatically open in your browser
  • Display a URL you can access from your phone

Accessing from Your Phone

Option 1: Same WiFi Network (Recommended)

  1. Make sure your phone and computer are on the same WiFi network
  2. When you run python ui.py, look for the output that shows:
    Running on local URL:  http://127.0.0.1:7860
    Running on network URL: http://192.168.x.x:7860
    
  3. Open the network URL (192.168.x.x:7860) in your phone's browser
  4. Grant camera permissions when prompted

Option 2: Public Link (Easy sharing)

  1. Edit ui.py and change line 170:
    share=True,  # Create a public link
    
  2. Run the app - Gradio will create a temporary public URL
  3. Use this URL from any device, anywhere

Usage

Phone Camera Tab

  1. Click on "πŸ“± Phone Camera" tab
  2. Allow camera access when prompted
  3. Position your face in the camera view
  4. Click "πŸ” Detect Faces" button
  5. See the results with detected faces highlighted

Upload Image Tab

  1. Click on "πŸ“€ Upload Image" tab
  2. Choose an image from your phone's gallery
  3. Click "πŸ” Detect Faces" button
  4. View the detection results

Detection Parameters

The face detection uses these default parameters:

  • scaleFactor: 1.1 (image pyramid scale)
  • minNeighbors: 5 (quality threshold)
  • minSize: (30, 30) pixels (minimum face size)

Tips for Best Results

  • πŸ“Έ Ensure good lighting
  • πŸ‘€ Face the camera directly
  • πŸ“ Maintain a moderate distance (2-3 feet)
  • 🎯 Avoid extreme angles or face coverings
  • πŸ’‘ Use modern browsers (Chrome, Safari)

Troubleshooting

Camera not working on phone?

  • Make sure you granted camera permissions
  • Try Chrome or Safari browser
  • Check if other apps can access the camera
  • Reload the page and try again

Can't connect from phone?

  • Verify both devices are on the same WiFi
  • Check firewall settings on your computer
  • Try using the public link option (share=True)

Faces not detected?

  • Improve lighting conditions
  • Move closer/farther from camera
  • Ensure face is clearly visible and frontal
  • Remove sunglasses or face coverings

Files

Deactivating Environment

When done, deactivate the virtual environment:

deactivate