Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available:
6.5.1
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)
- Make sure your phone and computer are on the same WiFi network
- 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 - Open the network URL (192.168.x.x:7860) in your phone's browser
- Grant camera permissions when prompted
Option 2: Public Link (Easy sharing)
- Edit ui.py and change line 170:
share=True, # Create a public link - Run the app - Gradio will create a temporary public URL
- Use this URL from any device, anywhere
Usage
Phone Camera Tab
- Click on "π± Phone Camera" tab
- Allow camera access when prompted
- Position your face in the camera view
- Click "π Detect Faces" button
- See the results with detected faces highlighted
Upload Image Tab
- Click on "π€ Upload Image" tab
- Choose an image from your phone's gallery
- Click "π Detect Faces" button
- 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
- ui.py - Main Gradio application
- main.py - Original Streamlit version
- requirements.txt - Python dependencies
Deactivating Environment
When done, deactivate the virtual environment:
deactivate