File size: 1,672 Bytes
1adaa44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d11b84b
1adaa44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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_image(image):
    pipe = pipeline("image-classification", "SolubleFish/swin-tiny-patch4-window7-224-finetuned-eurosat")
    return pipe(image)

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

# Intro
st.write("Please provide a Satellite image for classification /n /n Class names = Forest, River, Highway, AnnualCrop,SeaLake, HerbaceousVegetation, Industrial, Residential, PermanentCrop, Pasture")

# 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)

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