michaelwja commited on
Commit
8981abe
1 Parent(s): 05b88bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -17
app.py CHANGED
@@ -1,23 +1,63 @@
1
  import gradio as gr
2
  import torch
3
- from PIL import Image
4
 
5
- # Load the model using torch.hub (you must have the model locally)
6
- model_name = "skin_burn_2022_8_21 (1).pt"
7
- model =torch.hub.load("WongKinYiu/yolov7", 'custom',model_name)
8
 
9
- def predict(img):
10
- # Run inference with YOLO model
11
- results = model(img)
12
- # Convert the result to an image
13
- result_img = Image.fromarray(results.render())
14
- return result_img
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- # Define a Gradio interface
17
- iface = gr.Interface(
18
- fn=predict, # the function to wrap
19
- inputs=gr.inputs.Image(), # input type
20
- outputs=gr.outputs.Image() # output type
21
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import torch
3
+ import yolov7
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
 
29
+ model = torch.hub.load('WongKinYiu/yolov7', 'custom', path='path/to/best.pt', source='local', device="cpu", hf_model=True, trace=False)
30
+ model.conf = conf_threshold
31
+ model.iou = iou_threshold
32
+ results = model([image], size=image_size)
33
+ return results.render()[0]
34
+
35
+
36
+ inputs = [
37
+ gr.inputs.Image(type="pil", label="Input Image"),
38
+ gr.inputs.Dropdown(
39
+ choices=[
40
+ "skin_burn",
41
+ "kadirnar/yolov7-v0.1",
42
+ ],
43
+ default="skin_burn",
44
+ label="Model",
45
+ ),
46
+ gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
47
+ gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
48
+ gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"),
49
+ ]
50
 
51
+ outputs = gr.outputs.Image(type="filepath", label="Output Image")
52
+ title = "Yolov7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors"
53
+
54
+ demo_app = gr.Interface(
55
+ fn=yolov7_inference,
56
+ inputs=inputs,
57
+ outputs=outputs,
58
+ title=title,
59
+ examples=examples,
60
+ cache_examples=True,
61
+ theme='huggingface',
62
+ )
63
+ demo_app.launch(debug=True, enable_queue=True)