aiqtech commited on
Commit
6115a29
Β·
verified Β·
1 Parent(s): 0d0eb49

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +40 -43
index.html CHANGED
@@ -199,57 +199,54 @@ function hu(inp,k){const f=inp.files&&inp.files[0];if(!f)return;const z=inp.clos
199
  async function ul(f,k){const fd=new FormData();fd.append('files',f);for(const u of[`${B}/gradio/gradio_api/upload`,`${B}/gradio/upload`,`${B}/gradio_api/upload`,`${B}/upload`]){try{const r=await fetch(u,{method:'POST',body:fd});if(r.ok){const j=await r.json();U[k]=Array.isArray(j)?j[0]:j;return}}catch{}}}
200
  function mf(p){return{path:p,meta:{_type:'gradio.FileData'},orig_name:'face.png',mime_type:'image/png'}}
201
  async function gc(api,data){
 
 
202
  for(const u of[`${B}/gradio/gradio_api/call${api}`,`${B}/gradio/call${api}`,`${B}/gradio/api${api}`,`${B}/api${api}`,`${B}/gradio_api/call${api}`]){
203
  try{
204
  const r=await fetch(u,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({data})});
205
  if(!r.ok)continue;
206
  const j=await r.json();
207
  if(!j.event_id)continue;
208
- const sseUrl=`${u}/${j.event_id}`;
209
- return await new Promise((ok,no)=>{
210
- let done=false,retries=0,MAX_RETRY=10,es=null;
211
- const TOTAL_TIMEOUT=setTimeout(()=>{if(!done){done=true;if(es)es.close();no(new Error('μ‹œκ°„ 초과'));}},600000);
212
- function connect(){
213
- if(done)return;
214
- es=new EventSource(sseUrl);
215
- const onMsg=e=>{
216
- if(done)return;
217
- try{
218
- const raw=JSON.parse(e.data);
219
- // process_completed 포맷
220
- if(raw&&raw.msg==='process_completed'&&raw.output&&raw.output.data){
221
- done=true;clearTimeout(TOTAL_TIMEOUT);es.close();ok(raw.output.data);return;
222
- }
223
- // λ°°μ—΄ 직접 λ°˜ν™˜ 포맷
224
- const p=Array.isArray(raw)?raw:(raw&&raw.data&&Array.isArray(raw.data)?raw.data:null);
225
- if(p){done=true;clearTimeout(TOTAL_TIMEOUT);es.close();ok(p);}
226
- }catch{}
227
- };
228
- es.onmessage=onMsg;
229
- es.addEventListener('complete',onMsg);
230
- es.addEventListener('process_completed',e=>{
231
- if(done)return;
232
- try{
233
- const raw=JSON.parse(e.data);
234
- const out=raw&&raw.output&&raw.output.data?raw.output.data:null;
235
- if(out){done=true;clearTimeout(TOTAL_TIMEOUT);es.close();ok(out);}
236
- }catch{}
237
- });
238
- // onerror: μ¦‰μ‹œ ν¬κΈ°ν•˜μ§€ μ•Šκ³  μž¬μ—°κ²° μ‹œλ„
239
- es.onerror=()=>{
240
- if(done)return;
241
- es.close();
242
- retries++;
243
- if(retries>MAX_RETRY){done=true;clearTimeout(TOTAL_TIMEOUT);no(new Error('μ—°κ²° 였λ₯˜(μž¬μ‹œλ„ 초과)'));return;}
244
- // 2초 ν›„ 같은 event_id둜 μž¬μ—°κ²°
245
- setTimeout(connect,2000);
246
- };
247
- }
248
- connect();
249
- });
250
  }catch{}
251
  }
252
- throw new Error('API μ—°κ²° μ‹€νŒ¨');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  }
254
  function iu(d){if(!d)return null;if(typeof d==='string'){if(d.startsWith('/file='))return B+'/gradio'+d;return d}const u=d.url||d.path||(d.value&&(d.value.url||d.value.path));if(!u)return null;if(u.startsWith('/file='))return B+'/gradio'+u;if(!u.startsWith('http'))return B+'/gradio/file='+u;return u}
