Spaces:
Sleeping
Sleeping
File size: 8,912 Bytes
3494365 59844f8 fa3e9fe cae98ae fa3e9fe 3494365 fa3e9fe 59844f8 72fcc88 59844f8 3d3f535 152d4ee 3d3f535 59844f8 6234614 59844f8 152d4ee 59844f8 152d4ee 59844f8 152d4ee 59844f8 152d4ee 59844f8 6234614 59844f8 6234614 59844f8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
---
title: Computer Vision Playground
emoji: 🦀
colorFrom: indigo
colorTo: blue
sdk: streamlit
sdk_version: 1.36.0
app_file: app.py
pinned: false
license: mit
---
# Computer Vision Playground
This Streamlit application streams video from the webcam, analyzes facial sentiment, and displays the results in real-time. It serves as a playground for computer vision projects, with an example facial sentiment analysis demo.
For how to embed this space into an existing webpage see the example [index.html](https://huggingface.co/spaces/eusholli/sentiment-analyzer/blob/main/index.html) page.
For further instructions and guidance from Hugging Face see [here](https://huggingface.co/docs/hub/en/spaces-embed)
## How to Use
1. Clone the repository.
2. Ensure you have the necessary packages installed: `pip install -r requirements.txt`
3. Run the application: `streamlit run app.py`
## Create Your Own Analysis Space
Follow these steps to set up and modify the application for your own image analysis:
### Step 1: Clone the Repository
First, you need to clone the repository to your local machine. Open your terminal or command prompt and run:
```sh
git clone https://huggingface.co/spaces/eusholli/computer-vision-playground
cd computer-vision-playground
```
### Step 2: Install Dependencies
Make sure you have Python installed on your machine. You can download it from [python.org](https://www.python.org/).
Next, install the required packages. In the terminal, navigate to the cloned repository directory and run:
```sh
pip install -r requirements.txt
```
This will install all the necessary libraries specified in the \`requirements.txt\` file.
### Step 3: Run the Application
To start the Streamlit application, run:
```sh
streamlit run app.py
```
This will open a new tab in your default web browser with the Streamlit interface.
## Using the Application
#### Webcam Stream
- Allow access to your webcam when prompted.
- You will see the live stream from your webcam in the "Input Stream" section.
- The application will analyze the video frames in real-time and display the sentiment results in the "Analysis" section.
#### Uploading Images
- In the "Input Stream" section, under "Upload an Image", click on the "Choose an image..." button.
- Select an image file (jpg, jpeg, png) from your computer.
- The application will analyze the uploaded image and display the analysis results.
#### Image URL
- In the "Input Stream" section, under "Or Enter Image URL", paste an image URL and press Enter.
- The application will download and analyze the image from the provided URL and display the analysis results.
#### YouTube URL
- In the "Youtube URL" section, under "Enter a YouTube URL", paste a YouTube URL and press Enter.
- The application will stream and analyze the video directly from YouTube and display the analysis results.
#### Uploading Videos
- In the "Input Stream" section, under "Upload a Video", click on the "Choose a video..." button.
- Select a video file (mp4, avi, mov, mkv) from your computer.
- The application will analyze the video frames and display the analysis results.
#### Video URL
- In the "Input Stream" section, under "Or Enter Video Download URL", paste a video URL and press Enter.
- The application will download and analyze the video from the provided URL and display the analysis results.
## Customize the Analysis
You can customize the analysis function to perform your own image analysis. The default function \`analyze_frame\` performs facial sentiment analysis. To use your own analysis:
1. Replace the contents of the \`analyze_frame\` function in \`app.py\` with your custom analysis code.
2. Update any necessary imports at the top of the \`app.py\` file.
3. Adjust the \`ANALYSIS_TITLE\` variable to reflect your custom analysis.
Example:
```python
ANALYSIS_TITLE = "Custom Analysis"
def analyze_frame(frame: np.ndarray):
# Your custom analysis code here
...
```
### Troubleshooting
If you encounter any issues:
- Ensure all dependencies are correctly installed.
- Check that your webcam is working and accessible.
- Verify the URLs you provide are correct and accessible.
For more detailed information, refer to the comments in the \`app.py\` file.
### Debugging using Vscode
If you are using Vscode as your IDE you can use the following launch.json file to debug the current file (e.g. app.py) in your editor.
```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python:Streamlit",
"type": "debugpy",
"request": "launch",
"module": "streamlit",
"args": [
"run",
"${file}",
"--server.port",
"2000"
]
}
]
}
```
# How to Create a New Huggingface Space and Push Code to It
## Step 1: Create a New Huggingface Space
1. Log in to your [Huggingface](https://huggingface.co/) account.
2. Go to the [Spaces](https://huggingface.co/spaces) section.
3. Click on the **Create new Space** button.
4. Fill in the details for your new Space:
- **Space name**: Choose a unique name for your Space.
- **Owner**: Ensure your username is selected.
- **Visibility**: Choose between Public or Private based on your preference.
- **SDK**: Select the SDK you will use (in this case`streamlit`).
5. Click on the **Create Space** button to create your new Space.
## Step 2: Change the Local Git Remote Repo Reference
1. Open your terminal or command prompt.
2. Navigate to your local project directory:
```bash
cd /path/to/your/project
```
3. Remove the existing remote reference (if any):
```bash
git remote remove origin
```
4. Add the new remote reference pointing to your newly created Huggingface Space. Replace `<your-username>` and `<your-space-name>` with your actual Huggingface username and Space name:
```bash
git remote add origin https://huggingface.co/spaces/<your-username>/<your-space-name>.git
```
## Step 3: Add, Commit, and Push the Code to the New Space
1. Stage all the changes in your local project directory:
```bash
git add .
```
2. Commit the changes with a meaningful commit message:
```bash
git commit -m "Initial commit to Huggingface Space"
```
3. Push the changes to the new Huggingface Space:
```bash
git push origin main
```
> **Note**: If your default branch is not `main`, replace `main` with the appropriate branch name in the push command.
## Conclusion
You have now successfully created a new Huggingface Space, updated your local Git remote reference, and pushed your code to the new Space. You can verify that your code has been uploaded by visiting your Huggingface Space's URL.
## Webcam STUN/TURN Server
When running remotely on Huggingface, the code needs to access your remote webcam. It does this using the [streamlit-webrtc](https://github.com/whitphx/streamlit-webrtc) module but requires a Twilio account to be established and the credentials uploaded to the Huggingface space.
### How to Create a Free Twilio Account and Add Credentials to Huggingface Space Settings
#### Step 1: Create a Free Twilio Account
1. Go to the [Twilio Sign-Up Page](https://www.twilio.com/try-twilio).
2. Fill in your details to create a new account.
3. Verify your email address and phone number.
4. After verification, log in to your Twilio dashboard.
#### Step 2: Obtain `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN`
1. In the Twilio dashboard, navigate to the **Console**.
2. Look for the **Account Info** section on the dashboard.
3. Here, you will find your `Account SID` (referred to as `TWILIO_ACCOUNT_SID`).
4. To obtain your `Auth Token` (referred to as `TWILIO_AUTH_TOKEN`), click on the **Show** button next to the `Auth Token`.
#### Step 3: Add Twilio Credentials to Huggingface Space Settings
1. Log in to your [Huggingface](https://huggingface.co/) account.
2. Navigate to your Huggingface Space where you need to add the credentials.
3. Go to the **Settings** of your Space.
4. In the **Variables and secrets** section:
- Click on the **New variable** button to add `TWILIO_ACCOUNT_SID`:
- Name: `TWILIO_ACCOUNT_SID`
- Value: Copy your `Account SID` from the Twilio dashboard and paste it here.
- Click on the **New secret** button to add `TWILIO_AUTH_TOKEN`:
- Name: `TWILIO_AUTH_TOKEN`
- Value: Copy your `Auth Token` from the Twilio dashboard and paste it here.
5. Save the changes.
You have now successfully added your Twilio credentials to the Huggingface Space settings. Your application should now be able to access and use the Twilio API for WebRTC functionality.
### Contributing
We welcome contributions! If you have suggestions or improvements, feel free to open an issue or submit a pull request.
### License
This project is licensed under the MIT License.
|