import streamlit as st import pandas as pd import numpy as np from PIL import Image import tensorflow as tf import datetime import os # Global variable to store the uploaded image uploaded_image = None final_cord_list = [] if not os.path.exists("Exported Data"): os.mkdir("Exported Data") # DataFrame to store patient data df = pd.DataFrame(columns=['Status', 'Patient ID', 'Patient Name', 'Patient Age', 'Patient Contact', 'Gender']) # Function to export data to Excel def export_to_excel(): now = datetime.datetime.now() file_name = f"Exported Data/{now.strftime('%d_%m_%Y_%H_%M')}.xlsx" if os.path.exists(file_name): st.error(f"File {file_name} already exists!") else: df.to_excel(file_name, index=False) st.success("Data was exported as Excel file in the current directory") # Function to handle image upload and processing def upload_image(): global uploaded_image uploaded_image = st.file_uploader("Upload Image", type=['jpg', 'jpeg', 'png']) if uploaded_image is not None: img = Image.open(uploaded_image) st.image(img, caption="Uploaded Image", use_column_width=True) # Preprocess the image for model input img = img.resize((224, 224)) img_array = np.array(img) img_array = np.expand_dims(img_array, axis=0) return img_array # Function to perform cancer detection def detect_cancer(img_array): loaded_model = tf.keras.models.load_model('mymodel.hdf5') ypred = loaded_model.predict(img_array) return "Normal" if ypred < 0.5 else "OCCS" # Streamlit App st.title("OCD Tool") # Upload Image Section img_array = upload_image() if st.button("Detect Cancer"): if img_array is not None: result = detect_cancer(img_array) st.write(f"Prediction: {result}") # Collect patient data patient_id = st.text_input("Patient ID") patient_name = st.text_input("Patient Name") patient_age = st.text_input("Patient Age") patient_contact = st.text_input("Patient Contact") gender = st.selectbox("Gender", options=["Male", "Female", "Other"]) if st.button("Save Data"): final_cord_list.extend([result, patient_id, patient_name, patient_age, patient_contact, gender]) df.loc[len(df)] = final_cord_list st.success("Data saved, select another patient image") final_cord_list.clear() # Clear the list for new entries # Export Data Section if st.button("Export Data"): export_to_excel()