Commit
·
73e1dac
1
Parent(s):
2e71df7
tried adapting demo code from docs
Browse files
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 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
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=
|
30 |
-
inputs=gr.
|
31 |
-
outputs=
|
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()
|