BesottenJenny's picture
Update src/streamlit_app.py
be08488 verified
import streamlit as st
import numpy as np
from PIL import Image
import tensorflow as tf
# Konfigurasi halaman
st.set_page_config(
page_title='Aircraft Image Classification',
layout='wide',
initial_sidebar_state='expanded'
)
# Judul halaman
st.title("Aircraft Classification: Military or Civilian?")
st.subheader("Convolutional Neural Network - Proof of Concept for Aircraft Identification")
# Tampilkan gambar dengan caption
gambar1 = Image.open('./src/foto1.jpg')
st.image(gambar1, caption='Image Source: Dassault Aviation')
# Paragraf pembuka
st.write("""
In modern conflicts and crises, the spread of misinformation through open-source intelligence (OSINT)
can lead to severe geopolitical consequences. Visual data from social media is often misinterpreted,
resulting in false narratives. This project serves as a **Proof of Concept** for an automated system
that can assist analysts and journalists in verifying whether an aircraft shown in an image is
**Military** or **Civilian**. In other words, to **save civilian lives**.
One tragic example that highlights the urgency of such tools is the **MH17 incident** in 2014,
where a civilian airliner was shot down over a conflict zone. A model like this could serve as an early step
towards minimizing misinformation and ensuring accurate analysis.
""")
# Tampilkan gambar dengan caption
gambar2 = Image.open('./src/foto2.webp')
st.image(gambar2, caption='Crash site of MH17 | Image Source: Reuters')
# Paragraf tentang model
st.write("""
This Convolutional Neural Network (CNN) model was trained to achieve high accuracy in classifying images as either
**Military Aircraft** or **Civilian Aircraft**. The model performs exceptionally well for this specific task: **94.43%** accuracy on train data and **94.52%** accuracy on validation data.
But it has a limitation:
1. The model will not tell you the specific type of the aircraft.
2. If you upload an image unrelated to aircraft, it will still try to classify it into one of these two categories.
""")
# Load model
model = tf.keras.models.load_model('./src/epoch_18.keras')
# Upload gambar
uploaded_file = st.file_uploader("Upload an image (JPG/PNG):", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Tampilkan instruksi dan gambar yang diunggah
st.write("Processing your image...")
image = Image.open(uploaded_file).convert('RGB')
# Preprocessing: resize ke 150x150
img_resized = image.resize((150, 150))
img_array = np.array(img_resized) / 255.0 # Normalisasi
img_array = np.expand_dims(img_array, axis=0) # Tambahkan batch dimensi
# Prediksi
pred = model.predict(img_array)
prob_military = float(pred[0][0]) # probabilitas kelas military
prob_civilian = 1 - prob_military # probabilitas kelas civilian
# Tentukan kelas prediksi dan confidence
if prob_military >= 0.5:
pred_class = "Military Aircraft"
confidence = prob_military * 100
else:
pred_class = "Civilian Aircraft"
confidence = prob_civilian * 100
# Tampilkan gambar & hasil prediksi
st.image(image, caption='Uploaded Image')
st.write(f"### Prediction: **{pred_class}**")
st.write(f"Confidence: **{confidence:.2f}%**")
st.write(f"Probability (Civilian): {prob_civilian:.4f}")
st.write(f"Probability (Military): {prob_military:.4f}")
# Footer
st.markdown(
"""
<hr style="margin-top: 50px; border: none; border-top: 1px solid #ddd;">
<div style="text-align: center; color: gray; font-size: 12px; margin-top: 10px;">
© 2025 Zhaky Baridwan Triaji. All rights reserved.
</div>
""",
unsafe_allow_html=True
)