nehulagrawal commited on
Commit
e09ba31
Β·
1 Parent(s): 234dbc3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from sahi.classification import ImageClassification
4
+ from sahi.utils.cv import visualize_object_predictions, read_image
5
+ from ultralyticsplus import YOLO
6
+
7
+ def yolov8_inference(
8
+ image: gr.Image = None,
9
+ model_path: gr.Dropdown = None,
10
+ image_size: gr.Slider = 640,
11
+ conf_threshold: gr.Slider = 0.25,
12
+ iou_threshold: gr.Slider = 0.45,
13
+ ):
14
+ """
15
+ YOLOv8 inference function
16
+ Args:
17
+ image: Input image
18
+ model_path: Path to the model
19
+ image_size: Image size
20
+ conf_threshold: Confidence threshold
21
+ iou_threshold: IOU threshold
22
+
23
+ """
24
+ model = YOLO(model_path)
25
+ model.overrides['conf'] = conf_threshold
26
+ model.overrides['iou']= iou_threshold
27
+ model.overrides['agnostic_nms'] = False # NMS class-agnostic
28
+ model.overrides['max_det'] = 1000
29
+
30
+ # observe results
31
+ top_class_index = torch.argmax(results[0].probs).item()
32
+ Class = model.names[top_class_index]
33
+ print(Class)
34
+
35
+
36
+ inputs = [
37
+ gr.Image(type="filepath", label="Input Image"),
38
+ gr.Dropdown(["foduucom/Tyre-Quality-Classification-AI"],
39
+ default="foduucom/Tyre-Quality-Classification-AI", label="Model"),
40
+ gr.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
41
+ gr.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
42
+ gr.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"),
43
+ ]
44
+
45
+ outputs = gr.Image(type="filepath", label="Output Image")
46
+ title = "AI-Powered Tire Quality Inspection: YOLOv8s Enhanced Classification"
47
+
48
+ description ="""
49
+ πŸ”₯ Unveiling ThermalFoduu: Spot Objects with Thermal Vision! πŸ”πŸ“Έ Lost your keys in the dark? πŸ—οΈπŸŒ‘ ThermalFoduu's got you covered! Powered by Foduu AI, our app effortlessly detects objects in thermal images. No more blurry blobs – just pinpoint accuracy! πŸ¦…πŸŽ―
50
+ Love the thermal world? Give us a thumbs up! πŸ‘ Questions or suggestions? Contact us at info@foduu. Let's decode the thermal universe together! πŸ“§πŸŒ‘οΈ
51
+ """
52
+
53
+
54
+ 🌟 Space Description:"""
55
+ Welcome to our πŸ€– AI-Powered Tire Quality Inspection Space – a cutting-edge solution harnessing the capabilities of YOLOv8s to revolutionize πŸš— tire quality control processes.
56
+ """
57
+ πŸ” About This Space: """
58
+ This interactive platform empowers you to classify tires with unparalleled precision, utilizing a fine-tuned YOLOv8s model 🎯 specifically developed for identifying defects in tire manufacturing. By submitting an image of a tire, you can instantly determine whether it meets the rigorous quality standards required in the industry, helping to ensure safety and reliability in automotive products.
59
+ """
60
+ examples = [['samples/1.jpeg', 'foduucom/thermal-image-object-detection', 640, 0.25, 0.45], ['samples/2.jpg', 'foduucom/thermal-image-object-detection', 640, 0.25, 0.45]]
61
+ demo_app = gr.Interface(
62
+ fn=yolov8_inference,
63
+ inputs=inputs,
64
+ outputs=outputs,
65
+ title=title,
66
+ description=description,
67
+ examples=examples,
68
+ cache_examples=True,
69
+ theme='huggingface',
70
+ )
71
+ demo_app.queue().launch(debug=True)