Spaces:
Runtime error
Runtime error
File size: 3,016 Bytes
11dc9a8 adec7fa 7485bd9 7f33b70 adec7fa a3d5133 ab2c9b6 040c0c0 ab2c9b6 11dc9a8 040c0c0 e68deab 378829d ab2c9b6 e68deab 378829d 040c0c0 e68deab adec7fa 6153bc6 5a265b2 92533eb b4aeeaf 3c22553 adec7fa b4aeeaf 92533eb 11dc9a8 92533eb 6311754 e68deab b4aeeaf 11dc9a8 92533eb 0551e7e 5a265b2 ab2c9b6 92533eb 11dc9a8 ce4abb2 11dc9a8 |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
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 = negative_preds
predictions_df_url0 = predictions['Url'].iloc[0]
predictions_df_url1 = predictions['Url'].iloc[1]
predictions_df_url2 = predictions['Url'].iloc[2]
return predictions_df_url0, predictions_df_url1, predictions_df_url2
elif sentiment == "Negative":
predictions = negative_preds
predictions_df_url0 = predictions['Url'].iloc[0]
predictions_df_url1 = predictions['Url'].iloc[1]
predictions_df_url2 = predictions['Url'].iloc[2]
return predictions_df_url0, predictions_df_url1, predictions_df_url2
else:
predictions = negative_preds
predictions_df_url0 = predictions['Url'].iloc[0]
predictions_df_url1 = predictions['Url'].iloc[1]
predictions_df_url2 = predictions['Url'].iloc[2]
return predictions_df_url0, predictions_df_url1, predictions_df_url2
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"),gr.Textbox(),gr.Textbox()]
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() |