Update index.html
Browse files- index.html +53 -1
index.html
CHANGED
|
@@ -198,7 +198,59 @@ function st(t){document.querySelectorAll('.ni').forEach(e=>e.classList.remove('a
|
|
| 198 |
function hu(inp,k){const f=inp.files&&inp.files[0];if(!f)return;const z=inp.closest('.uz'),ph=z.querySelector('.ph'),im=z.querySelector('.ui');const r=new FileReader();r.onload=e=>{im.src=e.target.result;im.style.display='block';if(ph)ph.style.display='none';z.classList.add('hi')};r.readAsDataURL(f);ul(f,k)}
|
| 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 |
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}
|
| 203 |
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>')}
|
| 204 |
function sl(id){document.getElementById(id).classList.add('a')}function hl(id){document.getElementById(id).classList.remove('a')}
|
|
|
|
| 198 |
function hu(inp,k){const f=inp.files&&inp.files[0];if(!f)return;const z=inp.closest('.uz'),ph=z.querySelector('.ph'),im=z.querySelector('.ui');const r=new FileReader();r.onload=e=>{im.src=e.target.result;im.style.display='block';if(ph)ph.style.display='none';z.classList.add('hi')};r.readAsDataURL(f);ul(f,k)}
|
| 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>')}
|
| 256 |
function sl(id){document.getElementById(id).classList.add('a')}function hl(id){document.getElementById(id).classList.remove('a')}
|