255
  function md(s){return s.replace(/^### (.*$)/gm,'<h3>$1</h3>').replace(/^## (.*$)/gm,'<h2>$1</h2>').replace(/^# (.*$)/gm,'<h1>$1</h1>').replace(/\*\*(.*?)\*\*/g,'<b>$1</b>').replace(/\*(.*?)\*/g,'<em>$1</em>').replace(/^> (.*$)/gm,'<blockquote>$1</blockquote>').replace(/^---$/gm,'<hr>').replace(/^- (.*$)/gm,'<li>$1</li>').replace(/\n\n/g,'<br><br>').replace(/\n/g,'<br>')}
 
199
  async function ul(f,k){const fd=new FormData();fd.append('files',f);for(const u of[`${B}/gradio/gradio_api/upload`,`${B}/gradio/upload`,`${B}/gradio_api/upload`,`${B}/upload`]){try{const r=await fetch(u,{method:'POST',body:fd});if(r.ok){const j=await r.json();U[k]=Array.isArray(j)?j[0]:j;return}}catch{}}}
200
  function mf(p){return{path:p,meta:{_type:'gradio.FileData'},orig_name:'face.png',mime_type:'image/png'}}
201
  async function gc(api,data){
202
+ /* ── Phase 1: POST β†’ event_id νšλ“ (URL μˆœμ„œλŒ€λ‘œ μ‹œλ„) ── */
203
+ let sseUrl=null;
204
  for(const u of[`${B}/gradio/gradio_api/call${api}`,`${B}/gradio/call${api}`,`${B}/gradio/api${api}`,`${B}/api${api}`,`${B}/gradio_api/call${api}`]){
205
  try{
206
  const r=await fetch(u,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({data})});
207
  if(!r.ok)continue;
208
  const j=await r.json();
209
  if(!j.event_id)continue;
210
+ sseUrl=`${u}/${j.event_id}`;
211
+ break; /* POST 성곡 β†’ SSE λ‹¨κ³„λ‘œ 이동 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  }catch{}
213
  }
214
+ if(!sseUrl)throw new Error('API μ—°κ²° μ‹€νŒ¨ (μ„œλ²„μ— μ—°κ²°ν•  수 μ—†μŠ΅λ‹ˆλ‹€)');
215
+
216
+ /* ── Phase 2: SSE μˆ˜μ‹  + μžλ™ μž¬μ—°κ²° (μƒˆ POST μ ˆλŒ€ μ•ˆ 함) ── */
217
+ return new Promise((ok,no)=>{
218
+ let done=false,retries=0,es=null;
219
+ const MAX_RETRY=150; /* 150Γ—2s=5λΆ„ μž¬μ—°κ²° ν—ˆμš© */
220
+ const TOTAL_TO=setTimeout(()=>{if(!done){done=true;if(es)es.close();no(new Error('μ‹œκ°„ 초과 (10λΆ„)'));}},600000);
221
+ function resolve(val){if(done)return;done=true;clearTimeout(TOTAL_TO);if(es)es.close();ok(val);}
222
+ function reject(err){if(done)return;done=true;clearTimeout(TOTAL_TO);if(es)es.close();no(err);}
223
+ function onData(e){
224
+ try{
225
+ const raw=JSON.parse(e.data);
226
+ if(!raw)return;
227
+ /* process_completed 포맷 */
228
+ if(raw.msg==='process_completed'&&raw.output&&raw.output.data){resolve(raw.output.data);return;}
229
+ /* 직접 λ°°μ—΄ 포맷 */
230
+ const p=Array.isArray(raw)?raw:(raw.data&&Array.isArray(raw.data)?raw.data:null);
231
+ if(p)resolve(p);
232
+ }catch{}
233
+ }
234
+ function connect(){
235
+ if(done)return;
236
+ es=new EventSource(sseUrl);
237
+ es.onmessage=onData;
238
+ es.addEventListener('complete',onData);
239
+ es.addEventListener('process_completed',onData);
240
+ es.onerror=()=>{
241
+ if(done)return;
242
+ es.close();
243
+ retries++;
244
+ if(retries>MAX_RETRY){reject(new Error('연결이 반볡 λŠκΉ€ (μž¬μ‹œλ„ 초과)'));return;}
245
+ setTimeout(connect,2000); /* 2초 ν›„ 같은 event_id둜 μž¬μ—°κ²° */
246
+ };
247
+ }
248
+ connect();
249
+ });
250
  }
251
  function iu(d){if(!d)return null;if(typeof d==='string'){if(d.startsWith('/file='))return B+'/gradio'+d;return d}const u=d.url||d.path||(d.value&&(d.value.url||d.value.path));if(!u)return null;if(u.startsWith('/file='))return B+'/gradio'+u;if(!u.startsWith('http'))return B+'/gradio/file='+u;return u}
252
  function md(s){return s.replace(/^### (.*$)/gm,'<h3>$1</h3>').replace(/^## (.*$)/gm,'<h2>$1</h2>').replace(/^# (.*$)/gm,'<h1>$1</h1>').replace(/\*\*(.*?)\*\*/g,'<b>$1</b>').replace(/\*(.*?)\*/g,'<em>$1</em>').replace(/^> (.*$)/gm,'<blockquote>$1</blockquote>').replace(/^---$/gm,'<hr>').replace(/^- (.*$)/gm,'<li>$1</li>').replace(/\n\n/g,'<br><br>').replace(/\n/g,'<br>')}