torileatherman's picture
Update app.py
b4aeeaf
raw
history blame
2.37 kB
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)
predictions_df_url0 = predictions_df['Url'].iloc[0]
predictions_df_url1 = predictions_df['Url'].iloc[1]
predictions_df_url2 = predictions_df['Url'].iloc[2]
predictions_df_urls = [[predictions_df_url0],
[predictions_df_url1],
[predictions_df_url2]]
def article_selection(sentiment):
if sentiment == "Positive":
return predictions_df_urls #f"""The sentence you requested is Positive!"""
elif sentiment == "Negative":
return f"""The sentence you requested is Negative!"""
else:
return f"""The sentence you requested is Neutral!"""
def thanks():
return f"""Thank you for making our model better!"""
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(),
description = description1
)
demo = gr.TabbedInterface([suggestion_demo, manual_label_demo], ["Get recommended news articles", "Help improve our model"])
demo.launch()