Spaces:
Running
Running
# import sklearn | |
from os import O_ACCMODE | |
import gradio as gr | |
import joblib | |
from transformers import pipeline | |
import requests.exceptions | |
from huggingface_hub import HfApi, hf_hub_download | |
from huggingface_hub.repocard import metadata_load | |
app = gr.Blocks() | |
model_id_1 = "nlptown/bert-base-multilingual-uncased-sentiment" | |
model_id_2 = "microsoft/deberta-base" | |
model_id_3 = "distilbert-base-uncased-finetuned-sst-2-english" | |
model_id_4 = "lordtt13/emo-mobilebert" | |
model_id_5 = "juliensimon/reviews-sentiment-analysis" | |
def get_prediction(model_id): | |
classifier = pipeline("text-classification", model=model_id, return_all_scores=True) | |
def predict(review): | |
prediction = classifier(review) | |
print(prediction) | |
return prediction | |
return predict | |
with app: | |
gr.Markdown( | |
""" | |
# Compare Sentiment Analysis Models | |
Type text to predict sentiment. | |
""") | |
with gr.Row(): | |
inp_1= gr.Textbox(label="Type text here.",placeholder="The customer service was satisfactory.") | |
gr.Markdown( | |
""" | |
**Model Predictions** | |
""") | |
with gr.Row(): | |
with gr.Column(): | |
text1 = gr.Textbox(label="Model 1 = nlptown/bert-base-multilingual-uncased-sentiment") | |
btn1 = gr.Button("Predict - Model 1") | |
text2 = gr.Textbox(label="Model 2 = microsoft/deberta-base") | |
btn2 = gr.Button("Predict - Model 2") | |
with gr.Column(): | |
out_1 = gr.Textbox(label="Predictions for Model 1") | |
out_2 = gr.Textbox(label="Predictions for Model 2") | |
btn1.click(fn=get_prediction(model_id_1), inputs=inp_1, outputs=out_1) | |
btn2.click(fn=get_prediction(model_id_2), inputs=inp_1, outputs=out_2) | |
app.launch() |