Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from ultralytics import YOLO
|
3 |
+
# Load model dari Hugging Face
|
4 |
+
model = YOLO("https://huggingface.co/ozzadinataX/mineral/resolve/main/best.pt")
|
5 |
+
# Daftar kelas sesuai model
|
6 |
+
class_names = ['biotite', 'bornite', 'chrysocolla', 'malachite', 'muscovite', 'pyrite', 'quartz']
|
7 |
+
def classify_image(image):
|
8 |
+
results = model(image) # Jalankan model pada gambar
|
9 |
+
probs = results[0].probs # Ambil hasil probabilitas
|
10 |
+
# Prediksi kelas dengan probabilitas tertinggi
|
11 |
+
top1_index = probs.top1
|
12 |
+
top1_label = class_names[top1_index]
|
13 |
+
return f"Predicted Class: {top1_label}"
|
14 |
+
demo = gr.Interface(
|
15 |
+
fn=classify_image,
|
16 |
+
inputs=gr.Image(type="pil"),
|
17 |
+
outputs="text",
|
18 |
+
title="Mineral Classify Demo"
|
19 |
+
)
|
20 |
+
demo.launch(share=True)
|