-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
68 lines (53 loc) · 1.98 KB
/
streamlit_app.py
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
from collections import namedtuple
import altair as alt
import math
import pandas as pd
import streamlit as st
import json
import base64
from urllib.request import urlopen
from PIL import Image
import random
import numpy as np
st.set_page_config(
layout="wide", page_title="MLFix & Chill!"
)
"""
# MLFlix & Chill!
"""
df_all = pd.read_csv("videos.csv")
st.container()
col1, col2 = st.columns(2)
#col1.subheader('Col1')
#col1.subheader('Col2')
names = df_all["snippet.channelTitle"].unique()
for name in random.sample(list(names), 5):
with st.expander(name):
df = df_all[df_all["snippet.channelTitle"]==name]
df.reset_index(inplace=True)
header = """
| Image | Description |
| --------- | ----------- |
"""
rows = ""
for i in range(0,len(df)):
url = df["snippet.thumbnails.medium.url"][i]
image_base64 = base64.b64encode(urlopen(url).read()).decode('utf-8')
#img = Image.open(urlopen(url))
#name =st.text(df["snippet.channelTitle"][i])
#st.text(df["snippet.description"][i])
description = df["snippet.description"][i]
if(len(str(description))>3):
#print(len(str(description)))
split = " "
des_list= description.split(split)
if(len(des_list)>200):
description= split.join(des_list[0:200])
elif(np.isnan(float(description))):
description = ""
link = url = "http://www.youtube.com/watch?v="+df["id.videoId"][i]
image = f"<a href='{link}' target=”_blank”><img src='data:image/png;base64,{image_base64}'></a>"
description = f"<a href='{link}' target=”_blank”>{description}</a>"
rows += f"| {image} | {description} |\n"
html = header + rows
st.markdown(html, unsafe_allow_html=True)