Nathan Luskey
incorporated tweetnlp
c8de989
raw
history blame
812 Bytes
import gradio as gr
from tweetnlp import Sentiment
def classify(tweet):
# return "Hello " + name + "!!"
model_output = model.sentiment(tweet)
# Fill in both positive and negative values
if model_output["label"] == "positive":
formatted_output = dict()
formatted_output["positive"] = model_output["probability"]
formatted_output["negative"] = 1 - model_output["probability"]
else:
formatted_output = dict()
formatted_output["negative"] = model_output["probability"]
formatted_output["positive"] = 1 - model_output["probability"]
return formatted_output
if __name__ == "__main__":
# https://github.com/cardiffnlp/tweetnlp
model = Sentiment()
iface = gr.Interface(fn=classify, inputs="text", outputs="label")
iface.launch()