Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
|
| 4 |
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')
|
| 5 |
-
|
|
|
|
| 6 |
def detect_faces(image):
|
| 7 |
-
# Loading in yolov5s - you can switch to larger models such as yolov5m or yolov5l, or smaller such as yolov5n
|
| 8 |
results = model(image)
|
| 9 |
-
|
| 10 |
return results.render()[0]
|
| 11 |
|
| 12 |
-
# Create
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
# Launch the interface
|
| 16 |
-
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
# import torch
|
| 3 |
+
|
| 4 |
+
# model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')
|
| 5 |
+
# # Define the face detector function
|
| 6 |
+
# def detect_faces(image):
|
| 7 |
+
# # Loading in yolov5s - you can switch to larger models such as yolov5m or yolov5l, or smaller such as yolov5n
|
| 8 |
+
# results = model(image)
|
| 9 |
+
|
| 10 |
+
# return results.render()[0]
|
| 11 |
+
|
| 12 |
+
# # Create a Gradio interface
|
| 13 |
+
# iface = gr.Interface(fn=detect_faces, inputs=gr.Image(source="webcam", tool =None), outputs="image")
|
| 14 |
+
|
| 15 |
+
# # Launch the interface
|
| 16 |
+
# iface.launch(debug=True)
|
| 17 |
+
|
| 18 |
+
# demo = gr.TabbedInterface([img_demo, vid_demo], ["Image", "Video"])
|
| 19 |
+
|
| 20 |
+
# if __name__ == "__main__":
|
| 21 |
+
# demo.launch()
|
| 22 |
+
|
| 23 |
import gradio as gr
|
| 24 |
import torch
|
| 25 |
|
| 26 |
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')
|
| 27 |
+
|
| 28 |
+
# Define the face detector function
|
| 29 |
def detect_faces(image):
|
|
|
|
| 30 |
results = model(image)
|
|
|
|
| 31 |
return results.render()[0]
|
| 32 |
|
| 33 |
+
# Create Gradio interfaces for different modes
|
| 34 |
+
webcam_interface = gr.Interface(
|
| 35 |
+
fn=detect_faces,
|
| 36 |
+
inputs=gr.inputs.Image(source="webcam", tool=None),
|
| 37 |
+
outputs="image",
|
| 38 |
+
title="Webcam Mode"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
file_interface = gr.Interface(
|
| 42 |
+
fn=detect_faces,
|
| 43 |
+
inputs=gr.inputs.Image(source="file"),
|
| 44 |
+
outputs="image",
|
| 45 |
+
title="File Mode"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
url_interface = gr.Interface(
|
| 49 |
+
fn=detect_faces,
|
| 50 |
+
inputs=gr.inputs.Image(source="url"),
|
| 51 |
+
outputs="image",
|
| 52 |
+
title="URL Mode"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Create a list of interfaces
|
| 56 |
+
interfaces = [webcam_interface, file_interface, url_interface]
|
| 57 |
+
|
| 58 |
+
# Create the tabbed interface
|
| 59 |
+
tabbed_interface = gr.Interface(interfaces, layout="horizontal")
|
| 60 |
|
| 61 |
+
# Launch the tabbed interface
|
| 62 |
+
tabbed_interface.launch(debug=True)
|