Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,158 +3,339 @@ import requests
|
|
3 |
import os
|
4 |
import json
|
5 |
from datetime import timedelta
|
6 |
-
import logging
|
7 |
-
|
8 |
-
# ๋ก๊น
์ค์
|
9 |
-
logging.basicConfig(level=logging.DEBUG,
|
10 |
-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
11 |
-
logger = logging.getLogger(__name__)
|
12 |
|
13 |
app = Flask(__name__)
|
14 |
app.secret_key = os.urandom(24) # ์ธ์
์ํธํ๋ฅผ ์ํ ๋น๋ฐ ํค
|
15 |
app.permanent_session_lifetime = timedelta(days=7) # ์ธ์
์ ์ง ๊ธฐ๊ฐ ์ค์
|
16 |
|
17 |
-
# ํ๊น
ํ์ด์ค URL ๋ชฉ๋ก
|
18 |
HUGGINGFACE_URLS = [
|
19 |
"https://huggingface.co/spaces/ginipick/Tech_Hangman_Game",
|
20 |
"https://huggingface.co/spaces/openfree/deepseek_r1_API",
|
21 |
-
"https://huggingface.co/spaces/ginipick/open_Deep-Research"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
]
|
23 |
|
24 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
def validate_token(token):
|
26 |
-
logger.debug(f"ํ ํฐ ๊ฒ์ฆ ์๋ (ํ ํฐ ์ผ๋ถ: {token[:4]}...)")
|
27 |
headers = {"Authorization": f"Bearer {token}"}
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
-
"https://huggingface.co/api/whoami",
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
]
|
34 |
|
35 |
-
|
|
|
|
|
36 |
try:
|
37 |
-
|
38 |
-
response = requests.get(endpoint, headers=headers)
|
39 |
-
|
40 |
-
# ์๋ต ๋ก๊น
|
41 |
-
logger.debug(f"API ์๋ต ์ํ ์ฝ๋: {response.status_code}")
|
42 |
-
logger.debug(f"API ์๋ต ํค๋: {response.headers}")
|
43 |
-
|
44 |
if response.ok:
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
except Exception as e:
|
50 |
-
|
51 |
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
#
|
56 |
-
@app.route('/
|
57 |
-
def
|
|
|
|
|
|
|
|
|
|
|
58 |
token = request.form.get('token', '')
|
59 |
|
60 |
if not token:
|
61 |
return jsonify({'success': False, 'message': 'ํ ํฐ์ ์
๋ ฅํด์ฃผ์ธ์.'})
|
62 |
|
63 |
-
|
64 |
-
debug_info = {}
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
debug_info['token_format'] = 'hf_ ์ ๋์ฌ ์์' if is_valid_format else '์ ๋์ฌ ์์'
|
69 |
|
70 |
-
#
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
|
|
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
endpoint_results[endpoint] = {
|
85 |
-
'status_code': response.status_code,
|
86 |
-
'success': response.ok,
|
87 |
-
'content_type': response.headers.get('Content-Type', 'unknown'),
|
88 |
-
'response_sample': str(response.text)[:100] + '...' if response.text else 'Empty response'
|
89 |
-
}
|
90 |
-
except Exception as e:
|
91 |
-
endpoint_results[endpoint] = {'error': str(e)}
|
92 |
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
return jsonify({
|
99 |
-
'
|
100 |
-
'
|
101 |
-
'
|
102 |
})
|
103 |
|
104 |
-
# ๊ธฐ๋ณธ ํํ์ด์ง (๋๋ฒ๊น
ํ๋ฉด ํฌํจ)
|
105 |
-
@app.route('/')
|
106 |
-
def home():
|
107 |
-
return render_template('debug_index.html')
|
108 |
-
|
109 |
if __name__ == '__main__':
|
110 |
# templates ํด๋ ์์ฑ
|
111 |
os.makedirs('templates', exist_ok=True)
|
112 |
|
113 |
-
#
|
114 |
-
with open('templates/
|
115 |
f.write('''
|
116 |
<!DOCTYPE html>
|
117 |
<html lang="ko">
|
118 |
<head>
|
119 |
<meta charset="UTF-8">
|
120 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
121 |
-
<title
|
122 |
<style>
|
123 |
body {
|
124 |
font-family: Arial, sans-serif;
|
125 |
line-height: 1.6;
|
126 |
margin: 0;
|
127 |
-
padding:
|
128 |
-
color: #333;
|
129 |
-
}
|
130 |
-
|
131 |
-
h1, h2 {
|
132 |
color: #333;
|
133 |
}
|
134 |
|
135 |
.container {
|
136 |
-
max-width:
|
137 |
margin: 0 auto;
|
|
|
138 |
}
|
139 |
|
140 |
-
.
|
141 |
-
|
|
|
142 |
border-radius: 5px;
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
}
|
147 |
|
148 |
-
input[type="password"]
|
149 |
-
|
150 |
-
padding:
|
151 |
-
margin: 10px 0;
|
152 |
border: 1px solid #ccc;
|
153 |
border-radius: 4px;
|
|
|
154 |
}
|
155 |
|
156 |
button {
|
157 |
-
padding:
|
158 |
background-color: #4CAF50;
|
159 |
color: white;
|
160 |
border: none;
|
@@ -166,10 +347,75 @@ if __name__ == '__main__':
|
|
166 |
background-color: #45a049;
|
167 |
}
|
168 |
|
169 |
-
.
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
border-radius: 5px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
display: none;
|
174 |
}
|
175 |
|
@@ -183,116 +429,376 @@ if __name__ == '__main__':
|
|
183 |
color: #a94442;
|
184 |
}
|
185 |
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
}
|
193 |
|
194 |
-
.
|
|
|
|
|
|
|
|
|
195 |
display: none;
|
196 |
-
margin-top:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
}
|
198 |
</style>
|
199 |
</head>
|
200 |
<body>
|
201 |
<div class="container">
|
202 |
-
<
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
<
|
219 |
</div>
|
220 |
</div>
|
221 |
</div>
|
222 |
|
223 |
-
<div class="
|
224 |
-
<
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
<
|
230 |
-
|
231 |
-
</ul>
|
232 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
</div>
|
234 |
|
235 |
<script>
|
236 |
-
// ์์ ์ฐธ์กฐ
|
237 |
-
const
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
|
248 |
-
|
249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
return;
|
251 |
}
|
252 |
|
253 |
-
|
254 |
-
loading.style.display = 'block';
|
255 |
-
result.style.display = 'none';
|
256 |
|
257 |
try {
|
258 |
-
// FormData ์์ฑ
|
259 |
const formData = new FormData();
|
260 |
formData.append('token', token);
|
261 |
|
262 |
-
|
263 |
-
const response = await fetch('/api/test-token', {
|
264 |
method: 'POST',
|
265 |
body: formData
|
266 |
});
|
267 |
|
268 |
-
const data = await response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
} catch (error) {
|
276 |
-
|
277 |
-
|
278 |
-
resultDetails.textContent = error.stack || '์์ธ ์ ๋ณด ์์';
|
279 |
-
result.style.display = 'block';
|
280 |
} finally {
|
281 |
-
|
282 |
}
|
283 |
}
|
284 |
|
285 |
-
//
|
286 |
-
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
if (event.key === 'Enter') {
|
289 |
-
|
290 |
}
|
291 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
</script>
|
293 |
</body>
|
294 |
</html>
|
295 |
''')
|
296 |
|
297 |
# ํ๊น
ํ์ด์ค ์คํ์ด์ค์์๋ 7860 ํฌํธ ์ฌ์ฉ
|
298 |
-
app.run(host='0.0.0.0', port=7860
|
|
|
3 |
import os
|
4 |
import json
|
5 |
from datetime import timedelta
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
app.secret_key = os.urandom(24) # ์ธ์
์ํธํ๋ฅผ ์ํ ๋น๋ฐ ํค
|
9 |
app.permanent_session_lifetime = timedelta(days=7) # ์ธ์
์ ์ง ๊ธฐ๊ฐ ์ค์
|
10 |
|
11 |
+
# ํ๊น
ํ์ด์ค URL ๋ชฉ๋ก
|
12 |
HUGGINGFACE_URLS = [
|
13 |
"https://huggingface.co/spaces/ginipick/Tech_Hangman_Game",
|
14 |
"https://huggingface.co/spaces/openfree/deepseek_r1_API",
|
15 |
+
"https://huggingface.co/spaces/ginipick/open_Deep-Research",
|
16 |
+
"https://huggingface.co/spaces/aiqmaster/open-deep-research",
|
17 |
+
"https://huggingface.co/spaces/seawolf2357/DeepSeek-R1-32b-search",
|
18 |
+
"https://huggingface.co/spaces/ginigen/LLaDA",
|
19 |
+
"https://huggingface.co/spaces/VIDraft/PHI4-Multimodal",
|
20 |
+
"https://huggingface.co/spaces/ginigen/Ovis2-8B",
|
21 |
+
"https://huggingface.co/spaces/ginigen/Graph-Mind",
|
22 |
+
"https://huggingface.co/spaces/ginigen/Workflow-Canvas",
|
23 |
+
"https://huggingface.co/spaces/ginigen/Design",
|
24 |
+
"https://huggingface.co/spaces/ginigen/Diagram",
|
25 |
+
"https://huggingface.co/spaces/ginigen/Mockup",
|
26 |
+
"https://huggingface.co/spaces/ginigen/Infographic",
|
27 |
+
"https://huggingface.co/spaces/ginigen/Flowchart",
|
28 |
+
"https://huggingface.co/spaces/aiqcamp/FLUX-Vision",
|
29 |
+
"https://huggingface.co/spaces/ginigen/VoiceClone-TTS",
|
30 |
+
"https://huggingface.co/spaces/openfree/Perceptron-Network",
|
31 |
+
"https://huggingface.co/spaces/openfree/Article-Generator",
|
32 |
]
|
33 |
|
34 |
+
# URL์์ ๋ชจ๋ธ/์คํ์ด์ค ์ ๋ณด ์ถ์ถ
|
35 |
+
def extract_model_info(url):
|
36 |
+
parts = url.split('/')
|
37 |
+
if len(parts) < 6:
|
38 |
+
return None
|
39 |
+
|
40 |
+
if parts[3] == 'spaces' or parts[3] == 'models':
|
41 |
+
return {
|
42 |
+
'type': parts[3],
|
43 |
+
'owner': parts[4],
|
44 |
+
'repo': parts[5],
|
45 |
+
'full_id': f"{parts[4]}/{parts[5]}"
|
46 |
+
}
|
47 |
+
elif len(parts) >= 5:
|
48 |
+
# ๋ค๋ฅธ ํ์์ URL
|
49 |
+
return {
|
50 |
+
'type': 'models', # ๊ธฐ๋ณธ๊ฐ
|
51 |
+
'owner': parts[3],
|
52 |
+
'repo': parts[4],
|
53 |
+
'full_id': f"{parts[3]}/{parts[4]}"
|
54 |
+
}
|
55 |
+
|
56 |
+
return None
|
57 |
+
|
58 |
+
# URL์ ๋ง์ง๋ง ๋ถ๋ถ์ ์ ๋ชฉ์ผ๋ก ์ถ์ถ
|
59 |
+
def extract_title(url):
|
60 |
+
parts = url.split("/")
|
61 |
+
title = parts[-1] if parts else ""
|
62 |
+
return title.replace("_", " ").replace("-", " ")
|
63 |
+
|
64 |
+
# ํ๊น
ํ์ด์ค ์ธ์ฆ ํ์ธ - ์์ ๋ ๋ฒ์
|
65 |
def validate_token(token):
|
|
|
66 |
headers = {"Authorization": f"Bearer {token}"}
|
67 |
|
68 |
+
# ์์ : ํ
์คํธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํ์ผ๋ก whoami-v2 ์๋ํฌ์ธํธ ๋จผ์ ์๋
|
69 |
+
try:
|
70 |
+
response = requests.get("https://huggingface.co/api/whoami-v2", headers=headers)
|
71 |
+
if response.ok:
|
72 |
+
return True, response.json()
|
73 |
+
except Exception as e:
|
74 |
+
print(f"whoami-v2 ํ ํฐ ๊ฒ์ฆ ์ค๋ฅ: {e}")
|
75 |
+
|
76 |
+
# ๊ธฐ์กด whoami ์๋ํฌ์ธํธ๋ ์๋
|
77 |
+
try:
|
78 |
+
response = requests.get("https://huggingface.co/api/whoami", headers=headers)
|
79 |
+
if response.ok:
|
80 |
+
return True, response.json()
|
81 |
+
except Exception as e:
|
82 |
+
print(f"whoami ํ ํฐ ๊ฒ์ฆ ์ค๋ฅ: {e}")
|
83 |
+
|
84 |
+
return False, None
|
85 |
+
|
86 |
+
# ์ข์์ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ
|
87 |
+
def get_liked_repos(token):
|
88 |
+
headers = {"Authorization": f"Bearer {token}"}
|
89 |
+
endpoints = [
|
90 |
+
"/api/me/likes",
|
91 |
+
"/api/me/liked-repos",
|
92 |
+
"/api/me/favorites"
|
93 |
]
|
94 |
|
95 |
+
liked_models = {}
|
96 |
+
|
97 |
+
for endpoint in endpoints:
|
98 |
try:
|
99 |
+
response = requests.get(f"https://huggingface.co{endpoint}", headers=headers)
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
if response.ok:
|
101 |
+
data = response.json()
|
102 |
+
if isinstance(data, list):
|
103 |
+
for model in data:
|
104 |
+
if isinstance(model, dict):
|
105 |
+
if 'owner' in model and 'name' in model:
|
106 |
+
liked_models[f"{model['owner']}/{model['name']}"] = True
|
107 |
+
elif 'id' in model:
|
108 |
+
liked_models[model['id']] = True
|
109 |
+
elif isinstance(data, dict):
|
110 |
+
for key in data:
|
111 |
+
liked_models[key] = True
|
112 |
+
|
113 |
+
print(f"์ข์์ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ ์ฑ๊ณต (์๋ํฌ์ธํธ: {endpoint})")
|
114 |
+
return liked_models
|
115 |
except Exception as e:
|
116 |
+
print(f"์ข์์ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ ์ค๋ฅ (์๋ํฌ์ธํธ: {endpoint}): {e}")
|
117 |
|
118 |
+
return liked_models
|
119 |
+
|
120 |
+
# ์ข์์ ํ ๊ธ API ํธ์ถ
|
121 |
+
def toggle_like(token, type_name, owner, repo, is_liked):
|
122 |
+
headers = {"Authorization": f"Bearer {token}"}
|
123 |
+
normalized_type = "spaces" if type_name == "spaces" else "models"
|
124 |
+
method = "DELETE" if is_liked else "POST"
|
125 |
+
url = f"https://huggingface.co/api/{normalized_type}/{owner}/{repo}/like"
|
126 |
+
|
127 |
+
try:
|
128 |
+
if method == "DELETE":
|
129 |
+
response = requests.delete(url, headers=headers)
|
130 |
+
else:
|
131 |
+
response = requests.post(url, headers=headers)
|
132 |
+
|
133 |
+
return response.ok, response.status_code
|
134 |
+
except Exception as e:
|
135 |
+
print(f"์ข์์ ํ ๊ธ ์ค๋ฅ: {e}")
|
136 |
+
return False, 500
|
137 |
|
138 |
+
# ํํ์ด์ง ๋ผ์ฐํธ
|
139 |
+
@app.route('/')
|
140 |
+
def home():
|
141 |
+
return render_template('index.html')
|
142 |
+
|
143 |
+
# ๋ก๊ทธ์ธ ์ฒ๋ฆฌ API
|
144 |
+
@app.route('/api/login', methods=['POST'])
|
145 |
+
def login():
|
146 |
token = request.form.get('token', '')
|
147 |
|
148 |
if not token:
|
149 |
return jsonify({'success': False, 'message': 'ํ ํฐ์ ์
๋ ฅํด์ฃผ์ธ์.'})
|
150 |
|
151 |
+
is_valid, user_info = validate_token(token)
|
|
|
152 |
|
153 |
+
if not is_valid or not user_info:
|
154 |
+
return jsonify({'success': False, 'message': '์ ํจํ์ง ์์ ํ ํฐ์
๋๋ค.'})
|
|
|
155 |
|
156 |
+
# ์ฌ์ฉ์ ์ด๋ฆ ์ฐพ๊ธฐ
|
157 |
+
username = None
|
158 |
+
if 'name' in user_info:
|
159 |
+
username = user_info['name']
|
160 |
+
elif 'user' in user_info and 'username' in user_info['user']:
|
161 |
+
username = user_info['user']['username']
|
162 |
+
elif 'username' in user_info:
|
163 |
+
username = user_info['username']
|
164 |
+
else:
|
165 |
+
username = '์ธ์ฆ๋ ์ฌ์ฉ์'
|
166 |
|
167 |
+
# ์ข์์ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ
|
168 |
+
liked_models = get_liked_repos(token)
|
169 |
|
170 |
+
# ์ธ์
์ ์ ์ฅ
|
171 |
+
session['token'] = token
|
172 |
+
session['username'] = username
|
173 |
+
session['liked_models'] = liked_models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
+
return jsonify({
|
176 |
+
'success': True,
|
177 |
+
'username': username,
|
178 |
+
'liked_models': liked_models
|
179 |
+
})
|
180 |
+
|
181 |
+
# ๋ก๊ทธ์์ ์ฒ๋ฆฌ API
|
182 |
+
@app.route('/api/logout', methods=['POST'])
|
183 |
+
def logout():
|
184 |
+
session.pop('token', None)
|
185 |
+
session.pop('username', None)
|
186 |
+
session.pop('liked_models', None)
|
187 |
+
return jsonify({'success': True})
|
188 |
+
|
189 |
+
# URL ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ API
|
190 |
+
@app.route('/api/urls', methods=['GET'])
|
191 |
+
def get_urls():
|
192 |
+
search_query = request.args.get('search', '').lower()
|
193 |
+
show_only_liked = request.args.get('liked', 'false').lower() == 'true'
|
194 |
+
|
195 |
+
liked_models = session.get('liked_models', {})
|
196 |
+
|
197 |
+
results = []
|
198 |
+
for url in HUGGINGFACE_URLS:
|
199 |
+
title = extract_title(url)
|
200 |
+
model_info = extract_model_info(url)
|
201 |
+
|
202 |
+
if not model_info:
|
203 |
+
continue
|
204 |
+
|
205 |
+
is_liked = model_info['full_id'] in liked_models
|
206 |
+
|
207 |
+
# ํํฐ๋ง ์ ์ฉ
|
208 |
+
if show_only_liked and not is_liked:
|
209 |
+
continue
|
210 |
+
|
211 |
+
if search_query and search_query not in url.lower() and search_query not in title.lower():
|
212 |
+
continue
|
213 |
+
|
214 |
+
results.append({
|
215 |
+
'url': url,
|
216 |
+
'title': title,
|
217 |
+
'model_info': model_info,
|
218 |
+
'is_liked': is_liked
|
219 |
+
})
|
220 |
|
221 |
+
return jsonify(results)
|
222 |
+
|
223 |
+
# ์ข์์ ํ ๊ธ API
|
224 |
+
@app.route('/api/toggle-like', methods=['POST'])
|
225 |
+
def api_toggle_like():
|
226 |
+
if 'token' not in session:
|
227 |
+
return jsonify({'success': False, 'message': '๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค.'})
|
228 |
+
|
229 |
+
data = request.json
|
230 |
+
url = data.get('url')
|
231 |
+
current_liked = data.get('currentLiked', False)
|
232 |
+
|
233 |
+
if not url:
|
234 |
+
return jsonify({'success': False, 'message': 'URL์ด ํ์ํฉ๋๋ค.'})
|
235 |
+
|
236 |
+
model_info = extract_model_info(url)
|
237 |
+
if not model_info:
|
238 |
+
return jsonify({'success': False, 'message': '์ ํจํ์ง ์์ URL์
๋๋ค.'})
|
239 |
+
|
240 |
+
success, status_code = toggle_like(
|
241 |
+
session['token'],
|
242 |
+
model_info['type'],
|
243 |
+
model_info['owner'],
|
244 |
+
model_info['repo'],
|
245 |
+
current_liked
|
246 |
+
)
|
247 |
+
|
248 |
+
liked_models = session.get('liked_models', {})
|
249 |
|
250 |
+
if success:
|
251 |
+
# ์ธ์
์ ์ข์์ ์ํ ์
๋ฐ์ดํธ
|
252 |
+
if current_liked:
|
253 |
+
if model_info['full_id'] in liked_models:
|
254 |
+
del liked_models[model_info['full_id']]
|
255 |
+
else:
|
256 |
+
liked_models[model_info['full_id']] = True
|
257 |
+
|
258 |
+
session['liked_models'] = liked_models
|
259 |
+
|
260 |
+
return jsonify({
|
261 |
+
'success': True,
|
262 |
+
'new_state': not current_liked,
|
263 |
+
'message': f"{'์ข์์ ์ทจ์' if current_liked else '์ข์์'} ์ฑ๊ณต"
|
264 |
+
})
|
265 |
+
else:
|
266 |
+
return jsonify({
|
267 |
+
'success': False,
|
268 |
+
'message': f"API ์ค๋ฅ (์ํ ์ฝ๋: {status_code})"
|
269 |
+
})
|
270 |
+
|
271 |
+
# ์ธ์
์ํ ํ์ธ API
|
272 |
+
@app.route('/api/session-status', methods=['GET'])
|
273 |
+
def session_status():
|
274 |
return jsonify({
|
275 |
+
'logged_in': 'token' in session,
|
276 |
+
'username': session.get('username'),
|
277 |
+
'liked_count': len(session.get('liked_models', {}))
|
278 |
})
|
279 |
|
|
|
|
|
|
|
|
|
|
|
280 |
if __name__ == '__main__':
|
281 |
# templates ํด๋ ์์ฑ
|
282 |
os.makedirs('templates', exist_ok=True)
|
283 |
|
284 |
+
# index.html ํ์ผ ์์ฑ
|
285 |
+
with open('templates/index.html', 'w', encoding='utf-8') as f:
|
286 |
f.write('''
|
287 |
<!DOCTYPE html>
|
288 |
<html lang="ko">
|
289 |
<head>
|
290 |
<meta charset="UTF-8">
|
291 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
292 |
+
<title>Hugging Face URL ์นด๋ ๋ฆฌ์คํธ</title>
|
293 |
<style>
|
294 |
body {
|
295 |
font-family: Arial, sans-serif;
|
296 |
line-height: 1.6;
|
297 |
margin: 0;
|
298 |
+
padding: 0;
|
|
|
|
|
|
|
|
|
299 |
color: #333;
|
300 |
}
|
301 |
|
302 |
.container {
|
303 |
+
max-width: 1200px;
|
304 |
margin: 0 auto;
|
305 |
+
padding: 1rem;
|
306 |
}
|
307 |
|
308 |
+
.header {
|
309 |
+
background-color: #f0f0f0;
|
310 |
+
padding: 1rem;
|
311 |
border-radius: 5px;
|
312 |
+
margin-bottom: 1rem;
|
313 |
+
}
|
314 |
+
|
315 |
+
.user-controls {
|
316 |
+
display: flex;
|
317 |
+
justify-content: space-between;
|
318 |
+
align-items: center;
|
319 |
+
flex-wrap: wrap;
|
320 |
+
}
|
321 |
+
|
322 |
+
.filter-controls {
|
323 |
+
background-color: #f8f9fa;
|
324 |
+
padding: 1rem;
|
325 |
+
border-radius: 5px;
|
326 |
+
margin-bottom: 1rem;
|
327 |
}
|
328 |
|
329 |
+
input[type="password"],
|
330 |
+
input[type="text"] {
|
331 |
+
padding: 0.5rem;
|
|
|
332 |
border: 1px solid #ccc;
|
333 |
border-radius: 4px;
|
334 |
+
margin-right: 5px;
|
335 |
}
|
336 |
|
337 |
button {
|
338 |
+
padding: 0.5rem 1rem;
|
339 |
background-color: #4CAF50;
|
340 |
color: white;
|
341 |
border: none;
|
|
|
347 |
background-color: #45a049;
|
348 |
}
|
349 |
|
350 |
+
button.logout {
|
351 |
+
background-color: #f44336;
|
352 |
+
}
|
353 |
+
|
354 |
+
button.logout:hover {
|
355 |
+
background-color: #d32f2f;
|
356 |
+
}
|
357 |
+
|
358 |
+
.token-help {
|
359 |
+
margin-top: 0.5rem;
|
360 |
+
font-size: 0.8rem;
|
361 |
+
color: #666;
|
362 |
+
}
|
363 |
+
|
364 |
+
.token-help a {
|
365 |
+
color: #4CAF50;
|
366 |
+
text-decoration: none;
|
367 |
+
}
|
368 |
+
|
369 |
+
.token-help a:hover {
|
370 |
+
text-decoration: underline;
|
371 |
+
}
|
372 |
+
|
373 |
+
.cards-container {
|
374 |
+
display: flex;
|
375 |
+
flex-wrap: wrap;
|
376 |
+
gap: 1rem;
|
377 |
+
}
|
378 |
+
|
379 |
+
.card {
|
380 |
+
border: 1px solid #ccc;
|
381 |
border-radius: 5px;
|
382 |
+
padding: 1rem;
|
383 |
+
width: 300px;
|
384 |
+
box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
|
385 |
+
position: relative;
|
386 |
+
background-color: #f9f9f9;
|
387 |
+
}
|
388 |
+
|
389 |
+
.card a {
|
390 |
+
text-decoration: none;
|
391 |
+
color: #333;
|
392 |
+
word-break: break-all;
|
393 |
+
}
|
394 |
+
|
395 |
+
.like-button {
|
396 |
+
position: absolute;
|
397 |
+
top: 1rem;
|
398 |
+
right: 1rem;
|
399 |
+
border: none;
|
400 |
+
background: transparent;
|
401 |
+
font-size: 1.5rem;
|
402 |
+
cursor: pointer;
|
403 |
+
transition: color 0.2s;
|
404 |
+
}
|
405 |
+
|
406 |
+
.like-button.liked {
|
407 |
+
color: red;
|
408 |
+
}
|
409 |
+
|
410 |
+
.like-button.not-liked {
|
411 |
+
color: white;
|
412 |
+
-webkit-text-stroke: 1px #333;
|
413 |
+
}
|
414 |
+
|
415 |
+
.status-message {
|
416 |
+
padding: 1rem;
|
417 |
+
border-radius: 4px;
|
418 |
+
margin-bottom: 1rem;
|
419 |
display: none;
|
420 |
}
|
421 |
|
|
|
429 |
color: #a94442;
|
430 |
}
|
431 |
|
432 |
+
.loading {
|
433 |
+
position: fixed;
|
434 |
+
top: 0;
|
435 |
+
left: 0;
|
436 |
+
right: 0;
|
437 |
+
bottom: 0;
|
438 |
+
background-color: rgba(255, 255, 255, 0.7);
|
439 |
+
display: none;
|
440 |
+
justify-content: center;
|
441 |
+
align-items: center;
|
442 |
+
z-index: 1000;
|
443 |
+
font-size: 1.5rem;
|
444 |
}
|
445 |
|
446 |
+
.login-section {
|
447 |
+
margin-top: 1rem;
|
448 |
+
}
|
449 |
+
|
450 |
+
.logged-in-section {
|
451 |
display: none;
|
452 |
+
margin-top: 1rem;
|
453 |
+
}
|
454 |
+
|
455 |
+
@media (max-width: 768px) {
|
456 |
+
.user-controls {
|
457 |
+
flex-direction: column;
|
458 |
+
align-items: flex-start;
|
459 |
+
}
|
460 |
+
|
461 |
+
.user-controls > div {
|
462 |
+
margin-bottom: 1rem;
|
463 |
+
}
|
464 |
+
|
465 |
+
.card {
|
466 |
+
width: 100%;
|
467 |
+
}
|
468 |
}
|
469 |
</style>
|
470 |
</head>
|
471 |
<body>
|
472 |
<div class="container">
|
473 |
+
<div class="header">
|
474 |
+
<div class="user-controls">
|
475 |
+
<div>
|
476 |
+
<span>ํ๊น
ํ์ด์ค ๊ณ์ : </span>
|
477 |
+
<span id="currentUser">๋ก๊ทธ์ธ๋์ง ์์</span>
|
478 |
+
</div>
|
479 |
+
|
480 |
+
<div id="loginSection" class="login-section">
|
481 |
+
<input type="password" id="tokenInput" placeholder="ํ๊น
ํ์ด์ค API ํ ํฐ ์
๋ ฅ" />
|
482 |
+
<button id="loginButton">์ธ์ฆํ๊ธฐ</button>
|
483 |
+
<div class="token-help">
|
484 |
+
API ํ ํฐ์ <a href="https://huggingface.co/settings/tokens" target="_blank">ํ๊น
ํ์ด์ค ํ ํฐ ํ์ด์ง</a>์์ ์์ฑํ ์ ์์ต๋๋ค.
|
485 |
+
</div>
|
486 |
+
</div>
|
487 |
+
|
488 |
+
<div id="loggedInSection" class="logged-in-section">
|
489 |
+
<button id="logoutButton" class="logout">๋ก๊ทธ์์</button>
|
490 |
</div>
|
491 |
</div>
|
492 |
</div>
|
493 |
|
494 |
+
<div class="filter-controls">
|
495 |
+
<label>
|
496 |
+
<input type="checkbox" id="showOnlyLiked" />
|
497 |
+
๋ด๊ฐ ์ข์์ํ URL๋ง ๋ณด๊ธฐ
|
498 |
+
</label>
|
499 |
+
<label style="margin-left: 1rem;">
|
500 |
+
<input type="text" id="searchInput" placeholder="URL ๋๋ ์ ๋ชฉ์ผ๋ก ๊ฒ์" style="width: 250px;" />
|
501 |
+
</label>
|
|
|
502 |
</div>
|
503 |
+
|
504 |
+
<div id="statusMessage" class="status-message"></div>
|
505 |
+
|
506 |
+
<div id="loadingIndicator" class="loading">์ฒ๋ฆฌ ์ค...</div>
|
507 |
+
|
508 |
+
<div id="cardsContainer" class="cards-container"></div>
|
509 |
</div>
|
510 |
|
511 |
<script>
|
512 |
+
// DOM ์์ ์ฐธ์กฐ
|
513 |
+
const elements = {
|
514 |
+
tokenInput: document.getElementById('tokenInput'),
|
515 |
+
loginButton: document.getElementById('loginButton'),
|
516 |
+
logoutButton: document.getElementById('logoutButton'),
|
517 |
+
currentUser: document.getElementById('currentUser'),
|
518 |
+
cardsContainer: document.getElementById('cardsContainer'),
|
519 |
+
loadingIndicator: document.getElementById('loadingIndicator'),
|
520 |
+
statusMessage: document.getElementById('statusMessage'),
|
521 |
+
showOnlyLiked: document.getElementById('showOnlyLiked'),
|
522 |
+
searchInput: document.getElementById('searchInput'),
|
523 |
+
loginSection: document.getElementById('loginSection'),
|
524 |
+
loggedInSection: document.getElementById('loggedInSection')
|
525 |
+
};
|
526 |
+
|
527 |
+
// ์ ํ๋ฆฌ์ผ์ด์
์ํ
|
528 |
+
const state = {
|
529 |
+
username: null,
|
530 |
+
likedModels: {},
|
531 |
+
isLoading: false
|
532 |
+
};
|
533 |
+
|
534 |
+
// ๋ก๋ฉ ์ํ ํ์ ํจ์
|
535 |
+
function setLoading(isLoading) {
|
536 |
+
state.isLoading = isLoading;
|
537 |
+
elements.loadingIndicator.style.display = isLoading ? 'flex' : 'none';
|
538 |
+
}
|
539 |
+
|
540 |
+
// ์ํ ๋ฉ์์ง ํ์ ํจ์
|
541 |
+
function showMessage(message, isError = false) {
|
542 |
+
elements.statusMessage.textContent = message;
|
543 |
+
elements.statusMessage.className = `status-message ${isError ? 'error' : 'success'}`;
|
544 |
+
elements.statusMessage.style.display = 'block';
|
545 |
|
546 |
+
// 3์ด ํ ๋ฉ์์ง ์ฌ๋ผ์ง
|
547 |
+
setTimeout(() => {
|
548 |
+
elements.statusMessage.style.display = 'none';
|
549 |
+
}, 3000);
|
550 |
+
}
|
551 |
+
|
552 |
+
// API ์ค๋ฅ ์ฒ๋ฆฌ ํจ์
|
553 |
+
async function handleApiResponse(response) {
|
554 |
+
if (!response.ok) {
|
555 |
+
const errorText = await response.text();
|
556 |
+
throw new Error(`API ์ค๋ฅ (${response.status}): ${errorText}`);
|
557 |
+
}
|
558 |
+
return response.json();
|
559 |
+
}
|
560 |
+
|
561 |
+
// ์ธ์
์ํ ํ์ธ
|
562 |
+
async function checkSessionStatus() {
|
563 |
+
try {
|
564 |
+
const response = await fetch('/api/session-status');
|
565 |
+
const data = await handleApiResponse(response);
|
566 |
+
|
567 |
+
if (data.logged_in) {
|
568 |
+
state.username = data.username;
|
569 |
+
elements.currentUser.textContent = data.username;
|
570 |
+
elements.loginSection.style.display = 'none';
|
571 |
+
elements.loggedInSection.style.display = 'block';
|
572 |
+
|
573 |
+
// URL ๋ชฉ๋ก ๋ก๋
|
574 |
+
loadUrls();
|
575 |
+
}
|
576 |
+
} catch (error) {
|
577 |
+
console.error('์ธ์
์ํ ํ์ธ ์ค๋ฅ:', error);
|
578 |
+
}
|
579 |
+
}
|
580 |
+
|
581 |
+
// ๋ก๊ทธ์ธ ์ฒ๋ฆฌ
|
582 |
+
async function login(token) {
|
583 |
+
if (!token.trim()) {
|
584 |
+
showMessage('ํ ํฐ์ ์
๋ ฅํด์ฃผ์ธ์.', true);
|
585 |
return;
|
586 |
}
|
587 |
|
588 |
+
setLoading(true);
|
|
|
|
|
589 |
|
590 |
try {
|
|
|
591 |
const formData = new FormData();
|
592 |
formData.append('token', token);
|
593 |
|
594 |
+
const response = await fetch('/api/login', {
|
|
|
595 |
method: 'POST',
|
596 |
body: formData
|
597 |
});
|
598 |
|
599 |
+
const data = await handleApiResponse(response);
|
600 |
+
|
601 |
+
if (data.success) {
|
602 |
+
state.username = data.username;
|
603 |
+
state.likedModels = data.liked_models || {};
|
604 |
+
|
605 |
+
elements.currentUser.textContent = state.username;
|
606 |
+
elements.loginSection.style.display = 'none';
|
607 |
+
elements.loggedInSection.style.display = 'block';
|
608 |
+
|
609 |
+
showMessage(`${state.username}๋์ผ๋ก ๋ก๊ทธ์ธ๋์์ต๋๋ค.`);
|
610 |
+
|
611 |
+
// URL ๋ชฉ๋ก ๋ก๋
|
612 |
+
loadUrls();
|
613 |
+
} else {
|
614 |
+
showMessage(data.message || '๋ก๊ทธ์ธ์ ์คํจํ์ต๋๋ค.', true);
|
615 |
+
}
|
616 |
+
} catch (error) {
|
617 |
+
console.error('๋ก๊ทธ์ธ ์ค๋ฅ:', error);
|
618 |
+
showMessage(`๋ก๊ทธ์ธ ์ค๋ฅ: ${error.message}`, true);
|
619 |
+
} finally {
|
620 |
+
setLoading(false);
|
621 |
+
}
|
622 |
+
}
|
623 |
+
|
624 |
+
// ๋ก๊ทธ์์ ์ฒ๋ฆฌ
|
625 |
+
async function logout() {
|
626 |
+
setLoading(true);
|
627 |
+
|
628 |
+
try {
|
629 |
+
const response = await fetch('/api/logout', {
|
630 |
+
method: 'POST'
|
631 |
+
});
|
632 |
+
|
633 |
+
const data = await handleApiResponse(response);
|
634 |
+
|
635 |
+
if (data.success) {
|
636 |
+
state.username = null;
|
637 |
+
state.likedModels = {};
|
638 |
+
|
639 |
+
elements.currentUser.textContent = '๋ก๊ทธ์ธ๋์ง ์์';
|
640 |
+
elements.tokenInput.value = '';
|
641 |
+
elements.loginSection.style.display = 'block';
|
642 |
+
elements.loggedInSection.style.display = 'none';
|
643 |
+
|
644 |
+
showMessage('๋ก๊ทธ์์๋์์ต๋๋ค.');
|
645 |
+
|
646 |
+
// ์นด๋ ์ด๊ธฐํ
|
647 |
+
elements.cardsContainer.innerHTML = '';
|
648 |
+
}
|
649 |
+
} catch (error) {
|
650 |
+
console.error('๋ก๊ทธ์์ ์ค๋ฅ:', error);
|
651 |
+
showMessage(`๋ก๊ทธ์์ ์ค๋ฅ: ${error.message}`, true);
|
652 |
+
} finally {
|
653 |
+
setLoading(false);
|
654 |
+
}
|
655 |
+
}
|
656 |
+
|
657 |
+
// URL ๋ชฉ๋ก ๋ก๋
|
658 |
+
async function loadUrls() {
|
659 |
+
setLoading(true);
|
660 |
+
|
661 |
+
try {
|
662 |
+
const showOnlyLiked = elements.showOnlyLiked.checked;
|
663 |
+
const searchText = elements.searchInput.value;
|
664 |
+
|
665 |
+
const response = await fetch(`/api/urls?liked=${showOnlyLiked}&search=${encodeURIComponent(searchText)}`);
|
666 |
+
const urls = await handleApiResponse(response);
|
667 |
+
|
668 |
+
renderCards(urls);
|
669 |
+
} catch (error) {
|
670 |
+
console.error('URL ๋ชฉ๋ก ๋ก๋ ์ค๋ฅ:', error);
|
671 |
+
showMessage(`URL ๋ก๋ ์ค๋ฅ: ${error.message}`, true);
|
672 |
+
} finally {
|
673 |
+
setLoading(false);
|
674 |
+
}
|
675 |
+
}
|
676 |
+
|
677 |
+
// ์ข์์ ํ ๊ธ
|
678 |
+
async function toggleLike(url, button, currentLiked) {
|
679 |
+
if (!state.username) {
|
680 |
+
showMessage('์ข์์๋ฅผ ํ๋ ค๋ฉด ํ๊น
ํ์ด์ค API ํ ํฐ์ผ๋ก ์ธ์ฆ์ด ํ์ํฉ๋๋ค.', true);
|
681 |
+
return;
|
682 |
+
}
|
683 |
+
|
684 |
+
setLoading(true);
|
685 |
+
|
686 |
+
try {
|
687 |
+
const response = await fetch('/api/toggle-like', {
|
688 |
+
method: 'POST',
|
689 |
+
headers: {
|
690 |
+
'Content-Type': 'application/json'
|
691 |
+
},
|
692 |
+
body: JSON.stringify({
|
693 |
+
url: url,
|
694 |
+
currentLiked: currentLiked
|
695 |
+
})
|
696 |
+
});
|
697 |
+
|
698 |
+
const data = await handleApiResponse(response);
|
699 |
|
700 |
+
if (data.success) {
|
701 |
+
if (currentLiked) {
|
702 |
+
button.classList.remove('liked');
|
703 |
+
button.classList.add('not-liked');
|
704 |
+
} else {
|
705 |
+
button.classList.add('liked');
|
706 |
+
button.classList.remove('not-liked');
|
707 |
+
}
|
708 |
+
|
709 |
+
showMessage(data.message);
|
710 |
+
|
711 |
+
// ํํฐ๋ง๋ ๊ฒฝ์ฐ ๋ชฉ๋ก ๋ค์ ๋ก๋
|
712 |
+
if (elements.showOnlyLiked.checked) {
|
713 |
+
loadUrls();
|
714 |
+
}
|
715 |
+
} else {
|
716 |
+
showMessage(data.message, true);
|
717 |
+
}
|
718 |
} catch (error) {
|
719 |
+
console.error('์ข์์ ํ ๊ธ ์ค๋ฅ:', error);
|
720 |
+
showMessage(`์ข์์ ์ฒ๋ฆฌ ์ค๋ฅ: ${error.message}`, true);
|
|
|
|
|
721 |
} finally {
|
722 |
+
setLoading(false);
|
723 |
}
|
724 |
}
|
725 |
|
726 |
+
// ์นด๋ ๋ ๋๋ง
|
727 |
+
function renderCards(urls) {
|
728 |
+
elements.cardsContainer.innerHTML = '';
|
729 |
+
|
730 |
+
if (!urls || urls.length === 0) {
|
731 |
+
const noResultsMsg = document.createElement('p');
|
732 |
+
noResultsMsg.textContent = 'ํ์ํ URL์ด ์์ต๋๋ค.';
|
733 |
+
noResultsMsg.style.padding = '1rem';
|
734 |
+
noResultsMsg.style.fontStyle = 'italic';
|
735 |
+
elements.cardsContainer.appendChild(noResultsMsg);
|
736 |
+
return;
|
737 |
+
}
|
738 |
+
|
739 |
+
urls.forEach(item => {
|
740 |
+
const { url, title, is_liked } = item;
|
741 |
+
|
742 |
+
// ์นด๋ ์์ฑ
|
743 |
+
const card = document.createElement('div');
|
744 |
+
card.className = 'card';
|
745 |
+
|
746 |
+
// ์ ๋ชฉ
|
747 |
+
const titleEl = document.createElement('h3');
|
748 |
+
titleEl.textContent = title;
|
749 |
+
card.appendChild(titleEl);
|
750 |
+
|
751 |
+
// URL ๋งํฌ
|
752 |
+
const linkEl = document.createElement('a');
|
753 |
+
linkEl.href = url;
|
754 |
+
linkEl.textContent = url;
|
755 |
+
linkEl.target = '_blank';
|
756 |
+
card.appendChild(linkEl);
|
757 |
+
|
758 |
+
// ์ข์์ ๋ฒํผ (โฅ ์์ด์ฝ)
|
759 |
+
const likeBtn = document.createElement('button');
|
760 |
+
likeBtn.className = `like-button ${is_liked ? 'liked' : 'not-liked'}`;
|
761 |
+
likeBtn.textContent = 'โฅ';
|
762 |
+
|
763 |
+
likeBtn.addEventListener('click', function(e) {
|
764 |
+
e.preventDefault();
|
765 |
+
toggleLike(url, likeBtn, is_liked);
|
766 |
+
});
|
767 |
+
card.appendChild(likeBtn);
|
768 |
+
|
769 |
+
// ์นด๋ ์ถ๊ฐ
|
770 |
+
elements.cardsContainer.appendChild(card);
|
771 |
+
});
|
772 |
+
}
|
773 |
+
|
774 |
+
// ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ค์
|
775 |
+
elements.loginButton.addEventListener('click', () => {
|
776 |
+
login(elements.tokenInput.value);
|
777 |
+
});
|
778 |
+
|
779 |
+
elements.logoutButton.addEventListener('click', logout);
|
780 |
+
|
781 |
+
// ์ํฐ ํค๋ก ๋ก๊ทธ์ธ ๊ฐ๋ฅํ๊ฒ
|
782 |
+
elements.tokenInput.addEventListener('keypress', (event) => {
|
783 |
if (event.key === 'Enter') {
|
784 |
+
login(elements.tokenInput.value);
|
785 |
}
|
786 |
});
|
787 |
+
|
788 |
+
// ํํฐ๋ง ์ด๋ฒคํธ ๋ฆฌ์ค๋
|
789 |
+
elements.showOnlyLiked.addEventListener('change', loadUrls);
|
790 |
+
elements.searchInput.addEventListener('input', () => {
|
791 |
+
// ์
๋ ฅ ์ง์ฐ ์ฒ๋ฆฌ (ํ์ดํํ ๋๋ง๋ค API ํธ์ถ ๋ฐฉ์ง)
|
792 |
+
clearTimeout(state.searchTimeout);
|
793 |
+
state.searchTimeout = setTimeout(loadUrls, 300);
|
794 |
+
});
|
795 |
+
|
796 |
+
// ์ด๊ธฐํ
|
797 |
+
checkSessionStatus();
|
798 |
</script>
|
799 |
</body>
|
800 |
</html>
|
801 |
''')
|
802 |
|
803 |
# ํ๊น
ํ์ด์ค ์คํ์ด์ค์์๋ 7860 ํฌํธ ์ฌ์ฉ
|
804 |
+
app.run(host='0.0.0.0', port=7860)
|