astrolabesp commited on
Commit
ffff681
·
verified ·
1 Parent(s): 7061ea3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ # Load model dari Hugging Face
4
+ model = YOLO("https://huggingface.co/astrolabesp/vehicle-v2_deepl/resolve/main/best%20(5).pt")
5
+ # Daftar kelas sesuai model
6
+ class_names = [
7
+ 'Bus',
8
+ 'Car',
9
+ 'Motor-bike',
10
+ 'Three-wheel',
11
+ 'Truck',
12
+ 'Van'
13
+ ]
14
+ def classify_image(image):
15
+ results = model(image) # Jalankan model pada gambar
16
+ probs = results[0].probs # Ambil hasil probabilitas
17
+ # Prediksi kelas dengan probabilitas tertinggi
18
+ top1_index = probs.top1
19
+ top1_label = class_names[top1_index]
20
+ return f"Predicted Class: {top1_label}"
21
+ demo = gr.Interface(
22
+ fn=classify_image,
23
+ inputs=gr.Image(type="pil"),
24
+ outputs="text",
25
+ title="Vehicle Classify Demo"
26
+ )
27
+ demo.launch(share=True)