Sambhavnoobcoder commited on
Commit
078e4df
·
1 Parent(s): 4386646

software engineer draft

Browse files
Files changed (1) hide show
  1. app.py +9 -21
app.py CHANGED
@@ -5,29 +5,17 @@ import tensorflow as tf
5
  model = tf.keras.models.load_model("sentimentality.h5")
6
 
7
  def predict_sentiment(text):
8
- """
9
- This function takes a text input and returns the predicted sentiment using a saved model.
10
 
11
- Parameters:
12
- text (str): The input text to be analyzed
 
13
 
14
- Returns:
15
- str: The predicted sentiment of the input text (either "positive" or "negative")
16
- """
17
- # Preprocess the input text
18
- text = preprocess_text(text)
19
-
20
- # Make the prediction using the loaded model
21
- prediction = model.predict([text])[0][0]
22
-
23
- # Return the predicted sentiment
24
- if prediction > 0.5:
25
- return "positive"
26
- else:
27
- return "negative"
28
 
29
- # Create the Gradio interface
30
- iface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text")
 
31
 
32
- # Run the interface
33
  iface.launch()
 
5
  model = tf.keras.models.load_model("sentimentality.h5")
6
 
7
  def predict_sentiment(text):
8
+ # preprocess input text
9
+ processed_text = preprocess(text)
10
 
11
+ # predict sentiment
12
+ prediction = model.predict([processed_text])[0][0]
13
+ sentiment = 'positive' if prediction >= 0.5 else 'negative'
14
 
15
+ return sentiment
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ iface = gr.Interface(fn=predict_sentiment,
18
+ inputs=gr.inputs.Textbox(label='Input Text'),
19
+ outputs=gr.outputs.Label(label='Sentiment Prediction'))
20
 
 
21
  iface.launch()