import os import io import cv2 import requests import numpy as np import streamlit as st from PIL import Image from skimage.io import imread def infer() -> None: st.title("Overhead MNIST classification app") # select an input image file image_file_buffer = st.sidebar.file_uploader( "Select input image", type=["jpg", "jpeg"] ) # read the image if image_file_buffer is not None: image = Image.open(image_file_buffer) image_array = np.array(image) st.image(image_array, caption=f"Input image: {image_file_buffer.name}") else: st.write("Input image: not selected") # run inference when the option is invoked by the user infer_button = st.sidebar.button("Run inference") if infer_button: files = {"image_file": (image_file_buffer.name, image_file_buffer.getvalue())} # if the deployment is on local machine response = requests.post( "https://abhishekrs4-overhead-mnist.hf.space/predict", files=files, ) # if the deployment is on hugging face # response = requests.post( # "http://127.0.0.1:7860/predict", # files=files, # ) st.write("The following is the prediction") st.write(response.json()) return def app_info() -> None: st.title("App info") st.markdown("_Task - Overhead MNIST classification_") st.markdown( "_Project repo - [https://github.com/AbhishekRS4/overhead_mnist](https://github.com/AbhishekRS4/overhead_mnist)_" ) st.markdown( "_Dataset - [Overhead MNIST dataset](https://www.kaggle.com/datasets/datamunge/overheadmnist/)_" ) st.header("Brief description of the project") st.write( "The Overhead MNIST dataset contains images extracted from satellite data." ) st.write( "This dataset contains instances for 10 classes --- car, harbor, helicopter, oil_gas_field, parking_lot, plane, runway_mark, ship, stadium, and storage_tank." ) st.write("A custom architecture is modeled for the classification task.") st.write("The best performing model has been used for the deployed application.") return app_modes = { "App Info": app_info, "Overhead MNIST Inference App": infer, } def start_app() -> None: selected_mode = st.sidebar.selectbox("Select mode", list(app_modes.keys())) app_modes[selected_mode]() return def main() -> None: start_app() return if __name__ == "__main__": main()