Spaces:
Runtime error
Runtime error
import gradio as gr | |
import hopsworks | |
from datasets import load_dataset | |
import pandas as pd | |
project = hopsworks.login() | |
fs = project.get_feature_store() | |
dataset_api = project.get_dataset_api() | |
dataset = load_dataset("torileatherman/sentiment_analysis_batch_predictions", split='train') | |
predictions_df = pd.DataFrame(dataset) | |
grouped_predictions = predictions_df.groupby(predictions_df.Sentiment) | |
positive_preds = grouped_predictions.get_group(2) | |
neutral_preds = grouped_predictions.get_group(1) | |
negative_preds = grouped_predictions.get_group(0) | |
def article_selection(sentiment): | |
if sentiment == "Positive": | |
predictions = positive_preds | |
predictions_urls = predictions['Url'][0:3] | |
return predictions_urls | |
elif sentiment == "Negative": | |
predictions = negative_preds | |
predictions_urls = predictions['Url'][0:3] | |
return predictions_urls | |
else: | |
predictions = neutral_preds | |
predictions_urls = predictions['Url'][0:3] | |
return predictions_urls | |
def thanks(url, sentiment): | |
thanks_text = "Thank you for making our model better!" | |
return thanks_text | |
description1 = ''' | |
This application recommends news articles depending on the sentiment of the headline. | |
Enter your preference of what type of news articles you would like recommended to you today: Positive, Negative, or Neutral. | |
''' | |
description2 = ''' | |
This application recommends news articles depending on the sentiment of the headline. | |
Enter a news article url and its sentiment to help us improve our model. | |
The more data we have, the better news articles we can recommend to you! | |
''' | |
suggestion_demo = gr.Interface( | |
fn=article_selection, | |
title = 'Recommending News Articles', | |
inputs = gr.Dropdown(["Positive","Negative","Neutral"], label="What type of news articles would you like recommended?"), | |
outputs = gr.Textbox(label="Recommended News Articles", lines=3), | |
description = description1 | |
) | |
manual_label_demo = gr.Interface( | |
fn=thanks, | |
title="Manually Label a News Article", | |
inputs=[gr.Textbox(label = "Paste in URL of news article here."), | |
gr.Dropdown(["Positive","Negative","Neutral"], label="Select the sentiment of the news article.")], | |
outputs = gr.Textbox(label="Output"), | |
description = description2 | |
) | |
demo = gr.TabbedInterface([suggestion_demo, manual_label_demo], ["Get recommended news articles", "Help improve our model"]) | |
demo.launch() |