michaelwja commited on
Commit
e101990
1 Parent(s): 77d8882

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -58
app.py CHANGED
@@ -1,60 +1,39 @@
1
- import gradio as gr
2
  import torch
3
- from ultralytics import YOLO
4
-
5
-
6
- # Images
7
- torch.hub.download_url_to_file('https://github.com/Michael-OvO/Burn-Detection-Classification/blob/main/inference/images/1st_degree_1.jpg', '1st_degree_1.jpg')
8
- torch.hub.download_url_to_file('https://github.com/Michael-OvO/Burn-Detection-Classification/blob/main/inference/images/3rd_degree_1.jpg', '3rd_degree_1.jpg')
9
-
10
- def yolov7_inference(
11
- image: gr.inputs.Image = None,
12
- model_path: gr.inputs.Dropdown = None,
13
- image_size: gr.inputs.Slider = 640,
14
- conf_threshold: gr.inputs.Slider = 0.25,
15
- iou_threshold: gr.inputs.Slider = 0.45,
16
- ):
17
- """
18
- YOLOv7 inference function
19
- Args:
20
- image: Input image
21
- model_path: Path to the model
22
- image_size: Image size
23
- conf_threshold: Confidence threshold
24
- iou_threshold: IOU threshold
25
- Returns:
26
- Rendered image
27
- """
28
- model = YOLO('skin_burn.pt')
29
- model.conf = conf_threshold
30
- model.iou = iou_threshold
31
- results = model([image], size=image_size)
32
- return results.render()[0]
33
-
34
-
35
- inputs = [
36
- gr.inputs.Image(type="pil", label="Input Image"),
37
- gr.inputs.Dropdown(
38
- choices=[
39
- "skin_burn.pt",
40
- "Other"
41
- ],
42
- default="skin_burn",
43
- label="Model",
44
- ),
45
- gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
46
- gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
47
- gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"),
48
- ]
49
-
50
- outputs = gr.outputs.Image(type="filepath", label="Output Image")
51
- title = "Yolov7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors"
52
-
53
- demo_app = gr.Interface(
54
- fn=yolov7_inference,
55
- inputs=inputs,
56
  outputs=outputs,
57
- title=title,
58
- theme='huggingface',
59
- )
60
- demo_app.launch(debug=True, enable_queue=True)
 
 
1
  import torch
2
+ import gradio as gr
3
+ from huggingface_hub import hf_hub_download
4
+ from PIL import Image
5
+
6
+ REPO_ID = "Michael/YOLOv7"
7
+ FILENAME = "skin_burn.pt"
8
+
9
+
10
+ yolov7_custom_weights = hf_hub_download(repo_id=REPO_ID, filename=FILENAME,repo_type='space')
11
+
12
+ model = torch.hub.load('WongKinYiu/yolov7:main',model='custom', path_or_model=yolov7_custom_weights, force_reload=True)
13
+ def object_detection(im, size=416):
14
+ results = model(im)
15
+ results.render()
16
+ return Image.fromarray(results.imgs[0])
17
+
18
+ title = "Yolov7 Custom"
19
+
20
+ image = gr.inputs.Image(shape=(614,614), image_mode="RGB", source="upload", label="Upload Image", optional=False)
21
+ outputs = gr.outputs.Image(type="pil", label="Output Image")
22
+
23
+ Custom_description="Custom Training Performed on colab style='text-decoration: underline' target='_blank'>Link</a> </center><br> <center>Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors </center> <br> <b>1st</b> class is for Person Detected<br><b>2nd</b> class is for Car Detected"
24
+
25
+ Footer = (
26
+ "MOdel train on our custome dataset")
27
+
28
+
29
+ Top_Title="<center>Yolov7 🚀 Custom Trained style='text-decoration: underline' target='_blank'></center></a>Face with mask and face without mask Detection"
30
+ css = ".output-image, .input-image {height: 50rem !important; width: 100% !important;}"
31
+ css = ".image-preview {height: auto !important;}"
32
+
33
+ gr.Interface(
34
+ fn=object_detection,
35
+ inputs=image,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  outputs=outputs,
37
+ title=Top_Title,
38
+ description=Custom_description,
39
+ article=Footer,).launch()