Spaces:
Sleeping
Sleeping
Ensure application file is placed correctly
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from keras.preprocessing import image
|
4 |
+
from Model_Load import load_model_from_files
|
5 |
+
|
6 |
+
# Load model dan label
|
7 |
+
model = load_model_from_files("model.json", "my_model.h5")
|
8 |
+
|
9 |
+
labels = [
|
10 |
+
"Benteng Vredeburg", "Candi Borobudur", "Candi Prambanan", "Gedung Agung Istana Kepresidenan",
|
11 |
+
"Masjid Gedhe Kauman", "Monumen Serangan 1 Maret", "Museum Gunungapi Merapi",
|
12 |
+
"Situs Ratu Boko", "Taman Sari", "Tugu Yogyakarta"
|
13 |
+
]
|
14 |
+
|
15 |
+
# Fungsi preprocessing dan prediksi
|
16 |
+
def classify_image(img):
|
17 |
+
img = img.resize((224, 224))
|
18 |
+
img_array = image.img_to_array(img)
|
19 |
+
img_array = np.expand_dims(img_array, axis=0)
|
20 |
+
img_array = img_array / 255.0
|
21 |
+
|
22 |
+
pred = model.predict(img_array)[0]
|
23 |
+
confidence = np.max(pred)
|
24 |
+
predicted_label = labels[np.argmax(pred)]
|
25 |
+
|
26 |
+
return f"{predicted_label} (Confidence: {confidence * 100:.2f}%)"
|
27 |
+
|
28 |
+
# Buat antarmuka Gradio
|
29 |
+
demo = gr.Interface(
|
30 |
+
fn=classify_image,
|
31 |
+
inputs=gr.Image(type="pil"),
|
32 |
+
outputs="text",
|
33 |
+
title="Klasifikasi Cagar Budaya DIY",
|
34 |
+
description="Upload gambar dan model akan mengklasifikasikannya ke dalam salah satu situs budaya di Yogyakarta."
|
35 |
+
)
|
36 |
+
|
37 |
+
# Launch untuk Hugging Face Spaces
|
38 |
+
if __name__ == "__main__":
|
39 |
+
demo.launch()
|
40 |
+
|