File size: 3,324 Bytes
02362a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec9a0da
02362a0
 
 
 
 
3605e6e
 
 
 
 
 
 
 
02362a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import random
from datetime import datetime

import numpy as np
import requests
import satellighte as sat
import streamlit as st
from PIL import Image


def main():
    # pylint: disable=no-member

    st.set_page_config(
        page_title="Satellighte Demo Page",
        page_icon="📡",
        layout="centered",
        initial_sidebar_state="expanded",
        menu_items={
            "Get Help": "https://canturan10.github.io/satellighte/",
            "About": "Satellite Image Classification",
        },
    )

    st.title("Satellighte Demo Page")

    url = "https://raw.githubusercontent.com/canturan10/satellighte/master/src/satellighte.png?raw=true"
    satellighte = Image.open(requests.get(url, stream=True).raw)

    st.sidebar.image(satellighte, width=100)
    st.sidebar.title("Satellighte")
    st.sidebar.caption(sat.__description__)

    st.sidebar.write(
        "**Satellighte** is an image classification library  that consist state-of-the-art deep learning methods. It is a combination of the words **'Satellite'** and **'Light'**, and its purpose is to establish a light structure to classify satellite images, but to obtain robust results."
    )

    st.sidebar.caption(f"Version: `{sat.__version__}`")
    st.sidebar.caption(f"License: `{sat.__license__}`")
    st.sidebar.caption("")
    st.sidebar.caption(f"[Website](https://canturan10.github.io/satellighte/)")
    st.sidebar.caption(f"[Docs](https://satellighte.readthedocs.io/)")
    st.sidebar.caption(f"[Github](https://github.com/canturan10/satellighte)")
    st.sidebar.caption(f"[Demo Page](https://canturan10-satellighte-streamlit-app-6lr5ve.streamlitapp.com/)")
    #st.sidebar.caption(f"[Hugging Face](https://huggingface.co/spaces/canturan10/satellighte)")
    st.sidebar.caption(f"[Pypi](https://pypi.org/project/satellighte/)")
    st.sidebar.caption("")
    st.sidebar.caption(sat.__copyright__)

    selected_model = st.selectbox(
        "Select model",
        sat.available_models(),
    )
    selected_version = st.selectbox(
        "Select version",
        sat.get_model_versions(selected_model),
    )

    model = sat.Classifier.from_pretrained(selected_model, selected_version)
    model.eval()

    uploaded_file = st.file_uploader(
        "", type=["png", "jpg", "jpeg"], accept_multiple_files=False
    )

    if uploaded_file is None:
        st.write("Sample Image")
        # Sample image.
        url = f"https://raw.githubusercontent.com/canturan10/satellighte/master/src/eurosat_samples/{random_sample}?raw=true"
        image = Image.open(requests.get(url, stream=True).raw)

    else:
        # User-selected image.
        image = Image.open(uploaded_file)

    image = np.array(image.convert("RGB"))
    FRAME_WINDOW = st.image([], use_column_width=True)

    model = sat.Classifier.from_pretrained(selected_model, selected_version)
    model.eval()

    results = model.predict(image)
    pil_img = sat.utils.visualize(image, results)

    st.write("Results:", results)
    FRAME_WINDOW.image(pil_img)


if __name__ == "__main__":
    samples = [
        "AnnualCrop.jpg",
        "Forest.jpg",
        "HerbaceousVegetation.jpg",
        "PermanentCrop.jpg",
        "River.jpg",
    ]
    random.seed(datetime.now())
    random_sample = samples[random.randint(0, len(samples) - 1)]

    main()