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'sotseth/output' model_path=f'https://huggingface.co/sotseth/output' model=AutoModelForSequenceClassification.from_pretrained(model_path) #tokenizer=AutoTokenizer.from_pretrained(f"cardiffnlp/twitter-roberta-base-sentiment-latest") tokenizer=AutoTokenizer.from_pretrained(model_path) #from huggingface_hub import notebook_login #notebook_login() #tokenizer.push_to_hub('sotseth/output') 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)