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("Cassava leaf disease 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-cassava-leaf-disease-classification.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 - Cassava leaf disease classification_") st.markdown( "_Project repo - [https://github.com/AbhishekRS4/Deep_Learning/](https://github.com/AbhishekRS4/Deep_Learning/)_" ) st.markdown( "_Dataset - [Cassava leaf disease dataset](https://www.kaggle.com/competitions/cassava-leaf-disease-classification)_" ) st.header("Brief description of the project") st.write("The Cassava leaf disease dataset contains images of cassava leaves.") st.write( "This dataset contains instances for 5 classes --- .Cassava Bacterial Blight (CBB), Cassava Brown Streak Disease (CBSD), Cassava Green Mottle (CGM), Cassava Mosaic Disease (CMD), and Healthy" ) st.write( "The pretrained resnet-34 with a modified dense layer model is finetuned for the classification task." ) st.write("The best performing model has been used for the deployed application.") return app_modes = { "App Info": app_info, "Cassava Leaf Disease 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()