-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlink.py
129 lines (116 loc) · 4.21 KB
/
link.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import numpy as np
import pandas as pd
import streamlit as st
json_data = [
{'title' : '제목입니다.',
'summary' : '이렇궁저렇궁이렇궁저렇궁',
'keyword' : ['CS', 'Khuda', '이렇궁'],
'url' : 'https://velog.io/@so_yeong',
'img' : 'img_link'
},
{
'title' : '제목입니다.1',
'summary' : '이렇궁저렇궁이렇궁저렇궁1',
'keyword' : ['CS1', 'Khuda1', '머신러닝'],
'url' : 'https://velog.io/@so_yeong',
'img' : 'img_link'
},
{
'title' : '제목입니다.1',
'summary' : '이렇궁저렇궁이렇궁저렇궁1',
'keyword' : ['AI', 'Khuda1', '이렇궁1'],
'url' : 'https://velog.io/@so_yeong',
'img' : 'img_link'
},
{
'title' : '제목입니다.1',
'summary' : '이렇궁저렇궁이렇궁저렇궁1',
'keyword' : ['AI', 'Khuda1', '이렇궁1'],
'url' : 'https://velog.io/@so_yeong',
'img' : 'img_link'
},
{
'title' : '제목입니다.1',
'summary' : '이렇궁저렇궁이렇궁저렇궁1',
'keyword' : ['AI', 'Khuda1', '이렇궁1'],
'url' : 'https://velog.io/@so_yeong',
'img' : 'img_link'
},
{
'title' : '제목입니다.1',
'summary' : '이렇궁저렇궁이렇궁저렇궁1',
'keyword' : ['AI', 'Khuda1', '이렇궁1'],
'url' : 'https://velog.io/@so_yeong',
'img' : 'img_link'
},
{
'title' : '제목입니다.1',
'summary' : '이렇궁저렇궁이렇궁저렇궁1',
'keyword' : ['AI', 'Khuda1', '이렇궁1'],
'url' : 'https://velog.io/@so_yeong',
'img' : 'img_link'
},
{
'title' : '제목입니다.1',
'summary' : '이렇궁저렇궁이렇궁저렇궁1',
'keyword' : ['AI', 'Khuda1', '이렇궁1'],
'url' : 'https://velog.io/@so_yeong',
'img' : 'img_link'
},
]
url = 'https://velog.io/@so_yeong'
df = pd.DataFrame(json_data)
def truncate_text(text, max_length = 50):
if len(text) <= max_length:
return text
else:
return text[:max_length-3] + "..."
st.title('LINK')
st.caption('Link Is Not Kind')
# 'keyword' 필드의 요소들을 중복 없이 추출
tag_list = list({keyword for entry in json_data for keyword in entry['keyword']})
select = st.multiselect(
'Select Keywords',
tag_list)
if select:
filtered_df = df[df['keyword'].apply(lambda x: any(keyword in x for keyword in select))]
url_cnt = len(filtered_df)
col1, col2, col3 = st.columns(3)
with col1:
for i in range(0, url_cnt, 3):
with st.container():
st.image("img/test_img.png", width=220, use_column_width=100)
st.write(f'**[{filtered_df["title"].iloc[i]}]({url})**')
st.write(truncate_text(filtered_df['summary'].iloc[i]))
with col2:
for i in range(1, url_cnt, 3):
with st.container():
st.image("img/test_img.png", width=220, use_column_width=100)
st.write(f'**[{filtered_df["title"].iloc[i]}]({url})**')
st.write(truncate_text(filtered_df['summary'].iloc[i]))
with col3:
for i in range(2, url_cnt, 3):
with st.container():
st.image("img/test_img.png", width=220, use_column_width=100)
st.write(f'**[{filtered_df["title"].iloc[i]}]({url})**')
st.write(truncate_text(filtered_df['summary'].iloc[i]))
else:
col1, col2, col3 = st.columns(3)
with col1:
for i in range(0, len(df), 3):
with st.container():
st.image("img/test_img.png", width=220, use_column_width=100)
st.write(f'**[{df["title"].iloc[i]}]({url})**')
st.write(truncate_text(df['summary'].iloc[i]))
with col2:
for i in range(1, len(df), 3):
with st.container():
st.image("img/test_img.png", width=220, use_column_width=100)
st.write(f'**[{df["title"].iloc[i]}]({url})**')
st.write(truncate_text(df['summary'].iloc[i]))
with col3:
for i in range(2, len(df), 3):
with st.container():
st.image("img/test_img.png", width=220, use_column_width=100)
st.write(f'**[{df["title"].iloc[i]}]({url})**')
st.write(truncate_text(df['summary'].iloc[i]))