|
|
|
from transformers import AutoModelForSequenceClassification |
|
from transformers import TFAutoModelForSequenceClassification |
|
from transformers import AutoTokenizer, AutoConfig |
|
import numpy as np |
|
from scipy.special import softmax |
|
import gradio as gr |
|
|
|
|
|
model_path=f'https://huggingface.co/sotseth/output' |
|
|
|
model=AutoModelForSequenceClassification.from_pretrained(model_path) |
|
|
|
tokenizer=AutoTokenizer.from_pretrained(model_path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
def predict_tweet(tweet): |
|
|
|
inputs = tokenizer(tweet, return_tensors="pt", padding=True) |
|
outputs = model(**inputs) |
|
probs = outputs.logits.softmax(dim=-1) |
|
sentiment_classes = ['Negative', 'Neutral', 'Positive'] |
|
|
|
return {sentiment_classes[i]: float(probs[0, i]) for i in range(len(sentiment_classes))} |
|
|
|
iface=gr.Interface( |
|
fn=predict_tweet, |
|
inputs="text", |
|
outputs="label", |
|
title="Vaccine Sentiment Classifier", |
|
description="Enter your thought on vaccines", |
|
examples=[ |
|
["Vaccines are a game-changer in addressing public health"], |
|
["Vaccines are profit making"], |
|
["Vaccines are dangerous"] |
|
] |
|
|
|
) |
|
|
|
iface.launch(share=True) |
|
|
|
|