Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.8.0
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
|
| 2 |
---
|
| 3 |
+
title: webcam_constraints
|
| 4 |
+
emoji: 🔥
|
| 5 |
+
colorFrom: indigo
|
| 6 |
+
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
sdk_version: 5.8.0
|
| 9 |
+
app_file: run.py
|
| 10 |
pinned: false
|
| 11 |
+
hf_oauth: true
|
| 12 |
---
|
|
|
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
opencv-python
|
run.ipynb
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: webcam_constraints"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio opencv-python"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import cv2\n", "\n", "def get_video_shape(video):\n", " cap = cv2.VideoCapture(video)\n", " width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))\n", " height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))\n", " cap.release()\n", " return {\"width\": width, \"height\": height}\n", "\n", "def image_mod(image):\n", " width, height = image.size\n", " return {\"width\": width, \"height\": height}\n", "\n", "\n", "video = gr.Interface(\n", " fn=get_video_shape,\n", " inputs=gr.Video(webcam_constraints={\"video\": {\"width\": 800, \"height\": 600}}, sources=\"webcam\"),\n", " outputs=gr.JSON()\n", ")\n", "\n", "image = gr.Interface(\n", " image_mod,\n", " gr.Image(type=\"pil\", webcam_constraints={\"video\": {\"width\": 800, \"height\": 600}}, sources=\"webcam\"),\n", " gr.Json())\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"\"\"# Webcam Constraints\n", " The webcam constraints are set to 800x600 with the following syntax:\n", " ```python\n", " gr.Video(webcam_constraints={\"video\": {\"width\": 800, \"height\": 600}}, sources=\"webcam\")\n", " ```\n", " \"\"\")\n", " with gr.Tabs():\n", " with gr.Tab(\"Video\"):\n", " video.render()\n", " with gr.Tab(\"Image\"):\n", " image.render()\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
|
| 4 |
+
def get_video_shape(video):
|
| 5 |
+
cap = cv2.VideoCapture(video)
|
| 6 |
+
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 7 |
+
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 8 |
+
cap.release()
|
| 9 |
+
return {"width": width, "height": height}
|
| 10 |
+
|
| 11 |
+
def image_mod(image):
|
| 12 |
+
width, height = image.size
|
| 13 |
+
return {"width": width, "height": height}
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
video = gr.Interface(
|
| 17 |
+
fn=get_video_shape,
|
| 18 |
+
inputs=gr.Video(webcam_constraints={"video": {"width": 800, "height": 600}}, sources="webcam"),
|
| 19 |
+
outputs=gr.JSON()
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
image = gr.Interface(
|
| 23 |
+
image_mod,
|
| 24 |
+
gr.Image(type="pil", webcam_constraints={"video": {"width": 800, "height": 600}}, sources="webcam"),
|
| 25 |
+
gr.Json())
|
| 26 |
+
|
| 27 |
+
with gr.Blocks() as demo:
|
| 28 |
+
gr.Markdown("""# Webcam Constraints
|
| 29 |
+
The webcam constraints are set to 800x600 with the following syntax:
|
| 30 |
+
```python
|
| 31 |
+
gr.Video(webcam_constraints={"video": {"width": 800, "height": 600}}, sources="webcam")
|
| 32 |
+
```
|
| 33 |
+
""")
|
| 34 |
+
with gr.Tabs():
|
| 35 |
+
with gr.Tab("Video"):
|
| 36 |
+
video.render()
|
| 37 |
+
with gr.Tab("Image"):
|
| 38 |
+
image.render()
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
demo.launch()
|