Spaces:
Running
Running
File size: 2,105 Bytes
a1ac93a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import streamlit as st
import torch
import torchvision.transforms as transforms
from torchvision.transforms import ToTensor, Normalize, Compose
from PIL import Image
import numpy as np
from galaxy_classification import GalaxyCNN # Modelini import et
# Streamlit sayfa yapılandırması
st.set_page_config(
page_title="Galaxy Morphology Classification",
page_icon="✨",
layout="wide",
initial_sidebar_state="expanded",
)
# Modeli yükle
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = GalaxyCNN().to(device)
model.load_state_dict(torch.load("galaxy_cnn_model.pt", map_location=device))
model.eval()
# Görsel işleme fonksiyonu
def process_image(image):
transform = Compose([ToTensor(), Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]) # 3 kanal için normalize
image = image.convert("RGB").resize((64, 64)) # Modelin beklediği boyutta olmalı
image = transform(image).unsqueeze(0).to(device) # Model için uygun forma getir
return image
# Başlık ve alt başlık
st.title("🔭 Galaxy Morphology Classifier")
st.subheader("Upload a galaxy image and predict its morphological class!")
# Açıklama
st.write("""
### How It Works
1. Upload a galaxy image.
2. Click the "Classify Image" button.
3. The model predicts the galaxy's morphological class.
""")
# Görsel yükleme alanı
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
if uploaded_file:
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image", use_column_width=True)
# Tahmin butonu
if st.button("🔎 Classify Image"):
# Görseli işle
processed_image = process_image(image)
# Model ile tahmin yap
with torch.no_grad():
output = model(processed_image)
predicted_class = torch.argmax(output, dim=1).item()
# Sınıf isimleri
class_names = ["Smooth Round", "Smooth Cigar", "Edge-on Disk", "Spiral"]
st.write(f"**Prediction:** {class_names[predicted_class]} 🎯")
|