File size: 1,056 Bytes
7372787 | 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 | import streamlit as st
import requests
from PIL import Image
import io
# Streamlit app title
st.title("๐ฅ Potato Leaf Disease Classifier")
# Upload image
uploaded_file = st.file_uploader("Upload a potato leaf image", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Show preview
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image", use_column_width=True)
# Button to trigger prediction
if st.button("Predict"):
with st.spinner("Classifying..."):
# Send image to FastAPI backend
response = requests.post(
"http://localhost:8000/predict",
files={"file": uploaded_file.getvalue()}
)
if response.status_code == 200:
result = response.json()
st.success(f"๐ฟ Predicted Class: **{result['class']}**")
st.info(f"๐ Confidence: **{result['confidence'] * 100:.2f}%**")
else:
st.error("Prediction failed. Please try again.")
|