Spaces:
Sleeping
Sleeping
File size: 1,076 Bytes
a686fbb 779ab42 a686fbb 50bf1f2 a686fbb 779ab42 1399382 a686fbb 7e46f4b 1359230 7e46f4b 1359230 a686fbb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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() |