import gradio as gr import transformers import nltk from nltk.sentiment import SentimentIntensityAnalyzer # Download the VADER lexicon nltk.download('vader_lexicon') # Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="rohanphadke/roberta-finetuned-adjusted-triplebottomline", top_k=None) def greet(news): sia = SentimentIntensityAnalyzer() def convert_to_dict(predictions): result_dict = {} # Assuming predictions is a list of lists of dictionaries for prediction_list in predictions: for item in prediction_list: label = item['label'] score = item['score'] result_dict[label] = score return result_dict tbl_dict = convert_to_dict(pipe(news)) sia_score = sia.polarity_scores(news) return str(tbl_dict['people']), str(tbl_dict['planet']), str(tbl_dict['profit']), str(sia_score['compound']) demo = gr.Interface(fn=greet, inputs="text", outputs=["text", "text", "text", "text"]) demo.launch()