Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
jagadeshchilla committed Oct 17, 2024
1 parent 6d867fa commit 53bbb44
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pages/Image_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
}

# Initialize session state
# Initialize session state if it does not exist
if 'saved_predictions' not in st.session_state:
st.session_state.saved_predictions = []
if 'predictions' not in st.session_state:
Expand All @@ -54,7 +54,8 @@ def load_existing_predictions():
return []

# Load existing predictions into session state
st.session_state.saved_predictions = load_existing_predictions()
if not st.session_state.saved_predictions: # Check if it's empty
st.session_state.saved_predictions = load_existing_predictions()

def save_predictions_to_history(uploaded_files, predictions, model_name):
prediction_data = []
Expand All @@ -66,9 +67,7 @@ def save_predictions_to_history(uploaded_files, predictions, model_name):
'prediction': actual
})

# Check if predictions exist and extend saved_predictions list
if isinstance(st.session_state.saved_predictions, list):
st.session_state.saved_predictions.extend(prediction_data)
st.session_state.saved_predictions.extend(prediction_data)

with open('prediction_history.json', 'w') as f:
json.dump(st.session_state.saved_predictions, f, indent=4)
Expand Down Expand Up @@ -224,6 +223,6 @@ def image_to_base64(image: Image.Image) -> str:
""", unsafe_allow_html=True
)

# Streamlit application runner
if __name__ == '__main__':
# Call the function to show image prediction
if __name__ == "__main__":
show_image_prediction()

0 comments on commit 53bbb44

Please sign in to comment.