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