Spaces:
Sleeping
Sleeping
| 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:** | |
| ```bash | |
| .camera\Scripts\activate | |
| ``` | |
| **On Mac/Linux:** | |
| ```bash | |
| source .camera/bin/activate | |
| ``` | |
| ### 2. Install Dependencies | |
| ```bash | |
| 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 | |
| ```bash | |
| 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](ui.py) and change line 170: | |
| ```python | |
| 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 | |
| - [ui.py](ui.py) - Main Gradio application | |
| - [main.py](main.py) - Original Streamlit version | |
| - [requirements.txt](requirements.txt) - Python dependencies | |
| ## Deactivating Environment | |
| When done, deactivate the virtual environment: | |
| ```bash | |
| deactivate | |
| ``` |