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
d927a6e
 
 
ec0e5a1
 
 
d927a6e
ec0e5a1
d927a6e
 
 
 
 
 
 
4e7524a
ec0e5a1
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
from flask import Flask, render_template, request, redirect, url_for, jsonify, session
import requests
import os
import json
from datetime import timedelta
import logging

# λ‘œκΉ… μ„€μ •
logging.basicConfig(level=logging.DEBUG, 
                   format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

app = Flask(__name__)
app.secret_key = os.urandom(24)  # μ„Έμ…˜ μ•”ν˜Έν™”λ₯Ό μœ„ν•œ λΉ„λ°€ ν‚€
app.permanent_session_lifetime = timedelta(days=7)  # μ„Έμ…˜ μœ μ§€ κΈ°κ°„ μ„€μ •

# ν—ˆκΉ…νŽ˜μ΄μŠ€ URL λͺ©λ‘ (κ°„λž΅ν™”)
HUGGINGFACE_URLS = [
    "https://huggingface.co/spaces/ginipick/Tech_Hangman_Game",
    "https://huggingface.co/spaces/openfree/deepseek_r1_API",
    "https://huggingface.co/spaces/ginipick/open_Deep-Research"
]

# ν—ˆκΉ…νŽ˜μ΄μŠ€ 인증 확인 (디버깅 κ°œμ„ )
def validate_token(token):
    logger.debug(f"토큰 검증 μ‹œλ„ (토큰 일뢀: {token[:4]}...)")
    headers = {"Authorization": f"Bearer {token}"}
    
    # μ—¬λŸ¬ μ—”λ“œν¬μΈνŠΈ μ‹œλ„
    api_endpoints = [
        "https://huggingface.co/api/whoami",
        "https://huggingface.co/api/whoami-v2"
    ]
    
    for endpoint in api_endpoints:
        try:
            logger.debug(f"API μ—”λ“œν¬μΈνŠΈ μ‹œλ„: {endpoint}")
            response = requests.get(endpoint, headers=headers)
            
            # 응닡 λ‘œκΉ…
            logger.debug(f"API 응닡 μƒνƒœ μ½”λ“œ: {response.status_code}")
            logger.debug(f"API 응닡 헀더: {response.headers}")
            
            if response.ok:
                logger.debug("토큰 검증 성곡!")
                return True, response.json()
            else:
                logger.debug(f"토큰 검증 μ‹€νŒ¨ - 응닡: {response.text}")
        except Exception as e:
            logger.error(f"API 호좜 쀑 였λ₯˜ λ°œμƒ: {str(e)}")
    
    # λͺ¨λ“  API 호좜 μ‹€νŒ¨
    return False, None

# 토큰 검증 ν…ŒμŠ€νŠΈ API
@app.route('/api/test-token', methods=['POST'])
def test_token():
    token = request.form.get('token', '')
    
    if not token:
        return jsonify({'success': False, 'message': '토큰을 μž…λ ₯ν•΄μ£Όμ„Έμš”.'})
    
    # 상세 디버깅 정보 μˆ˜μ§‘
    debug_info = {}
    
    # 토큰 ν˜•μ‹ 확인
    is_valid_format = token.startswith('hf_')
    debug_info['token_format'] = 'hf_ 접두사 있음' if is_valid_format else '접두사 μ—†μŒ'
    
    # 직접 API 호좜 ν…ŒμŠ€νŠΈ
    test_endpoints = [
        "https://huggingface.co/api/whoami",
        "https://huggingface.co/api/whoami-v2",
        "https://huggingface.co/api/models/meta/llama"
    ]
    
    endpoint_results = {}
    
    for endpoint in test_endpoints:
        try:
            headers = {"Authorization": f"Bearer {token}"}
            response = requests.get(endpoint, headers=headers, timeout=5)
            
            endpoint_results[endpoint] = {
                'status_code': response.status_code,
                'success': response.ok,
                'content_type': response.headers.get('Content-Type', 'unknown'),
                'response_sample': str(response.text)[:100] + '...' if response.text else 'Empty response'
            }
        except Exception as e:
            endpoint_results[endpoint] = {'error': str(e)}
    
    debug_info['endpoint_tests'] = endpoint_results
    
    # μ΅œμ’… νŒλ‹¨
    is_valid = any(result.get('success', False) for result in endpoint_results.values())
    
    return jsonify({
        'success': is_valid,
        'debug_info': debug_info,
        'message': '토큰이 μœ νš¨ν•©λ‹ˆλ‹€.' if is_valid else 'μœ νš¨ν•˜μ§€ μ•Šμ€ ν† ν°μž…λ‹ˆλ‹€.'
    })

# κΈ°λ³Έ ν™ˆνŽ˜μ΄μ§€ (디버깅 ν™”λ©΄ 포함)
@app.route('/')
def home():
    return render_template('debug_index.html')

if __name__ == '__main__':
    # templates 폴더 생성
    os.makedirs('templates', exist_ok=True)
    
    # λ””λ²„κΉ…μš© HTML 생성
    with open('templates/debug_index.html', 'w', encoding='utf-8') as f:
        f.write('''
<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>ν—ˆκΉ…νŽ˜μ΄μŠ€ 토큰 디버거</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      line-height: 1.6;
      margin: 0;
      padding: 20px;
      color: #333;
    }
    
    h1, h2 {
      color: #333;
    }
    
    .container {
      max-width: 800px;
      margin: 0 auto;
    }
    
    .card {
      border: 1px solid #ddd;
      border-radius: 5px;
      padding: 20px;
      margin-bottom: 20px;
      background-color: #f9f9f9;
    }
    
    input[type="password"] {
      width: 100%;
      padding: 10px;
      margin: 10px 0;
      border: 1px solid #ccc;
      border-radius: 4px;
    }
    
    button {
      padding: 10px 15px;
      background-color: #4CAF50;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }
    
    button:hover {
      background-color: #45a049;
    }
    
    .result {
      margin-top: 20px;
      padding: 15px;
      border-radius: 5px;
      display: none;
    }
    
    .success {
      background-color: #dff0d8;
      color: #3c763d;
    }
    
    .error {
      background-color: #f2dede;
      color: #a94442;
    }
    
    pre {
      background-color: #f5f5f5;
      padding: 10px;
      border-radius: 5px;
      overflow-x: auto;
      white-space: pre-wrap;
    }
    
    .loading {
      display: none;
      margin-top: 10px;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>ν—ˆκΉ…νŽ˜μ΄μŠ€ 토큰 디버거</h1>
    
    <div class="card">
      <h2>토큰 ν…ŒμŠ€νŠΈ</h2>
      <p>ν—ˆκΉ…νŽ˜μ΄μŠ€ API 토큰을 μž…λ ₯ν•˜μ—¬ μœ νš¨μ„±μ„ ν…ŒμŠ€νŠΈν•©λ‹ˆλ‹€.</p>
      
      <input type="password" id="tokenInput" placeholder="ν—ˆκΉ…νŽ˜μ΄μŠ€ API 토큰 μž…λ ₯ (hf_둜 μ‹œμž‘)" />
      <button id="testButton">토큰 ν…ŒμŠ€νŠΈ</button>
      
      <div id="loading" class="loading">ν…ŒμŠ€νŠΈ 쀑...</div>
      
      <div id="result" class="result">
        <h3>ν…ŒμŠ€νŠΈ κ²°κ³Ό</h3>
        <p id="resultMessage"></p>
        <div id="detailsContainer">
          <h4>상세 정보</h4>
          <pre id="resultDetails"></pre>
        </div>
      </div>
    </div>
    
    <div class="card">
      <h2>디버깅 팁</h2>
      <ul>
        <li>토큰은 <code>hf_</code>둜 μ‹œμž‘ν•΄μ•Ό ν•©λ‹ˆλ‹€.</li>
        <li>토큰은 곡백 없이 μž…λ ₯ν•΄μ•Ό ν•©λ‹ˆλ‹€.</li>
        <li>토큰이 λ§Œλ£Œλ˜μ§€ μ•Šμ•˜λŠ”μ§€ ν™•μΈν•˜μ„Έμš”.</li>
        <li>토큰에 μ μ ˆν•œ κΆŒν•œ(μ΅œμ†Œ READ)이 μžˆλŠ”μ§€ ν™•μΈν•˜μ„Έμš”.</li>
        <li>λ„€νŠΈμ›Œν¬ μ œν•œμ΄ μžˆλŠ” ν™˜κ²½μΈμ§€ ν™•μΈν•˜μ„Έμš”.</li>
      </ul>
    </div>
  </div>
  
  <script>
    // μš”μ†Œ μ°Έμ‘°
    const tokenInput = document.getElementById('tokenInput');
    const testButton = document.getElementById('testButton');
    const loading = document.getElementById('loading');
    const result = document.getElementById('result');
    const resultMessage = document.getElementById('resultMessage');
    const resultDetails = document.getElementById('resultDetails');
    
    // 토큰 ν…ŒμŠ€νŠΈ ν•¨μˆ˜
    async function testToken() {
      const token = tokenInput.value.trim();
      
      if (!token) {
        alert('토큰을 μž…λ ₯ν•΄μ£Όμ„Έμš”.');
        return;
      }
      
      // UI μ—…λ°μ΄νŠΈ
      loading.style.display = 'block';
      result.style.display = 'none';
      
      try {
        // FormData 생성
        const formData = new FormData();
        formData.append('token', token);
        
        // API 호좜
        const response = await fetch('/api/test-token', {
          method: 'POST',
          body: formData
        });
        
        const data = await response.json();
        
        // κ²°κ³Ό ν‘œμ‹œ
        result.className = `result ${data.success ? 'success' : 'error'}`;
        resultMessage.textContent = data.message;
        resultDetails.textContent = JSON.stringify(data.debug_info, null, 2);
        result.style.display = 'block';
      } catch (error) {
        result.className = 'result error';
        resultMessage.textContent = `였λ₯˜ λ°œμƒ: ${error.message}`;
        resultDetails.textContent = error.stack || '상세 정보 μ—†μŒ';
        result.style.display = 'block';
      } finally {
        loading.style.display = 'none';
      }
    }
    
    // 이벀트 λ¦¬μŠ€λ„ˆ
    testButton.addEventListener('click', testToken);
    tokenInput.addEventListener('keypress', (event) => {
      if (event.key === 'Enter') {
        testToken();
      }
    });
  </script>
</body>
</html>
''')
    
    # ν—ˆκΉ…νŽ˜μ΄μŠ€ μŠ€νŽ˜μ΄μŠ€μ—μ„œλŠ” 7860 포트 μ‚¬μš©
    app.run(host='0.0.0.0', port=7860, debug=True)