Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import requests
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
|
| 7 |
+
# This is a placeholder for your image classification function
|
| 8 |
+
def classify_image(image):
|
| 9 |
+
pipe = pipeline("image-classification", "SolubleFish/swin-tiny-patch4-window7-224-finetuned-eurosat")
|
| 10 |
+
return pipe(image)
|
| 11 |
+
|
| 12 |
+
# Title
|
| 13 |
+
st.title("Image Classification Web App")
|
| 14 |
+
|
| 15 |
+
# Intro
|
| 16 |
+
st.write("Please provide a Satellite image for classification")
|
| 17 |
+
|
| 18 |
+
# Image input via URL
|
| 19 |
+
url = st.text_input("Image URL")
|
| 20 |
+
if url:
|
| 21 |
+
try:
|
| 22 |
+
response = requests.get(url)
|
| 23 |
+
image = Image.open(BytesIO(response.content))
|
| 24 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 25 |
+
except Exception as e:
|
| 26 |
+
st.write("Invalid URL. Please enter a valid URL for an image.")
|
| 27 |
+
|
| 28 |
+
# Image input via file uploader
|
| 29 |
+
uploaded_file = st.file_uploader("Or upload an image", type=["jpg", "png"])
|
| 30 |
+
if uploaded_file is not None:
|
| 31 |
+
image = Image.open(uploaded_file)
|
| 32 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 33 |
+
|
| 34 |
+
# Classification button
|
| 35 |
+
if st.button("Classify Image"):
|
| 36 |
+
if url or uploaded_file:
|
| 37 |
+
results = classify_image(image)
|
| 38 |
+
if results:
|
| 39 |
+
# Use markdown to present the results
|
| 40 |
+
for result in results:
|
| 41 |
+
st.markdown(f"**Class name:** {result['label']} \n\n **Confidence:** {str(format(result['score']*100, '.2f'))}"+"%")
|
| 42 |
+
else:
|
| 43 |
+
st.write("No results found.")
|
| 44 |
+
else:
|
| 45 |
+
st.write("Please provide an image for classification.")
|
| 46 |
+
|