|
import streamlit as st |
|
from transformers import pipeline |
|
from PIL import Image |
|
import requests |
|
from io import BytesIO |
|
|
|
|
|
def classify_image(image): |
|
pipe = pipeline("image-classification", "SolubleFish/swin_transformers-finetuned-eurosat") |
|
return pipe(image) |
|
|
|
|
|
st.title("Image Classification Web App") |
|
|
|
|
|
st.write("Please provide a Satellite image for classification ") |
|
|
|
|
|
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.") |
|
|
|
|
|
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) |
|
|
|
|
|
if st.button("Classify Image"): |
|
if url or uploaded_file: |
|
results = classify_image(image) |
|
if 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.") |
|
|
|
|