Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -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/septyandy/Rock_Type_Classification/resolve/main/best.pt")
|
| 5 |
+
# Daftar kelas sesuai model
|
| 6 |
+
class_names = ['Igneous_Rock', 'Sedimentary_Rock', 'Metamorphic_Rock']
|
| 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="Rock Type Identification Application"
|
| 19 |
+
)
|
| 20 |
+
demo.launch(share=True)
|