Update app.py
Browse files
app.py
CHANGED
@@ -20,16 +20,39 @@ def predict_with_loaded_model(in_sentences):
|
|
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 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:", st.session_state.user_input)
|
31 |
+
|
32 |
+
# Define buttons with a sidebar layout for easy spacing
|
33 |
+
col1, col2 = st.columns([1, 1])
|
34 |
+
with col1:
|
35 |
+
# When the user clicks "Predict", run the prediction function
|
36 |
+
if st.button("Predict"):
|
37 |
+
if user_input:
|
38 |
+
# Update session state with the user input
|
39 |
+
st.session_state.user_input = user_input
|
40 |
+
# Make the prediction using the model
|
41 |
+
st.session_state.prediction = predict_with_loaded_model([user_input])[0]
|
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 |
+
st.session_state.user_input = ""
|
49 |
+
st.session_state.prediction = None
|
50 |
+
st.experimental_rerun()
|
51 |
+
|
52 |
+
# Display the prediction result
|
53 |
+
if st.session_state.prediction:
|
54 |
+
prediction = st.session_state.prediction
|
55 |
+
st.write(f"Text: {prediction['text']}")
|
56 |
+
st.write(f"Prediction: {prediction['label']}")
|
57 |
+
# st.write(f"Confidence: {prediction['confidence']}")
|
58 |
+
|