File size: 2,966 Bytes
1adaa44
 
 
 
 
 
 
a665ec4
 
 
 
 
 
 
 
 
1adaa44
 
 
 
 
a665ec4
1adaa44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a665ec4
 
 
 
 
 
1adaa44
a665ec4
1adaa44
 
 
a665ec4
1adaa44
a665ec4
1adaa44
a665ec4
1adaa44
a665ec4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline
from PIL import Image
import requests
from io import BytesIO

# This is a placeholder for your image classification function
def classify_image1(image):
    pipe1 = pipeline("image-classification", "SolubleFish/swin_transformer-finetuned-eurosat")
    return pipe1(image)
def classify_image2(image):
    pipe2 = pipeline("image-classification", "SolubleFish/image_classification_convnext")
    return pipe2(image)
def classify_image3(image):
    pipe3 = pipeline("image-classification", "SolubleFish/image_classification_vit")
    return pipe3(image)

# Title
st.title("Image Classification Web App")

# Intro
st.write("Please provide a Satellite image for classification")

# Image input via URL
url = st.text_input("Image URL")
if url:
    try:
        response = requests.get(url)
        image = Image.open(BytesIO(response.content))
        st.image(image, caption='Uploaded Image', use_column_width=True)
    except Exception as e:
        st.write("Invalid URL. Please enter a valid URL for an image.")

# Image input via file uploader
uploaded_file = st.file_uploader("Or upload an image", type=["jpg", "png"])
if uploaded_file is not None:
    image = Image.open(uploaded_file)
    st.image(image, caption='Uploaded Image', use_column_width=True)


# Create three columns
col1, col2, col3 = st.columns(3)

# Classification button for classify_image1
if col1.button("Classify Image by swin"):
    if url or uploaded_file:
        results = classify_image1(image)
        if results:
            # Use markdown to present the results
            for result in results:
                col1.markdown(f"**Class name:** {result['label']} \n\n **Confidence:** {str(format(result['score']*100, '.2f'))}"+"%")
        else:
            col1.write("No results found.")
    else:
        col1.write("Please provide an image for classification.")

# Classification button for classify_image2
if col2.button("Classify Image by convnext"):
    if url or uploaded_file:
        results = classify_image2(image)
        if results:
            # Use markdown to present the results
            for result in results:
                col2.markdown(f"**Class name:** {result['label']} \n\n **Confidence:** {str(format(result['score']*100, '.2f'))}"+"%")
        else:
            col2.write("No results found.")
    else:
        col2.write("Please provide an image for classification.")

# Classification button for classify_image3
if col3.button("Classify Image by vit"):
    if url or uploaded_file:
        results = classify_image3(image)
        if results:
            # Use markdown to present the results
            for result in results:
                col3.markdown(f"**Class name:** {result['label']} \n\n **Confidence:** {str(format(result['score']*100, '.2f'))}"+"%")
        else:
            col3.write("No results found.")
    else:
        col3.write("Please provide an image for classification.")