stanlys96 commited on
Commit
537cf6b
·
verified ·
1 Parent(s): 63226c9

Upload 6 files

Browse files
Files changed (1) hide show
  1. prediction.py +19 -19
prediction.py CHANGED
@@ -19,29 +19,29 @@ def get_feeling(number):
19
 
20
  # Load the model function
21
  def load_model():
22
- return tf.keras.models.load_model('model.keras', custom_objects={'KerasLayer': tf_hub.KerasLayer})
23
 
24
- st.session_state.the_model = load_model()
 
 
25
 
26
  def app():
27
  st.header('Prediction', divider='rainbow')
28
 
29
  user_input = st.text_input("Enter your text here:")
30
- if 'the_model' not in st.session_state:
31
- with st.spinner("Loading the model, please wait..."):
32
- if st.button('Predict', type="secondary"):
33
- data = {
34
- "text_processed": [
35
- user_input
36
- ]
37
- }
38
- df = pd.DataFrame(data)
39
- with st.spinner("Making prediction..."):
40
- # Replace with your preprocessing and prediction code
41
- predictions = st.session_state.the_model.predict(df)
42
- predicted_class = np.argmax(predictions, axis=1)
43
- the_sentiment = predicted_class[0]
44
 
45
- st.write(f"We have predicted that the sentiment of this text is {get_feeling(the_sentiment)}")
46
- else:
47
- st.write("Click the button to predict!")
 
19
 
20
  # Load the model function
21
  def load_model():
22
+ return tf.keras.models.load_model('model.keras', custom_objects={'KerasLayer': tf_hub.KerasLayer})
23
 
24
+ if 'the_model' not in st.session_state:
25
+ with st.spinner("Loading the model, please wait..."):
26
+ st.session_state.the_model = load_model()
27
 
28
  def app():
29
  st.header('Prediction', divider='rainbow')
30
 
31
  user_input = st.text_input("Enter your text here:")
32
+ if st.button('Predict', type="secondary"):
33
+ data = {
34
+ "text_processed": [
35
+ user_input
36
+ ]
37
+ }
38
+ df = pd.DataFrame(data)
39
+ with st.spinner("Making prediction..."):
40
+ # Replace with your preprocessing and prediction code
41
+ predictions = st.session_state.the_model.predict(df)
42
+ predicted_class = np.argmax(predictions, axis=1)
43
+ the_sentiment = predicted_class[0]
 
 
44
 
45
+ st.write(f"We have predicted that the sentiment of this text is {get_feeling(the_sentiment)}")
46
+ else:
47
+ st.write("Click the button to predict!")