Update index.html
Browse files- 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 |
-
|
| 209 |
-
|
| 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>')}
|