Spaces:
Runtime error
Runtime error
Nathan Luskey
commited on
Commit
·
c8de989
1
Parent(s):
edc005c
incorporated tweetnlp
Browse files- README.md +1 -1
- app.py +21 -4
- py_env.yaml +15 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Twitter Sentiment
|
3 |
-
emoji:
|
4 |
colorFrom: blue
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
title: Twitter Sentiment
|
3 |
+
emoji: 🐦
|
4 |
colorFrom: blue
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
app.py
CHANGED
@@ -1,7 +1,24 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
def
|
4 |
-
return "Hello " + name + "!!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from tweetnlp import Sentiment
|
3 |
|
4 |
+
def classify(tweet):
|
5 |
+
# return "Hello " + name + "!!"
|
6 |
+
model_output = model.sentiment(tweet)
|
7 |
+
# Fill in both positive and negative values
|
8 |
+
if model_output["label"] == "positive":
|
9 |
+
formatted_output = dict()
|
10 |
+
formatted_output["positive"] = model_output["probability"]
|
11 |
+
formatted_output["negative"] = 1 - model_output["probability"]
|
12 |
+
else:
|
13 |
+
formatted_output = dict()
|
14 |
+
formatted_output["negative"] = model_output["probability"]
|
15 |
+
formatted_output["positive"] = 1 - model_output["probability"]
|
16 |
+
return formatted_output
|
17 |
|
18 |
+
|
19 |
+
|
20 |
+
if __name__ == "__main__":
|
21 |
+
# https://github.com/cardiffnlp/tweetnlp
|
22 |
+
model = Sentiment()
|
23 |
+
iface = gr.Interface(fn=classify, inputs="text", outputs="label")
|
24 |
+
iface.launch()
|
py_env.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# # Create conda environemnt
|
2 |
+
# conda env create -f py_env.yaml
|
3 |
+
|
4 |
+
# # Update Conda environement
|
5 |
+
# conda env update -f py_env.yaml --prune
|
6 |
+
|
7 |
+
name: twitter_env
|
8 |
+
channels:
|
9 |
+
- conda-forge
|
10 |
+
- defaults
|
11 |
+
dependencies:
|
12 |
+
- pip
|
13 |
+
- pip:
|
14 |
+
- gradio
|
15 |
+
- tweetnlp
|