Sambhavnoobcoder commited on
Commit
73e1dac
·
1 Parent(s): 2e71df7

tried adapting demo code from docs

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -13,23 +13,16 @@ def preprocess(text):
13
  text = tf.keras.preprocessing.sequence.pad_sequences(text, maxlen=500, padding='post', truncating='post')
14
  return text
15
 
16
- # Define a function to make a prediction on the input text
17
- def predict_sentiment(text):
18
- # Preprocess the text
19
- text = preprocess(text)
20
- # Make a prediction using the loaded model
21
- proba = model.predict(text)[0]
22
- # Normalize the probabilities
23
- proba /= proba.sum()
24
- # Return the probability distribution
25
- return {"Positive": float(proba[0]), "Negative": float(proba[1]), "Neutral": float(proba[2])}
26
 
27
- # Create a Gradio interface
28
  iface = gr.Interface(
29
- fn=predict_sentiment,
30
- inputs=gr.inputs.Textbox(label="Enter text here"),
31
- outputs=gr.outputs.Label(label="Sentiment", default="Neutral")
32
- )
 
33
 
34
- # Launch the interface
35
  iface.launch()
 
13
  text = tf.keras.preprocessing.sequence.pad_sequences(text, maxlen=500, padding='post', truncating='post')
14
  return text
15
 
16
+ def sentiment_analysis(text):
17
+ scores = model.predict(text)
18
+ del scores["compound"]
19
+ return scores
 
 
 
 
 
 
20
 
 
21
  iface = gr.Interface(
22
+ fn=sentiment_analysis,
23
+ inputs=gr.Textbox(placeholder="Enter a positive or negative sentence here..."),
24
+ outputs="label",
25
+ interpretation="default",
26
+ examples=[["This is wonderful!"]])
27
 
 
28
  iface.launch()