File size: 2,398 Bytes
72eb83c
5a1e68a
ee0f9c8
5a1e68a
 
 
72eb83c
ee0f9c8
f9febec
5a1e68a
ee0f9c8
5a1e68a
214b790
5a1e68a
9339185
b2cfdd0
5a1e68a
 
a2607da
 
72eb83c
ee0f9c8
07da643
 
 
 
 
ee0f9c8
 
96e6361
ee0f9c8
5a1e68a
 
fa57fe8
5f80fd8
72eb83c
ee0f9c8
41b9b6a
d709ea9
f9febec
1768336
5ac096b
72eb83c
f9febec
9f388f4
 
 
 
 
 
cfc8c76
8d86263
a91c119
72eb83c
d7a183e
 
 
f23cf26
d7a183e
 
f23cf26
72eb83c
bb65b06
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
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(server_port=8000)