Spaces:
Runtime error
Runtime error
shrirangphadke
commited on
Update app.py
Browse filesGradio sentiment signal
app.py
CHANGED
@@ -1,23 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
import numpy as np
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
predictions = model.predict(np.expand_dims(image, axis=0))
|
15 |
-
return {imagenet_labels[i]: float(predictions[0][i]) for i in range(1000)}
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
21 |
|
22 |
-
|
23 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from textblob import TextBlob
|
|
|
3 |
|
4 |
+
def analyze_sentiment(text):
|
5 |
+
blob = TextBlob(text)
|
6 |
+
sentiment = blob.sentiment.polarity
|
7 |
+
if sentiment > 0:
|
8 |
+
color = "green"
|
9 |
+
label = "Positive"
|
10 |
+
elif sentiment < 0:
|
11 |
+
color = "red"
|
12 |
+
label = "Negative"
|
13 |
+
else:
|
14 |
+
color = "yellow"
|
15 |
+
label = "Neutral"
|
16 |
+
return color, label
|
17 |
|
18 |
+
def sentiment_analysis(text):
|
19 |
+
color, label = analyze_sentiment(text)
|
20 |
+
return "<h2 style='color:{}; text-align:center;'>{} Sentiment</h2>".format(color, label)
|
|
|
|
|
21 |
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=sentiment_analysis,
|
24 |
+
inputs=gr.inputs.Textbox(lines=5, label="Enter Text"),
|
25 |
+
outputs="html"
|
26 |
+
)
|
27 |
|
28 |
+
iface.launch()
|
|