Spaces:
Running
Running
Update index.html
Browse files- index.html +29 -15
index.html
CHANGED
|
@@ -9,7 +9,7 @@
|
|
| 9 |
*{box-sizing:border-box}
|
| 10 |
body{margin:0;font-family:system-ui,sans-serif;background:#0f0b1a;color:#eee}
|
| 11 |
header{display:flex;justify-content:space-between;align-items:center;padding:14px 16px}
|
| 12 |
-
h1{margin:0;font-size:
|
| 13 |
.tabs{display:flex;gap:8px;padding:0 16px}
|
| 14 |
.tab{flex:1;padding:10px;border:0;border-radius:10px;background:#221a38;color:#aaa;font-size:15px}
|
| 15 |
.tab.on{background:#7c3aed;color:#fff}
|
|
@@ -20,15 +20,17 @@ button.go{width:100%;margin-top:10px;padding:14px;border:0;border-radius:10px;ba
|
|
| 20 |
#out{margin-top:14px;text-align:center}
|
| 21 |
#out img{max-width:100%;border-radius:12px}
|
| 22 |
#msg{color:#fbbf24;margin-top:10px;white-space:pre-wrap;word-break:break-word}
|
| 23 |
-
#set{display:none;padding:16px;background:#171128;margin:0 16px;border-radius:12px}
|
| 24 |
label{display:block;margin:10px 0 4px;font-size:14px;color:#bbb}
|
| 25 |
a.dl{display:inline-block;margin-top:8px;color:#a78bfa}
|
| 26 |
</style>
|
| 27 |
</head>
|
| 28 |
<body>
|
| 29 |
-
<header><h1>🐢 Rebel</h1><button class="tab" style="flex:none" onclick="toggleSet()">⚙️</button></header>
|
| 30 |
|
| 31 |
<div id="set">
|
|
|
|
|
|
|
| 32 |
<label>مفتاح Hugging Face (يُحفظ في متصفحك فقط)</label>
|
| 33 |
<input id="tok" type="password" placeholder="hf_...">
|
| 34 |
<label>نموذج الصور</label>
|
|
@@ -53,27 +55,39 @@ a.dl{display:inline-block;margin-top:8px;color:#a78bfa}
|
|
| 53 |
const $=id=>document.getElementById(id);
|
| 54 |
const get=(k,d)=>{try{return localStorage.getItem(k)||d}catch(e){return d}};
|
| 55 |
const put=(k,v)=>{try{localStorage.setItem(k,v)}catch(e){}};
|
|
|
|
| 56 |
$('tok').value=get('tok','');
|
| 57 |
$('mod').value=get('mod','black-forest-labs/FLUX.1-schnell');
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
function toggleSet(){const s=$('set');s.style.display=s.style.display==='block'?'none':'block'}
|
| 60 |
-
function saveSet(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
async function gen(){
|
| 62 |
const prompt=$('p').value.trim(), tok=get('tok',''), mod=get('mod','');
|
| 63 |
-
if(!tok){$('set').style.display='block';$('msg').textContent='أدخل المفتاح
|
| 64 |
if(!prompt){$('msg').textContent='اكتب وصف الصورة';return}
|
| 65 |
-
$('btn').disabled=true;$('msg').textContent='جارٍ التوليد...';$('out').innerHTML='';
|
| 66 |
try{
|
| 67 |
-
const
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
if(!r.ok){throw new Error(r.status+' '+(await r.text()).slice(0,300))}
|
| 73 |
-
const url=URL.createObjectURL(await r.blob());
|
| 74 |
$('out').innerHTML='<img src="'+url+'"><br><a class="dl" download="rebel.png" href="'+url+'">⬇️ حفظ الصورة</a>';
|
| 75 |
$('msg').textContent='';
|
| 76 |
-
}catch(e){$('msg').textContent='تعذر التوليد:\n'+e.message}
|
| 77 |
$('btn').disabled=false;
|
| 78 |
}
|
| 79 |
</script>
|
|
|
|
| 9 |
*{box-sizing:border-box}
|
| 10 |
body{margin:0;font-family:system-ui,sans-serif;background:#0f0b1a;color:#eee}
|
| 11 |
header{display:flex;justify-content:space-between;align-items:center;padding:14px 16px}
|
| 12 |
+
h1{margin:0;font-size:19px}
|
| 13 |
.tabs{display:flex;gap:8px;padding:0 16px}
|
| 14 |
.tab{flex:1;padding:10px;border:0;border-radius:10px;background:#221a38;color:#aaa;font-size:15px}
|
| 15 |
.tab.on{background:#7c3aed;color:#fff}
|
|
|
|
| 20 |
#out{margin-top:14px;text-align:center}
|
| 21 |
#out img{max-width:100%;border-radius:12px}
|
| 22 |
#msg{color:#fbbf24;margin-top:10px;white-space:pre-wrap;word-break:break-word}
|
| 23 |
+
#set{display:none;padding:16px;background:#171128;margin:0 16px 14px;border-radius:12px}
|
| 24 |
label{display:block;margin:10px 0 4px;font-size:14px;color:#bbb}
|
| 25 |
a.dl{display:inline-block;margin-top:8px;color:#a78bfa}
|
| 26 |
</style>
|
| 27 |
</head>
|
| 28 |
<body>
|
| 29 |
+
<header><h1 id="hello">🐢 Rebel</h1><button class="tab" style="flex:none" onclick="toggleSet()">⚙️</button></header>
|
| 30 |
|
| 31 |
<div id="set">
|
| 32 |
+
<label>اسمك</label>
|
| 33 |
+
<input id="nm" placeholder="اكتب اسمك">
|
| 34 |
<label>مفتاح Hugging Face (يُحفظ في متصفحك فقط)</label>
|
| 35 |
<input id="tok" type="password" placeholder="hf_...">
|
| 36 |
<label>نموذج الصور</label>
|
|
|
|
| 55 |
const $=id=>document.getElementById(id);
|
| 56 |
const get=(k,d)=>{try{return localStorage.getItem(k)||d}catch(e){return d}};
|
| 57 |
const put=(k,v)=>{try{localStorage.setItem(k,v)}catch(e){}};
|
| 58 |
+
$('nm').value=get('nm','');
|
| 59 |
$('tok').value=get('tok','');
|
| 60 |
$('mod').value=get('mod','black-forest-labs/FLUX.1-schnell');
|
| 61 |
+
function hello(){const n=get('nm','');$('hello').textContent=n?'🐢 أهلاً '+n:'🐢 Rebel'}
|
| 62 |
+
hello();
|
| 63 |
+
if(!get('nm','')||!get('tok','')) $('set').style.display='block';
|
| 64 |
function toggleSet(){const s=$('set');s.style.display=s.style.display==='block'?'none':'block'}
|
| 65 |
+
function saveSet(){
|
| 66 |
+
const n=$('nm').value.trim(), t=$('tok').value.trim();
|
| 67 |
+
if(!n){$('msg').textContent='اكتب اسمك أولاً';return}
|
| 68 |
+
if(!t){$('msg').textContent='أدخل المفتاح';return}
|
| 69 |
+
put('nm',n);put('tok',t);put('mod',$('mod').value.trim());
|
| 70 |
+
$('set').style.display='none';$('msg').textContent='تم الحفظ ✅';hello();
|
| 71 |
+
}
|
| 72 |
+
let lib=null;
|
| 73 |
+
async function getLib(){
|
| 74 |
+
if(!lib) lib=await import('https://cdn.jsdelivr.net/npm/@huggingface/inference/+esm');
|
| 75 |
+
return lib;
|
| 76 |
+
}
|
| 77 |
async function gen(){
|
| 78 |
const prompt=$('p').value.trim(), tok=get('tok',''), mod=get('mod','');
|
| 79 |
+
if(!get('nm','')||!tok){$('set').style.display='block';$('msg').textContent='أدخل اسمك ثم المفتاح';return}
|
| 80 |
if(!prompt){$('msg').textContent='اكتب وصف الصورة';return}
|
| 81 |
+
$('btn').disabled=true;$('msg').textContent='جارٍ التوليد... (قد يستغرق دقيقة)';$('out').innerHTML='';
|
| 82 |
try{
|
| 83 |
+
const M=await getLib();
|
| 84 |
+
const C=M.InferenceClient||M.HfInference;
|
| 85 |
+
const client=new C(tok);
|
| 86 |
+
const blob=await client.textToImage({provider:'auto',model:mod,inputs:prompt});
|
| 87 |
+
const url=URL.createObjectURL(blob);
|
|
|
|
|
|
|
| 88 |
$('out').innerHTML='<img src="'+url+'"><br><a class="dl" download="rebel.png" href="'+url+'">⬇️ حفظ الصورة</a>';
|
| 89 |
$('msg').textContent='';
|
| 90 |
+
}catch(e){$('msg').textContent='تعذر التوليد:\n'+(e.message||e)}
|
| 91 |
$('btn').disabled=false;
|
| 92 |
}
|
| 93 |
</script>
|