Update app.py
Browse files
app.py
CHANGED
|
@@ -20,39 +20,16 @@ def predict_with_loaded_model(in_sentences):
|
|
| 20 |
# Streamlit interface
|
| 21 |
st.title("Stress Prediction with DistilBERT")
|
| 22 |
|
| 23 |
-
# Initialize session state variables for user input and prediction output
|
| 24 |
-
if 'user_input' not in st.session_state:
|
| 25 |
-
st.session_state.user_input = ""
|
| 26 |
-
if 'prediction' not in st.session_state:
|
| 27 |
-
st.session_state.prediction = None
|
| 28 |
-
|
| 29 |
# Add a text input box for the user to enter a sentence
|
| 30 |
-
user_input = st.text_area("Enter a sentence or text:",
|
| 31 |
-
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
else:
|
| 43 |
-
st.write("Please enter a sentence to predict.")
|
| 44 |
-
|
| 45 |
-
with col2:
|
| 46 |
-
# Refresh button to reset the user input and output
|
| 47 |
-
if st.button("Refresh"):
|
| 48 |
-
# Clear both user input and prediction output
|
| 49 |
-
st.session_state.user_input = ""
|
| 50 |
-
st.session_state.prediction = None
|
| 51 |
-
st.rerun() # Refresh the app
|
| 52 |
-
|
| 53 |
-
# Display the prediction result
|
| 54 |
-
if st.session_state.prediction:
|
| 55 |
-
prediction = st.session_state.prediction
|
| 56 |
-
st.write(f"Text: {prediction['text']}")
|
| 57 |
-
st.write(f"Prediction: {prediction['label']}")
|
| 58 |
-
# st.write(f"Confidence: {prediction['confidence']}")
|
|
|
|
| 20 |
# Streamlit interface
|
| 21 |
st.title("Stress Prediction with DistilBERT")
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
# Add a text input box for the user to enter a sentence
|
| 24 |
+
user_input = st.text_area("Enter a sentence or text:", "")
|
| 25 |
+
|
| 26 |
+
# When the user clicks "Predict", run the prediction function
|
| 27 |
+
if st.button("Predict"):
|
| 28 |
+
if user_input:
|
| 29 |
+
# Make the prediction using the model
|
| 30 |
+
prediction = predict_with_loaded_model([user_input])[0]
|
| 31 |
+
st.write(f"Text: {prediction['text']}")
|
| 32 |
+
st.write(f"Prediction: {prediction['label']}")
|
| 33 |
+
# st.write(f"Confidence: {prediction['confidence']}")
|
| 34 |
+
else:
|
| 35 |
+
st.write("Please enter a sentence to predict.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|