File size: 8,296 Bytes
767029b
7867f84
 
 
 
3807d96
7867f84
9133f0d
 
 
 
7867f84
 
9133f0d
 
 
 
 
7867f84
9133f0d
7867f84
 
 
3807d96
7867f84
 
 
 
 
 
 
e51a1d5
9133f0d
c93f6a1
9133f0d
 
 
7867f84
 
 
 
 
9133f0d
7867f84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9133f0d
7867f84
 
9133f0d
 
7867f84
 
 
 
 
 
 
 
 
 
9133f0d
7867f84
 
9133f0d
 
 
7867f84
9133f0d
7867f84
 
 
 
9133f0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7867f84
 
 
 
 
 
 
 
 
 
 
 
 
 
9133f0d
7867f84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9133f0d
7867f84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
767029b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1" />
  <title>Aparna's Iris Queue</title>
  <style>
    body { font-family: system-ui, sans-serif; max-width: 740px; margin: 24px auto; padding: 0 16px; background: #160c14; color: #fdf2f8; }
    h2 { color: #f472b6; }
    label { display: block; margin-top: 14px; font-weight: 600; font-size: 14px; color: #fbcfe8; }
    input, textarea { width: 100%; box-sizing: border-box; margin-top: 6px; padding: 10px; border-radius: 8px; border: 1px solid #831843; background: #281322; color: #fdf2f8; font-size: 14px; }
    .radios { display: flex; gap: 18px; margin-top: 8px; }
    .radios label { display: flex; align-items: center; gap: 6px; margin-top: 0; font-weight: 500; cursor: pointer; }
    .radios input { width: auto; margin: 0; accent-color: #ec4899; }
    .row { display: flex; gap: 8px; align-items: stretch; margin-top: 6px; }
    .row input { margin-top: 0; flex: 1; }
    .btn-sec { padding: 10px 14px; border: 1px solid #9d174d; border-radius: 8px; background: #500724; color: #fbcfe8; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; }
    .btn-pri { margin-top: 18px; width: 100%; padding: 12px; border: 0; border-radius: 8px; background: #ec4899; color: #fff; font-weight: 700; font-size: 16px; cursor: pointer; }
    button:disabled { opacity: 0.6; cursor: wait; }
    #titles_box, #status { margin-top: 10px; padding: 12px; border-radius: 8px; background: #281322; border: 1px solid #831843; white-space: pre-wrap; font-family: monospace; font-size: 13px; max-height: 220px; overflow-y: auto; }
  </style>
</head>
<body>
  <h2>🩷 Aparna's Iris Queue Helper</h2>

  <label>Video Type</label>
  <div class="radios">
    <label><input type="radio" name="video_type" value="shorts" checked /> shorts</label>
    <label><input type="radio" name="video_type" value="longform" /> longform</label>
  </div>

  <label for="access_key">Access Key</label>
  <div class="row">
    <input id="access_key" type="password" placeholder="Paste the token here" />
    <button id="load_titles_btn" class="btn-sec" type="button">Load Last 30 Titles</button>
  </div>
  <div id="titles_box">(Click "Load Last 30 Titles" above to view past titles)</div>

  <label for="video_title">Video Title</label>
  <input id="video_title" type="text" placeholder="Enter catchy clickable YouTube title..." />

  <label for="audio_url">Audio URL</label>
  <div class="row">
    <input id="audio_url" type="url" placeholder="https://..." />
    <button id="paste_btn" class="btn-sec" type="button">Paste from Clipboard</button>
  </div>

  <div id="thumb_wrap">
    <label for="thumb_prompt">Thumbnail Prompt (Longform Only)</label>
    <textarea id="thumb_prompt" rows="4" placeholder="Detailed descriptive visual prompt with bold hook text (longform only)..."></textarea>
  </div>

  <label for="transcript">Raw Transcript</label>
  <textarea id="transcript" rows="9" placeholder="Paste raw spoken transcript (without [SPOKEN WORD])..."></textarea>

  <button id="save_btn" class="btn-pri" type="button">Save Entry</button>
  <div id="status">Ready.</div>

  <script type="module">
    import { downloadFile, uploadFile } from "https://cdn.jsdelivr.net/npm/@huggingface/hub/+esm";

    const keyEl = document.getElementById("access_key");
    const loadBtn = document.getElementById("load_titles_btn");
    const titlesBox = document.getElementById("titles_box");
    const titleEl = document.getElementById("video_title");
    const urlEl = document.getElementById("audio_url");
    const pasteBtn = document.getElementById("paste_btn");
    const thumbWrap = document.getElementById("thumb_wrap");
    const thumbEl = document.getElementById("thumb_prompt");
    const trEl = document.getElementById("transcript");
    const btnEl = document.getElementById("save_btn");
    const stEl = document.getElementById("status");
    const savedFingerprints = new Set();

    const savedKey = localStorage.getItem("aparna_fg_key") || "";
    if (savedKey) keyEl.value = savedKey;

    function getVt() {
      return document.querySelector('input[name="video_type"]:checked')?.value || "shorts";
    }
    function toggleThumb() {
      thumbWrap.style.display = getVt() === "longform" ? "block" : "none";
    }
    document.querySelectorAll('input[name="video_type"]').forEach(r => r.addEventListener("change", toggleThumb));
    toggleThumb();

    loadBtn.addEventListener("click", async () => {
      const token = keyEl.value.trim();
      if (!token) { titlesBox.textContent = "ERROR: Enter Access Key first."; return; }
      localStorage.setItem("aparna_fg_key", token);
      const histPath = getVt() === "longform" ? "history/longform_titles.txt" : "history/shorts_titles.txt";
      titlesBox.textContent = "Loading...";
      try {
        const res = await downloadFile({
          repo: { type: "dataset", name: "AparnaVelvet/Storage" },
          path: histPath,
          accessToken: token,
        });
        const txt = res ? (await res.text()).trim() : "";
        titlesBox.textContent = txt || "(0 titles so far — first run!)";
      } catch (err) {
        titlesBox.textContent = "ERROR loading titles: " + (err?.message || err);
      }
    });

    pasteBtn.addEventListener("click", async () => {
      try {
        const txt = (await navigator.clipboard.readText() || "").trim();
        if (!txt) { stEl.textContent = "Clipboard is empty."; return; }
        urlEl.value = txt;
        stEl.textContent = "Pasted URL from clipboard.";
      } catch (err) {
        stEl.textContent = "Clipboard blocked: " + (err?.message || err);
        urlEl.focus();
      }
    });

    btnEl.addEventListener("click", async () => {
      const token = keyEl.value.trim();
      const vtype = getVt();
      const title = titleEl.value.replace(/[\r\n]+/g, " ").trim();
      const url = urlEl.value.trim();
      const thumbPrompt = vtype === "longform" ? thumbEl.value.replace(/[\r\n]+/g, " ").trim() : "";
      let raw = trEl.value.replace(/\[\s*SPOKEN\s+WORD\s*\]/gi, "").replace(/\s+/g, " ").trim();

      if (!token) { stEl.textContent = "ERROR: Please enter Access Key."; return; }
      if (title.length < 3) { stEl.textContent = "ERROR: Please enter a Video Title."; return; }
      if (!/^https?:\/\/\S+$/i.test(url)) { stEl.textContent = "ERROR: Please enter a valid http/https Audio URL."; return; }
      if (vtype === "longform" && thumbPrompt.length < 10) {
        stEl.textContent = "ERROR: Please enter a detailed Thumbnail Prompt for longform videos.";
        return;
      }
      if (raw.length < 5) { stEl.textContent = "ERROR: Transcript is empty."; return; }

      const fpInput = `${vtype}|${url.toLowerCase()}|${raw.toLowerCase()}`;
      const buf = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(fpInput));
      const fp = Array.from(new Uint8Array(buf)).map(b => b.toString(16).padStart(2, "0")).join("").slice(0, 8);

      if (savedFingerprints.has(fp)) {
        stEl.textContent = "SKIPPED: Duplicate entry already saved in this session.";
        return;
      }

      localStorage.setItem("aparna_fg_key", token);
      btnEl.disabled = true;
      stEl.textContent = "Saving...";

      try {
        const now = new Date();
        const p = (n) => String(n).padStart(2, "0");
        const dateStr = `${now.getUTCFullYear()}${p(now.getUTCMonth()+1)}${p(now.getUTCDate())}`;
        const prefix = vtype === "longform" ? "long" : "short";
        const repoPath = `${vtype}/${prefix}_${dateStr}_${fp}.txt`;
        const body = `TITLE: ${title}\n\nURL: ${url}\n\nTHUMBNAIL_PROMPT:\n${thumbPrompt}\n\nTRANSCRIPT:\n${raw}\n`;

        await uploadFile({
          repo: { type: "dataset", name: "AparnaVelvet/Storage" },
          accessToken: token,
          file: { path: repoPath, content: new Blob([body], { type: "text/plain" }) },
          commitTitle: `Queue ${repoPath} via Iris Queue Space`,
        });
        savedFingerprints.add(fp);
        stEl.textContent = `SUCCESS: Saved ${repoPath}`;
      } catch (err) {
        stEl.textContent = `ERROR: ${err?.message || err}`;
      } finally {
        btnEl.disabled = false;
      }
    });
  </script>
</body>
</html>