SamuelHarner's picture
Update app.py
995b250 verified
import hopsworks
import pandas as pd
import gradio as gr
from datetime import datetime
today = datetime.now().strftime('%Y-%m-%d')
# Get data
project = hopsworks.login()
fs = project.get_feature_store()
dataset_api = project.get_dataset_api()
most_positive_fg = fs.get_feature_group(name="articles_most_positive", version=1)
most_positive_df = most_positive_fg.read()
#most_positive_df = most_positive_df[most_positive_df['pubdate'] == today]
most_positive_article = most_positive_df.iloc[-1] # get most recent most positive article (in case today's failed)
# Get images
dataset_api.download("Resources/images/average_sentiment_timeline.png")
dataset_api.download("Resources/images/most_positive_timeline.png")
if most_positive_article['pubdate'] == today: # show image generated for today's article
try:
dataset_api.download("Resources/images/news_image.png")
news_img = 'news_image.png'
except:
news_img = 'https://raw.githubusercontent.com/SamuelHarner/app-images/main/images/delight-news-logo.png?raw=true'
else:
news_img = 'https://raw.githubusercontent.com/SamuelHarner/app-images/main/images/delight-news-logo.png?raw=true'
# Get content
news_headline = most_positive_article["title"]
news_source = most_positive_article["source_id"]
news_description = most_positive_article["description"]
news_link = most_positive_article["link"]
# Create UI
with gr.Blocks(theme=gr.themes.Default(font=[gr.themes.GoogleFont("IBM Plex Mono"), "Arial", "sans-serif"])) as demo:
gr.Markdown("<div align='center'><h1>The Delight Dispatch โ˜€๏ธ๐Ÿ—ž๏ธ</h1></div")
gr.Markdown("## Today's News: " + news_headline)
gr.Markdown(news_description)
gr.Markdown("Reported by: " + news_source)
with gr.Row():
with gr.Column():
pass
with gr.Column():
gr.Image(news_img, elem_id="news-img")
with gr.Column():
pass
with gr.Row():
gr.Markdown("Read the full article here: " + news_link)
with gr.Row():
with gr.Column():
gr.Label("Average Sentiment History of News in General")
gr.Image("average_sentiment_timeline.png", elem_id="general-history")
with gr.Column():
gr.Label("Sentiment History of News on this Demo")
gr.Image("most_positive_timeline.png", elem_id="demo-history")
demo.launch()