SolubleFish's picture
Create app.py
1adaa44 verified
raw
history blame
No virus
1.54 kB
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")
# 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.")