-
Notifications
You must be signed in to change notification settings - Fork 0
/
link.py
161 lines (141 loc) · 5.23 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import streamlit as st
from flask import Flask, request, jsonify
from flask_cors import CORS
app = Flask(__name__)
CORS(app) # 모든 경로에 대해 CORS를 허용합니다.
# 데이터를 저장할 변수
stored_data = {}
# 업데이트 데이터를 처리하는 엔드포인트
@app.route('/update_data', methods=['POST'])
def update_data():
try:
data = request.get_json()
global stored_data
# 기존 데이터에 추가
stored_data.update(data)
return jsonify({'message': 'Data received and updated successfully.'})
except Exception as e:
return jsonify({'error': str(e)})
# Streamlit 앱
def main():
st.title('Streamlit App')
# 저장된 데이터를 출력
st.write('Stored Data:', stored_data)
if __name__ == '__main__':
main()
# 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]))