owaiskha9654 commited on
Commit
923429f
1 Parent(s): 37867c2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = "owaiskha9654/Yolov7_Custom_Object_Detection"
7
+ FILENAME = "best.pt"
8
+
9
+ yolov7_weights = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
10
+
11
+ model = torch.hub.load('WongKinYiu/yolov7', 'custom', path=yolov7_weights, force_reload=True) # local repo
12
+
13
+ def object_detection(im, size=416):
14
+ results = model(im) # inference
15
+ #results.print() # print results to screen
16
+ #results.show() # display results
17
+ #results.save() # save as results1.jpg, results2.jpg... etc.
18
+ results.render() # updates results.imgs with boxes and labels
19
+ return Image.fromarray(results.imgs[0])
20
+
21
+ title = "Identificação de Defeitos em Banana"
22
+ description = """Esse modelo é uma pequena demonstração baseada em uma análise de cerca de 60 imagens somente. Para resultados mais confiáveis e genéricos, são necessários mais exemplos (imagens).
23
+ """
24
+
25
+ image = gr.inputs.Image(shape=(416, 416), image_mode="RGB", source="upload", label="Image", optional=False)
26
+ outputs = gr.outputs.Image(type="pil", label="Output Image")
27
+
28
+ gr.Interface(
29
+ fn=object_detection,
30
+ inputs=image,
31
+ outputs=outputs,
32
+ title=title,
33
+ description=description,
34
+ examples=[["sample_images/IMG_0125.JPG"], ["sample_images/IMG_0129.JPG"],
35
+ ["sample_images/IMG_0157.JPG"], ["sample_images/IMG_0158.JPG"]],
36
+ ).launch()