Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
|
|
3 |
import time
|
4 |
from PIL import Image
|
5 |
# Images
|
@@ -7,6 +8,9 @@ torch.hub.download_url_to_file('https://cdn.pixabay.com/photo/2016/06/15/01/11/s
|
|
7 |
torch.hub.download_url_to_file('https://cdn.pixabay.com/photo/2016/11/21/14/31/vw-bus-1845719_1280.jpg', 'bus.jpg')
|
8 |
# Model
|
9 |
model = torch.hub.load('ultralytics/yolov3', 'yolov3') # or yolov3-spp, yolov3-tiny, custom
|
|
|
|
|
|
|
10 |
def yolo(im, size=640):
|
11 |
g = (size / max(im.size)) # gain
|
12 |
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
@@ -14,13 +18,14 @@ def yolo(im, size=640):
|
|
14 |
results.render() # updates results.imgs with boxes and labels
|
15 |
return Image.fromarray(results.imgs[0])
|
16 |
#inputs = gr.inputs.Image(type='pil', label="Original Image")
|
|
|
|
|
|
|
|
|
|
|
17 |
while True:
|
18 |
-
inputs=gr.inputs.Image(type="pil",source="webcam")
|
19 |
outputs = gr.outputs.Image(type="pil", label="Output Image")
|
20 |
-
|
21 |
-
|
22 |
-
article = "
|
23 |
-
examples = [['soccer.jpg'], ['bus.jpg']]
|
24 |
-
gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, theme="huggingface").launch(
|
25 |
-
debug=True)
|
26 |
-
time.sleep(1)
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
import cv2
|
4 |
import time
|
5 |
from PIL import Image
|
6 |
# Images
|
|
|
8 |
torch.hub.download_url_to_file('https://cdn.pixabay.com/photo/2016/11/21/14/31/vw-bus-1845719_1280.jpg', 'bus.jpg')
|
9 |
# Model
|
10 |
model = torch.hub.load('ultralytics/yolov3', 'yolov3') # or yolov3-spp, yolov3-tiny, custom
|
11 |
+
|
12 |
+
cam = cv2.VideoCapture(0)
|
13 |
+
|
14 |
def yolo(im, size=640):
|
15 |
g = (size / max(im.size)) # gain
|
16 |
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
|
|
18 |
results.render() # updates results.imgs with boxes and labels
|
19 |
return Image.fromarray(results.imgs[0])
|
20 |
#inputs = gr.inputs.Image(type='pil', label="Original Image")
|
21 |
+
title = "Определение элементов"
|
22 |
+
description = "Находит на картинке элементы"
|
23 |
+
article = "тест"
|
24 |
+
examples = [['soccer.jpg'], ['bus.jpg']]
|
25 |
+
|
26 |
while True:
|
27 |
+
#inputs=gr.inputs.Image(type="pil",source="webcam")
|
28 |
outputs = gr.outputs.Image(type="pil", label="Output Image")
|
29 |
+
ret, frame = cam.read()
|
30 |
+
inputs = Image.fromarray(frame)
|
31 |
+
gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, theme="huggingface").launch(debug=True)
|
|
|
|
|
|
|
|