Twitter_nlp / app.py
gamza's picture
Create app.py
8fe0112
raw
history blame
863 Bytes
import gradio as gr
from keras.models import load_model
import pickle
import torch
import numpy as np
import pandas as pd
from utils import test_sentences
model = torch.load('bert_classification(0.87).pt')
# Gradio ์ธํ„ฐํŽ˜์ด์Šค์—์„œ ์‚ฌ์šฉํ•  ํ•จ์ˆ˜ ์ •์˜
def predict_sentiment(text):
logit = test_sentences([text], model)
sent = np.argmax(logit)
classes = {0: "์ค‘๋ฆฝ", 1:"๊ธ์ •", 2:"๋ถ€์ •"}
sentiment = classes[sent]
return sentiment
title = "๐Ÿคทโ€โ™€๏ธ๐Ÿคทโ€โ™‚๏ธWhat is the EMOTION of TWEETโ”"
description = "โ–ถํŠธ์œ„ํ„ฐ ๊ฐ์ • ์•Œ์•„๋ณด๊ธฐ"
tweet = gr.Interface(
fn=predict_sentiment,
inputs=gr.inputs.Textbox(placeholder="Enter tweet here..."),
outputs=gr.outputs.Textbox(label="Sentiment Prediction"),
title=title,
theme="finlaymacklon/boxy_violet",
description=description
)
tweet.launch(share=True)