Download index.html from Sada8888/h3html: direct link, hf CLI and curl.
- Browser
- Download file 37 kB
-
https://huggingface.co/spaces/Sada8888/h3html/resolve/main/index.html
- Command line
-
hf download hf://spaces/Sada8888/h3html/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Sada8888/h3html/resolve/main/index.html
37 kB
| <html lang="fa" dir="rtl"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <meta name="color-scheme" content="light" /> | |
| <title>MiniMax-H3 Reference — کلاینت اختصاصی Sada8888/Rvcpro</title> | |
| <link rel="preconnect" href="https://fonts.googleapis.com"> | |
| <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | |
| <link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap" rel="stylesheet"> | |
| <style> | |
| :root{ | |
| --bg:#faf6ec; | |
| --card:#ffffff; | |
| --border:#ecdfc4; | |
| --text:#2c2416; | |
| --muted:#8a7f68; | |
| --primary:#ef7d1a; | |
| --primary-dark:#d4670a; | |
| --accent:#7fb519; | |
| --tracking-bg:#fff6e2; | |
| --tracking-border:#f2d99a; | |
| --radius:16px; | |
| --shadow:0 1px 2px rgba(44,36,22,.06), 0 10px 28px rgba(44,36,22,.06); | |
| } | |
| *{box-sizing:border-box;} | |
| html,body{margin:0;padding:0;} | |
| body{ | |
| background:var(--bg); | |
| color:var(--text); | |
| font-family:'Vazirmatn', system-ui, sans-serif; | |
| line-height:1.6; | |
| padding-bottom:60px; | |
| } | |
| a{color:var(--primary-dark);} | |
| .wrap{max-width:1180px;margin:0 auto;padding:0 20px;} | |
| .topbar{ | |
| display:flex;justify-content:space-between;align-items:center; | |
| flex-wrap:wrap;gap:14px;padding:22px 0 8px; | |
| } | |
| .brand{display:flex;align-items:center;gap:12px;} | |
| .logo-dot{ | |
| width:34px;height:34px;border-radius:10px;flex:none; | |
| background:linear-gradient(135deg,var(--primary),var(--accent)); | |
| box-shadow:0 4px 10px rgba(239,125,26,.35); | |
| } | |
| .brand h1{font-size:1.25rem;margin:0;} | |
| .brand p{margin:2px 0 0;color:var(--muted);font-size:.85rem;} | |
| .toplinks{display:flex;gap:16px;font-size:.85rem;flex-wrap:wrap;} | |
| .toplinks a{text-decoration:none;font-weight:600;} | |
| .toplinks a:hover{text-decoration:underline;} | |
| .intro{color:var(--muted);font-size:.9rem;max-width:760px;margin:6px 0 20px;} | |
| .intro b{color:var(--text);} | |
| .banner{ | |
| background:#fdecea;border:1px solid #f3c6c1;color:#8a2e26; | |
| padding:10px 14px;border-radius:12px;font-size:.85rem;margin-bottom:16px; | |
| } | |
| main.layout{ | |
| display:grid;grid-template-columns:1.25fr 1fr;gap:22px;align-items:start; | |
| } | |
| @media (max-width:900px){ main.layout{grid-template-columns:1fr;} } | |
| .panel{ | |
| background:var(--card);border:1px solid var(--border); | |
| border-radius:var(--radius);box-shadow:var(--shadow); | |
| padding:20px; | |
| } | |
| .field{display:flex;flex-direction:column;gap:6px;margin-bottom:14px;} | |
| .field-label{font-size:.85rem;font-weight:700;color:var(--text);} | |
| textarea,input[type=text],input[type=number],input[type=password],select{ | |
| padding:10px 12px;border:1px solid var(--border);border-radius:10px; | |
| font-family:inherit;font-size:.92rem;background:#fffdf8;color:var(--text); | |
| width:100%; | |
| } | |
| textarea{resize:vertical;} | |
| select{direction:ltr;text-align:right;cursor:pointer;} | |
| input:focus,textarea:focus,select:focus{outline:2px solid var(--primary);outline-offset:1px;} | |
| .checkbox-row{display:flex;align-items:center;gap:8px;font-size:.88rem;cursor:pointer;user-select:none;} | |
| .checkbox-row input{width:16px;height:16px;accent-color:var(--primary);} | |
| .tabs{margin:16px 0 6px;} | |
| .tab-buttons{display:flex;gap:2px;border-bottom:1px solid var(--border);margin-bottom:14px;} | |
| .tab-btn{ | |
| padding:9px 16px;border:none;background:none;cursor:pointer; | |
| font-family:inherit;font-size:.88rem;color:var(--muted); | |
| border-bottom:2px solid transparent;margin-bottom:-1px;font-weight:600; | |
| } | |
| .tab-btn.active{color:var(--primary-dark);border-bottom-color:var(--primary);} | |
| .tab-panel[hidden]{display:none;} | |
| .image-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:10px;} | |
| .image-slot{ | |
| position:relative;height:120px;border:1.5px dashed var(--border);border-radius:12px; | |
| display:flex;align-items:center;justify-content:center;cursor:pointer; | |
| overflow:hidden;background:#fffdf6;transition:border-color .15s; | |
| } | |
| .image-slot:hover{border-color:var(--primary);} | |
| .image-slot img{width:100%;height:100%;object-fit:cover;} | |
| .slot-hint{font-size:.72rem;color:var(--muted);text-align:center;padding:6px;} | |
| .remove-btn{ | |
| position:absolute;top:5px;left:5px;width:22px;height:22px;border-radius:50%; | |
| border:none;background:rgba(30,25,15,.65);color:#fff;cursor:pointer;font-size:.7rem; | |
| display:flex;align-items:center;justify-content:center; | |
| } | |
| #addImageBtn{margin-top:10px;} | |
| .dropzone{ | |
| border:1.5px dashed var(--border);border-radius:12px;padding:26px; | |
| text-align:center;cursor:pointer;color:var(--muted);font-size:.85rem;background:#fffdf6; | |
| } | |
| .dropzone:hover{border-color:var(--primary);} | |
| audio,video{width:100%;margin-top:10px;border-radius:10px;background:#000;} | |
| .clear-link{ | |
| background:none;border:none;color:var(--muted);font-size:.78rem; | |
| text-decoration:underline;cursor:pointer;margin-top:6px;padding:0;font-family:inherit; | |
| } | |
| .btn-primary{ | |
| background:var(--primary);color:#fff;border:none;padding:13px 22px; | |
| border-radius:12px;font-weight:700;cursor:pointer;font-family:inherit;font-size:.98rem; | |
| transition:background .15s; | |
| } | |
| .btn-primary:hover{background:var(--primary-dark);} | |
| .btn-primary:disabled{opacity:.55;cursor:not-allowed;} | |
| .btn-lg{width:100%;margin-top:8px;} | |
| .btn-secondary{ | |
| background:#fff;border:1.5px solid var(--primary);color:var(--primary-dark); | |
| padding:9px 16px;border-radius:10px;font-weight:700;cursor:pointer;font-family:inherit;font-size:.85rem; | |
| } | |
| .btn-secondary:disabled{opacity:.55;cursor:not-allowed;} | |
| .btn-ghost{ | |
| background:none;border:1px solid var(--border);color:var(--text); | |
| padding:6px 13px;border-radius:9px;cursor:pointer;font-family:inherit;font-size:.8rem; | |
| } | |
| .btn-ghost:hover{border-color:var(--primary);} | |
| .tracking-box{ | |
| margin-top:16px;padding:14px 16px;background:var(--tracking-bg); | |
| border:1px solid var(--tracking-border);border-radius:12px; | |
| } | |
| .tracking-row{display:flex;align-items:center;gap:10px;margin-top:6px;flex-wrap:wrap;} | |
| .tracking-row code{ | |
| direction:ltr;unicode-bidi:isolate;font-family:'Courier New',monospace; | |
| font-size:1.15rem;font-weight:800;letter-spacing:3px;color:var(--primary-dark); | |
| } | |
| .status-text{font-size:.83rem;color:var(--muted);margin-top:10px;line-height:1.8;} | |
| .status-text.small{font-size:.8rem;margin-top:8px;} | |
| .status-text code{direction:ltr;unicode-bidi:isolate;display:inline-block;} | |
| details.accordion-native{ | |
| margin-top:14px;border:1px solid var(--border);border-radius:12px;padding:2px 16px; | |
| } | |
| details.accordion-native summary{ | |
| cursor:pointer;padding:13px 0;font-weight:700;font-size:.88rem;list-style:none; | |
| display:flex;justify-content:space-between;align-items:center; | |
| } | |
| details.accordion-native summary::-webkit-details-marker{display:none;} | |
| details.accordion-native summary::after{content:"⌄";font-size:1rem;color:var(--muted);transition:transform .15s;} | |
| details.accordion-native[open] summary::after{transform:rotate(180deg);} | |
| .accordion-native-body{padding-bottom:16px;} | |
| .advanced-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px 18px;} | |
| @media (max-width:600px){ .advanced-grid{grid-template-columns:1fr;} } | |
| .divider{grid-column:1/-1;border:none;border-top:1px solid var(--border);margin:2px 0;} | |
| .range-row{display:flex;align-items:center;gap:10px;} | |
| .range-row input[type=range]{flex:1;accent-color:var(--primary);} | |
| .row-inline{display:flex;gap:8px;} | |
| .row-inline input{flex:1;} | |
| .video-frame{ | |
| border:1px solid var(--border);border-radius:12px;overflow:hidden; | |
| background:#fdf9ee;min-height:220px;display:flex;align-items:center;justify-content:center; | |
| } | |
| .video-frame video{width:100%;display:block;} | |
| .video-frame .placeholder{color:var(--muted);font-size:.85rem;padding:34px;text-align:center;} | |
| .history-panel{margin-top:24px;} | |
| .history-head{display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:10px;} | |
| .history-head h2{margin:0;font-size:1.05rem;} | |
| .history-note{color:var(--muted);font-size:.82rem;margin:6px 0 4px;} | |
| .history-list{display:flex;flex-direction:column;gap:12px;margin-top:14px;} | |
| .history-item{border:1px solid var(--border);border-radius:12px;padding:14px 16px;background:#fffefb;} | |
| .history-item-top{display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap;} | |
| .history-prompt{font-size:.9rem;flex:1;min-width:200px;} | |
| .history-meta{font-size:.75rem;color:var(--muted);display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;} | |
| .code-chip{ | |
| direction:ltr;unicode-bidi:isolate;font-family:'Courier New',monospace;font-weight:700; | |
| background:var(--tracking-bg);border:1px solid var(--tracking-border);border-radius:7px; | |
| padding:1px 8px;color:var(--primary-dark); | |
| } | |
| .badge{display:inline-block;padding:3px 11px;border-radius:999px;font-size:.7rem;font-weight:800;} | |
| .badge-queued{background:#eef1f6;color:#4a5568;} | |
| .badge-running{background:#fff2cf;color:#92600a;} | |
| .badge-done{background:#e2f6e6;color:#1f7a34;} | |
| .badge-error{background:#fbe4e2;color:#b3261e;} | |
| .badge-unknown{background:#eee;color:#666;} | |
| .history-actions{display:flex;gap:8px;margin-top:11px;flex-wrap:wrap;align-items:center;} | |
| .history-item video{width:100%;margin-top:10px;border-radius:10px;} | |
| #historyEmptyNote{color:var(--muted);font-size:.85rem;padding:10px 2px;} | |
| footer.note{max-width:1180px;margin:26px auto 0;padding:0 20px;color:var(--muted);font-size:.78rem;line-height:1.8;} | |
| footer.note b{color:var(--text);} | |
| .spin{ | |
| display:inline-block;width:13px;height:13px;border:2px solid rgba(255,255,255,.5); | |
| border-top-color:#fff;border-radius:50%;animation:spin .7s linear infinite;vertical-align:-2px;margin-inline-start:6px; | |
| } | |
| @keyframes spin{to{transform:rotate(360deg);}} | |
| </style> | |
| </head> | |
| <body> | |
| <div class="wrap"> | |
| <div class="topbar"> | |
| <div class="brand"> | |
| <div class="logo-dot"></div> | |
| <div> | |
| <h1>MiniMax-H3 Reference</h1> | |
| <p>کلاینت اختصاصی — متصل به Space رسمی <span dir="ltr">Sada8888/Rvcpro</span></p> | |
| </div> | |
| </div> | |
| <div class="toplinks"> | |
| <a href="https://huggingface.co/MiniMaxAI/MiniMax-H3" target="_blank" rel="noopener">مدل</a> | |
| <a href="https://www.minimax.io/blog/minimax-h3" target="_blank" rel="noopener">وبلاگ</a> | |
| <a href="https://huggingface.co/spaces/Sada8888/Rvcpro" target="_blank" rel="noopener">Space اصلی ↗</a> | |
| </div> | |
| </div> | |
| <p class="intro"> | |
| <b>MiniMax-H3</b> مدلی ۳۳ میلیارد پارامتری برای تولید ویدیو بههمراه صدای هماهنگ (محیط، افکت و گفتار) است. | |
| یک تصویر، صدا یا ویدیوی مرجع اضافه کنید و توصیف موردنظرتان را بنویسید. این صفحه هیچ سروری ندارد؛ همهچیز | |
| مستقیماً از مرورگر شما به Space بالا وصل میشود. | |
| </p> | |
| <div id="connError" class="banner" hidden></div> | |
| <main class="layout"> | |
| <!-- ===== فرم ===== --> | |
| <section class="panel"> | |
| <div class="field"> | |
| <span class="field-label">توصیف (Prompt)</span> | |
| <textarea id="promptInput" rows="3">The character walks through a neon-lit street in the rain, humming to themselves</textarea> | |
| </div> | |
| <label class="checkbox-row"> | |
| <input type="checkbox" id="upsampleCheck" /> | |
| <span>بهبود خودکار متن توصیف (Upsample prompt)</span> | |
| </label> | |
| <div class="tabs"> | |
| <div class="tab-buttons"> | |
| <button type="button" class="tab-btn active" data-tab="images">تصاویر</button> | |
| <button type="button" class="tab-btn" data-tab="audio">صدا</button> | |
| <button type="button" class="tab-btn" data-tab="video">ویدیو</button> | |
| </div> | |
| <div class="tab-panel" data-panel="images"> | |
| <div id="imageSlots" class="image-grid"></div> | |
| <button type="button" id="addImageBtn" class="btn-ghost">+ افزودن تصویر دیگر</button> | |
| </div> | |
| <div class="tab-panel" data-panel="audio" hidden> | |
| <div class="dropzone" id="audioDrop"> | |
| <input type="file" id="audioInput" accept="audio/*" hidden /> | |
| <p>یک فایل صوتی (صدا یا موسیقی) را انتخاب کنید</p> | |
| </div> | |
| <audio id="audioPreview" controls hidden></audio> | |
| <button type="button" id="audioClearBtn" class="clear-link" hidden>حذف فایل صوتی</button> | |
| </div> | |
| <div class="tab-panel" data-panel="video" hidden> | |
| <div class="dropzone" id="videoDrop"> | |
| <input type="file" id="videoInput" accept="video/*" hidden /> | |
| <p>حرکت و دوربین، بین ۲ تا ۱۵ ثانیه — صدای آن هم همراه میآید</p> | |
| </div> | |
| <video id="videoPreview" controls hidden></video> | |
| <button type="button" id="videoClearBtn" class="clear-link" hidden>حذف ویدیوی مرجع</button> | |
| </div> | |
| </div> | |
| <button type="button" id="generateBtn" class="btn-primary btn-lg">ساخت ویدیو</button> | |
| <div id="trackingBox" class="tracking-box" hidden> | |
| <span class="field-label">کد پیگیری</span> | |
| <div class="tracking-row"> | |
| <code id="trackingCodeText"></code> | |
| <button type="button" id="copyCodeBtn" class="btn-ghost">کپی کد</button> | |
| </div> | |
| </div> | |
| <p id="submitStatus" class="status-text"></p> | |
| <details class="accordion-native"> | |
| <summary>دریافت با کد پیگیری</summary> | |
| <div class="accordion-native-body"> | |
| <div class="row-inline"> | |
| <input type="text" id="retrieveCodeInput" placeholder="مثلاً K7XQPA" /> | |
| <button type="button" id="retrieveBtn" class="btn-secondary">بررسی وضعیت</button> | |
| </div> | |
| <p id="retrieveStatus" class="status-text"></p> | |
| </div> | |
| </details> | |
| <details class="accordion-native"> | |
| <summary>تنظیمات پیشرفته</summary> | |
| <div class="accordion-native-body advanced-grid"> | |
| <label class="field"> | |
| <span class="field-label">قاب تصویر (Canvas)</span> | |
| <select id="canvasSelect"></select> | |
| </label> | |
| <label class="field" id="matchField" hidden> | |
| <span class="checkbox-row"> | |
| <input type="checkbox" id="matchCheck" checked /> | |
| <span>مدت زمان از روی صدای مرجع تعیین شود</span> | |
| </span> | |
| </label> | |
| <label class="field" id="durationField"> | |
| <span class="field-label">مدت زمان (ثانیه): <b id="durationValueText">5</b></span> | |
| <div class="range-row"> | |
| <input type="range" id="durationRange" min="2" max="14" step="1" value="5" /> | |
| </div> | |
| </label> | |
| <label class="field"> | |
| <span class="field-label">تعداد گامها (Steps): <b id="stepsValueText">28</b></span> | |
| <div class="range-row"> | |
| <input type="range" id="stepsRange" min="10" max="40" step="1" value="28" /> | |
| </div> | |
| </label> | |
| <label class="field"> | |
| <span class="field-label">Seed</span> | |
| <input type="number" id="seedInput" value="42" step="1" /> | |
| </label> | |
| <hr class="divider" /> | |
| <label class="field"> | |
| <span class="field-label">توکن Hugging Face (اختیاری)</span> | |
| <input type="password" id="hfTokenInput" placeholder="hf_xxxxxxxxxxxxxxxxxxxx" autocomplete="off" dir="ltr" /> | |
| </label> | |
| <div class="field"> | |
| <span class="field-label"> </span> | |
| <button type="button" id="clearTokenBtn" class="btn-ghost" style="width:fit-content;">حذف توکن ذخیرهشده</button> | |
| </div> | |
| <p class="status-text" style="grid-column:1/-1;margin-top:-4px;"> | |
| این توکن فقط داخل همین مرورگر (localStorage) ذخیره میشود و مستقیماً برای فراخوانی همین Space | |
| (<span dir="ltr" class="code-chip">Sada8888/Rvcpro</span>) استفاده میشود؛ به هیچ سرور دیگری ارسال نمیشود. | |
| وارد کردن توکن باعث میشود درخواست از سهمیهٔ GPU حساب خودتان در Hugging Face استفاده کند. | |
| </p> | |
| </div> | |
| </details> | |
| </section> | |
| <!-- ===== خروجی ===== --> | |
| <section class="panel"> | |
| <h2 style="margin-top:0;font-size:1.05rem;">خروجی</h2> | |
| <div id="resultVideoWrap" class="video-frame empty"> | |
| <p class="placeholder">ویدیوی تولیدشده اینجا نمایش داده میشود.</p> | |
| </div> | |
| </section> | |
| </main> | |
| <!-- ===== سابقه ===== --> | |
| <section class="panel history-panel"> | |
| <div class="history-head"> | |
| <h2>سابقه</h2> | |
| <button type="button" id="clearHistoryBtn" class="btn-ghost">پاککردن همه سابقه</button> | |
| </div> | |
| <p class="history-note"> | |
| هر درخواستی که میسازید، بههمراه کد پیگیریاش بهصورت دائمی در همین مرورگر ذخیره میشود. | |
| هر زمان خواستید روی «پیگیری» بزنید تا وضعیت و ویدیوی نهایی از Space دریافت شود. | |
| </p> | |
| <div id="historyList" class="history-list"></div> | |
| <p id="historyEmptyNote">هنوز درخواستی ثبت نشده است.</p> | |
| </section> | |
| </div> | |
| <footer class="note"> | |
| <div class="wrap" style="padding:0;"> | |
| این صفحه فقط به Space رسمی <b dir="ltr">Sada8888/Rvcpro</b> (مدل MiniMax-H3) روی Hugging Face متصل میشود؛ | |
| درخواستها مستقیماً از مرورگر شما به آن Space ارسال میگردد و از طریق هیچ سرور واسطهای عبور نمیکند. | |
| لطفاً فقط از تصاویر، صدا یا ویدیوهایی استفاده کنید که اجازهٔ استفاده از آنها را دارید؛ خود Space درخواستهای | |
| نامناسب را بهصورت خودکار رد میکند. | |
| </div> | |
| </footer> | |
| <script type="module"> | |
| const SPACE_ID = "Sada8888/Rvcpro"; | |
| const SPACE_HOST = "https://sada8888-rvcpro.hf.space"; | |
| const HISTORY_KEY = "h3_rvcpro_history_v1"; | |
| const TOKEN_KEY = "h3_rvcpro_hf_token_v1"; | |
| const MAX_IMAGE_SLOTS = 9; | |
| const OPEN_IMAGE_SLOTS = 2; | |
| const CANVASES = [ | |
| "960x544 · 16:9 fast", "1024x576 · 16:9 fast", "1152x640 · 16:9", | |
| "1280x704 · 16:9", "1344x768 · 16:9 full", | |
| "544x960 · 9:16 fast", "640x1152 · 9:16", "768x1344 · 9:16 full", | |
| "544x544 · 1:1 fast", "768x768 · 1:1 full", "1024x1024 · 1:1 max", | |
| "768x576 · 4:3 fast", "1024x768 · 4:3 full", "576x768 · 3:4 fast", "768x1024 · 3:4 full", | |
| "1152x512 · 21:9 fast", "1536x672 · 21:9 full", | |
| ]; | |
| const DEFAULT_CANVAS = "960x544 · 16:9 fast"; | |
| /* ---------- عناصر DOM ---------- */ | |
| const $ = (id) => document.getElementById(id); | |
| const connErrorEl = $("connError"); | |
| const promptInput = $("promptInput"); | |
| const upsampleCheck = $("upsampleCheck"); | |
| const imageSlotsEl = $("imageSlots"); | |
| const addImageBtn = $("addImageBtn"); | |
| const audioInput = $("audioInput"), audioDrop = $("audioDrop"), audioPreview = $("audioPreview"), audioClearBtn = $("audioClearBtn"); | |
| const videoInput = $("videoInput"), videoDrop = $("videoDrop"), videoPreview = $("videoPreview"), videoClearBtn = $("videoClearBtn"); | |
| const generateBtn = $("generateBtn"); | |
| const trackingBox = $("trackingBox"), trackingCodeText = $("trackingCodeText"), copyCodeBtn = $("copyCodeBtn"); | |
| const submitStatus = $("submitStatus"); | |
| const retrieveCodeInput = $("retrieveCodeInput"), retrieveBtn = $("retrieveBtn"), retrieveStatus = $("retrieveStatus"); | |
| const canvasSelect = $("canvasSelect"); | |
| const matchField = $("matchField"), matchCheck = $("matchCheck"); | |
| const durationField = $("durationField"), durationRange = $("durationRange"), durationValueText = $("durationValueText"); | |
| const stepsRange = $("stepsRange"), stepsValueText = $("stepsValueText"); | |
| const seedInput = $("seedInput"); | |
| const hfTokenInput = $("hfTokenInput"), clearTokenBtn = $("clearTokenBtn"); | |
| const resultVideoWrap = $("resultVideoWrap"); | |
| const historyListEl = $("historyList"), historyEmptyNote = $("historyEmptyNote"), clearHistoryBtn = $("clearHistoryBtn"); | |
| /* ---------- ابزارهای کمکی ---------- */ | |
| function escapeHtml(str) { | |
| return String(str ?? "").replace(/[&<>"']/g, c => ({ "&":"&","<":"<",">":">",'"':""","'":"'" }[c])); | |
| } | |
| function mdLite(escapedText) { | |
| return escapedText | |
| .replace(/\*\*(.*?)\*\*/g, "<b>$1</b>") | |
| .replace(/`([^`]+)`/g, "<code>$1</code>") | |
| .replace(/\n\n/g, "<br><br>") | |
| .replace(/\n/g, "<br>"); | |
| } | |
| function truncate(str, n) { | |
| if (!str) return ""; | |
| return str.length > n ? str.slice(0, n) + "…" : str; | |
| } | |
| function makeId() { | |
| return (crypto.randomUUID ? crypto.randomUUID() : "id-" + Date.now() + "-" + Math.random().toString(16).slice(2)); | |
| } | |
| function copyText(text) { | |
| navigator.clipboard?.writeText(text).catch(() => {}); | |
| } | |
| /* ---------- بارگذاری کتابخانه Gradio Client ---------- */ | |
| let GradioClient = null, handle_file = null, libReady = false; | |
| (async () => { | |
| try { | |
| const mod = await import("https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js"); | |
| GradioClient = mod.Client; | |
| handle_file = mod.handle_file; | |
| libReady = true; | |
| } catch (err) { | |
| connErrorEl.hidden = false; | |
| connErrorEl.textContent = "بارگذاری کتابخانهٔ ارتباط با Space ناموفق بود. اتصال اینترنت خود را بررسی کنید. (" + (err?.message || err) + ")"; | |
| } | |
| })(); | |
| let cachedClient = null, cachedToken; | |
| async function getClient() { | |
| if (!libReady) throw new Error("کتابخانهٔ ارتباط با Space هنوز آماده نیست؛ چند لحظه صبر کنید و دوباره تلاش کنید."); | |
| const token = hfTokenInput.value.trim() || undefined; | |
| if (cachedClient && cachedToken === token) return cachedClient; | |
| const opts = {}; | |
| if (token) { opts.hf_token = token; opts.token = token; } | |
| cachedClient = await GradioClient.connect(SPACE_ID, opts); | |
| cachedToken = token; | |
| return cachedClient; | |
| } | |
| function resolveFileUrl(data) { | |
| if (!data) return null; | |
| if (typeof data === "string") return data; | |
| if (data.url) return data.url; | |
| if (data.path) return `${SPACE_HOST}/file=${encodeURIComponent(data.path)}`; | |
| return null; | |
| } | |
| function classifyStatus(text, url) { | |
| if (url) return "done"; | |
| if (!text) return "unknown"; | |
| if (/This request failed/i.test(text)) return "error"; | |
| if (/Generating now/i.test(text)) return "running"; | |
| if (/Submitted, not started yet/i.test(text)) return "queued"; | |
| if (/Ready\s*—/i.test(text)) return "done"; | |
| return "unknown"; | |
| } | |
| async function checkJobByCode(code) { | |
| const app = await getClient(); | |
| const result = await app.predict("/check_job", { code }); | |
| const [videoData, statusText] = result.data; | |
| return { url: resolveFileUrl(videoData), statusText }; | |
| } | |
| function showResultVideo(url) { | |
| resultVideoWrap.innerHTML = `<video controls autoplay src="${url}"></video>`; | |
| resultVideoWrap.classList.remove("empty"); | |
| } | |
| /* ---------- تبها ---------- */ | |
| document.querySelectorAll(".tab-btn").forEach(btn => { | |
| btn.addEventListener("click", () => { | |
| document.querySelectorAll(".tab-btn").forEach(b => b.classList.remove("active")); | |
| btn.classList.add("active"); | |
| const tab = btn.dataset.tab; | |
| document.querySelectorAll(".tab-panel").forEach(p => { p.hidden = p.dataset.panel !== tab; }); | |
| }); | |
| }); | |
| /* ---------- اسلاتهای تصویر ---------- */ | |
| const imageFiles = new Array(MAX_IMAGE_SLOTS).fill(null); | |
| let openImageCount = OPEN_IMAGE_SLOTS; | |
| for (let i = 0; i < MAX_IMAGE_SLOTS; i++) { | |
| const slot = document.createElement("div"); | |
| slot.className = "image-slot"; | |
| slot.style.display = i < OPEN_IMAGE_SLOTS ? "" : "none"; | |
| slot.innerHTML = ` | |
| <input type="file" accept="image/*" hidden /> | |
| <div class="slot-inner"><span class="slot-hint">تصویر ${i + 1}<br>(سوژه، سبک یا صحنه)</span></div> | |
| <button type="button" class="remove-btn" hidden title="حذف">✕</button> | |
| `; | |
| const input = slot.querySelector("input"); | |
| const inner = slot.querySelector(".slot-inner"); | |
| const removeBtn = slot.querySelector(".remove-btn"); | |
| slot.addEventListener("click", (e) => { if (e.target !== removeBtn) input.click(); }); | |
| input.addEventListener("change", () => { | |
| const file = input.files[0]; | |
| if (!file) return; | |
| imageFiles[i] = file; | |
| inner.innerHTML = `<img src="${URL.createObjectURL(file)}" alt="تصویر ${i + 1}" />`; | |
| removeBtn.hidden = false; | |
| }); | |
| removeBtn.addEventListener("click", (e) => { | |
| e.stopPropagation(); | |
| imageFiles[i] = null; | |
| input.value = ""; | |
| inner.innerHTML = `<span class="slot-hint">تصویر ${i + 1}<br>(سوژه، سبک یا صحنه)</span>`; | |
| removeBtn.hidden = true; | |
| }); | |
| imageSlotsEl.appendChild(slot); | |
| } | |
| addImageBtn.addEventListener("click", () => { | |
| if (openImageCount >= MAX_IMAGE_SLOTS) return; | |
| const nextSlot = imageSlotsEl.children[openImageCount]; | |
| if (nextSlot) nextSlot.style.display = ""; | |
| openImageCount++; | |
| if (openImageCount >= MAX_IMAGE_SLOTS) addImageBtn.hidden = true; | |
| }); | |
| /* ---------- صدا و ویدیوی مرجع ---------- */ | |
| let audioFile = null, videoFile = null; | |
| function probeMediaDuration(file) { | |
| return new Promise(resolve => { | |
| if (!file) return resolve(null); | |
| const isAudio = file.type.startsWith("audio"); | |
| const el = document.createElement(isAudio ? "audio" : "video"); | |
| el.preload = "metadata"; | |
| const url = URL.createObjectURL(file); | |
| el.onloadedmetadata = () => { resolve(el.duration || null); URL.revokeObjectURL(url); }; | |
| el.onerror = () => { resolve(null); URL.revokeObjectURL(url); }; | |
| el.src = url; | |
| }); | |
| } | |
| async function updateDurationControls() { | |
| const carried = []; | |
| if (audioFile) { const d = await probeMediaDuration(audioFile); if (d) carried.push(d); } | |
| if (videoFile) { const d = await probeMediaDuration(videoFile); if (d) carried.push(d); } | |
| const derivable = carried.length === 1 && carried[0] >= 2 && carried[0] <= 15; | |
| matchField.hidden = !derivable; | |
| durationField.hidden = derivable && matchCheck.checked; | |
| } | |
| matchCheck.addEventListener("change", updateDurationControls); | |
| audioDrop.addEventListener("click", () => audioInput.click()); | |
| audioInput.addEventListener("change", async () => { | |
| const file = audioInput.files[0]; | |
| if (!file) return; | |
| audioFile = file; | |
| audioPreview.src = URL.createObjectURL(file); | |
| audioPreview.hidden = false; | |
| audioClearBtn.hidden = false; | |
| await updateDurationControls(); | |
| }); | |
| audioClearBtn.addEventListener("click", async () => { | |
| audioFile = null; audioInput.value = ""; | |
| audioPreview.hidden = true; audioPreview.removeAttribute("src"); | |
| audioClearBtn.hidden = true; | |
| await updateDurationControls(); | |
| }); | |
| videoDrop.addEventListener("click", () => videoInput.click()); | |
| videoInput.addEventListener("change", async () => { | |
| const file = videoInput.files[0]; | |
| if (!file) return; | |
| videoFile = file; | |
| videoPreview.src = URL.createObjectURL(file); | |
| videoPreview.hidden = false; | |
| videoClearBtn.hidden = false; | |
| await updateDurationControls(); | |
| }); | |
| videoClearBtn.addEventListener("click", async () => { | |
| videoFile = null; videoInput.value = ""; | |
| videoPreview.hidden = true; videoPreview.removeAttribute("src"); | |
| videoClearBtn.hidden = true; | |
| await updateDurationControls(); | |
| }); | |
| /* ---------- گزینههای قاب تصویر ---------- */ | |
| CANVASES.forEach(label => { | |
| const opt = document.createElement("option"); | |
| opt.value = label; opt.textContent = label; | |
| if (label === DEFAULT_CANVAS) opt.selected = true; | |
| canvasSelect.appendChild(opt); | |
| }); | |
| /* ---------- اسلایدرها ---------- */ | |
| durationRange.addEventListener("input", () => durationValueText.textContent = durationRange.value); | |
| stepsRange.addEventListener("input", () => stepsValueText.textContent = stepsRange.value); | |
| /* ---------- توکن Hugging Face ---------- */ | |
| hfTokenInput.value = localStorage.getItem(TOKEN_KEY) || ""; | |
| hfTokenInput.addEventListener("change", () => { | |
| const v = hfTokenInput.value.trim(); | |
| if (v) localStorage.setItem(TOKEN_KEY, v); else localStorage.removeItem(TOKEN_KEY); | |
| }); | |
| clearTokenBtn.addEventListener("click", () => { | |
| hfTokenInput.value = ""; | |
| localStorage.removeItem(TOKEN_KEY); | |
| }); | |
| /* ---------- سابقه (History) ---------- */ | |
| function loadHistory() { | |
| try { return JSON.parse(localStorage.getItem(HISTORY_KEY) || "[]"); } catch { return []; } | |
| } | |
| function saveHistory(list) { localStorage.setItem(HISTORY_KEY, JSON.stringify(list)); } | |
| function addHistoryEntry(entry) { | |
| const list = loadHistory(); list.unshift(entry); saveHistory(list); renderHistory(); | |
| } | |
| function patchHistoryEntry(id, patch) { | |
| const list = loadHistory(); | |
| const idx = list.findIndex(x => x.id === id); | |
| if (idx === -1) return; | |
| list[idx] = { ...list[idx], ...patch }; | |
| saveHistory(list); renderHistory(); | |
| } | |
| function removeHistoryEntry(id) { | |
| saveHistory(loadHistory().filter(x => x.id !== id)); | |
| renderHistory(); | |
| } | |
| const badgeLabels = { queued: "در صف", running: "در حال ساخت", done: "آماده", error: "خطا", unknown: "نامشخص" }; | |
| function renderHistory() { | |
| const list = loadHistory(); | |
| historyListEl.innerHTML = ""; | |
| historyEmptyNote.hidden = list.length !== 0; | |
| list.forEach(item => { | |
| const kind = item.statusKind || "unknown"; | |
| const card = document.createElement("div"); | |
| card.className = "history-item"; | |
| card.innerHTML = ` | |
| <div class="history-item-top"> | |
| <div class="history-prompt">${escapeHtml(truncate(item.prompt, 90))}</div> | |
| <span class="badge badge-${kind}">${badgeLabels[kind] || "نامشخص"}</span> | |
| </div> | |
| <div class="history-meta"> | |
| <span>${new Date(item.createdAt).toLocaleString("fa-IR")}</span> | |
| <span class="code-chip">${escapeHtml(item.code)}</span> | |
| ${item.canvas ? `<span dir="ltr">${escapeHtml(item.canvas)}</span>` : ""} | |
| </div> | |
| <div class="history-actions"> | |
| <button type="button" class="btn-secondary act-track">پیگیری</button> | |
| <button type="button" class="btn-ghost act-copy">کپی کد</button> | |
| ${item.videoUrl ? `<a class="btn-ghost" download target="_blank" rel="noopener" href="${item.videoUrl}">دانلود ویدیو</a>` : ""} | |
| <button type="button" class="btn-ghost act-delete">حذف</button> | |
| </div> | |
| <p class="status-text small">${mdLite(escapeHtml(item.statusText || ""))}</p> | |
| ${item.videoUrl ? `<video controls src="${item.videoUrl}"></video>` : ""} | |
| `; | |
| card.querySelector(".act-track").addEventListener("click", (e) => trackHistoryItem(item.id, e.currentTarget)); | |
| card.querySelector(".act-copy").addEventListener("click", () => copyText(item.code)); | |
| card.querySelector(".act-delete").addEventListener("click", () => { | |
| if (confirm("این مورد از سابقه حذف شود؟")) removeHistoryEntry(item.id); | |
| }); | |
| historyListEl.appendChild(card); | |
| }); | |
| } | |
| async function trackHistoryItem(id, btnEl) { | |
| const item = loadHistory().find(x => x.id === id); | |
| if (!item) return; | |
| if (btnEl) { btnEl.disabled = true; btnEl.innerHTML = "در حال بررسی...<span class=\"spin\"></span>"; } | |
| try { | |
| const { url, statusText } = await checkJobByCode(item.code); | |
| const kind = classifyStatus(statusText, url); | |
| patchHistoryEntry(id, { statusText, statusKind: kind, videoUrl: url || item.videoUrl }); | |
| if (kind === "done" && url) showResultVideo(url); | |
| } catch (err) { | |
| patchHistoryEntry(id, { statusText: "خطا در بررسی وضعیت: " + (err?.message || err), statusKind: "error" }); | |
| } | |
| } | |
| function autoPoll(id, attempt) { | |
| if (attempt > 100) return; | |
| setTimeout(async () => { | |
| await trackHistoryItem(id, null); | |
| const item = loadHistory().find(x => x.id === id); | |
| if (!item || item.statusKind === "done" || item.statusKind === "error") return; | |
| autoPoll(id, attempt + 1); | |
| }, 6000); | |
| } | |
| clearHistoryBtn.addEventListener("click", () => { | |
| if (!confirm("همهٔ سابقه پاک شود؟ این کار قابل بازگشت نیست.")) return; | |
| saveHistory([]); renderHistory(); | |
| }); | |
| /* ---------- ساخت ویدیو (Generate) ---------- */ | |
| generateBtn.addEventListener("click", async () => { | |
| const prompt = promptInput.value.trim(); | |
| if (!prompt) { submitStatus.innerHTML = escapeHtml("برای شروع، یک توصیف بنویسید."); return; } | |
| const hasImage = imageFiles.some(Boolean); | |
| if (!hasImage && !videoFile) { | |
| submitStatus.innerHTML = escapeHtml("حداقل یک تصویر یا یک ویدیوی مرجع اضافه کنید."); | |
| return; | |
| } | |
| if (imageFiles.every(f => !f) && !videoFile && audioFile) { | |
| submitStatus.innerHTML = escapeHtml("صدا بهتنهایی کافی نیست؛ یک تصویر یا ویدیو هم اضافه کنید."); | |
| return; | |
| } | |
| generateBtn.disabled = true; | |
| const original = generateBtn.textContent; | |
| generateBtn.innerHTML = "در حال ارسال...<span class=\"spin\"></span>"; | |
| submitStatus.innerHTML = ""; | |
| try { | |
| const app = await getClient(); | |
| const payload = { | |
| prompt, | |
| canvas: canvasSelect.value, | |
| match: matchCheck.checked, | |
| duration: Number(durationRange.value), | |
| steps: Number(stepsRange.value), | |
| seed: Number(seedInput.value), | |
| upsample: upsampleCheck.checked, | |
| }; | |
| imageFiles.forEach((file, idx) => { if (file) payload[`image_${idx + 1}`] = handle_file(file); }); | |
| if (audioFile) payload.audio_path = handle_file(audioFile); | |
| if (videoFile) payload.video_path = handle_file(videoFile); | |
| const result = await app.predict("/submit_job", payload); | |
| const [code, statusText] = result.data; | |
| trackingBox.hidden = false; | |
| trackingCodeText.textContent = code; | |
| submitStatus.innerHTML = mdLite(escapeHtml(statusText)); | |
| const id = makeId(); | |
| addHistoryEntry({ | |
| id, code, prompt, canvas: canvasSelect.value, | |
| createdAt: Date.now(), statusKind: "queued", statusText, videoUrl: null, | |
| }); | |
| autoPoll(id, 0); | |
| } catch (err) { | |
| submitStatus.innerHTML = "خطا در ارسال درخواست: " + escapeHtml(err?.message || String(err)); | |
| } finally { | |
| generateBtn.disabled = false; | |
| generateBtn.textContent = original; | |
| } | |
| }); | |
| copyCodeBtn.addEventListener("click", () => copyText(trackingCodeText.textContent)); | |
| /* ---------- دریافت با کد پیگیری (دستی) ---------- */ | |
| retrieveBtn.addEventListener("click", async () => { | |
| const code = retrieveCodeInput.value.trim().toUpperCase(); | |
| if (!code) { retrieveStatus.textContent = "یک کد پیگیری وارد کنید."; return; } | |
| retrieveBtn.disabled = true; | |
| retrieveStatus.innerHTML = "در حال بررسی..."; | |
| try { | |
| const { url, statusText } = await checkJobByCode(code); | |
| const kind = classifyStatus(statusText, url); | |
| retrieveStatus.innerHTML = mdLite(escapeHtml(statusText)); | |
| if (url) showResultVideo(url); | |
| const existing = loadHistory().find(x => x.code === code); | |
| if (existing) { | |
| patchHistoryEntry(existing.id, { statusText, statusKind: kind, videoUrl: url || existing.videoUrl }); | |
| } else { | |
| addHistoryEntry({ | |
| id: makeId(), code, prompt: "(بازیابیشده با کد پیگیری)", canvas: "", | |
| createdAt: Date.now(), statusKind: kind, statusText, videoUrl: url, | |
| }); | |
| } | |
| } catch (err) { | |
| retrieveStatus.textContent = "خطا: " + (err?.message || err); | |
| } finally { | |
| retrieveBtn.disabled = false; | |
| } | |
| }); | |
| retrieveCodeInput.addEventListener("keydown", (e) => { if (e.key === "Enter") retrieveBtn.click(); }); | |
| /* ---------- شروع ---------- */ | |
| renderHistory(); | |
| </script> | |
| </body> | |
| </html> |