Spaces:
Running
Running
test sign in
Browse files- front/package.json +2 -2
- front/src/App.tsx +20 -11
- front/src/components/AuthCard.tsx +56 -8
- front/src/config.ts +7 -10
- front/src/utils/utils.ts +3 -0
- index.html +232 -51
front/package.json
CHANGED
@@ -4,8 +4,8 @@
|
|
4 |
"version": "0.0.0",
|
5 |
"type": "module",
|
6 |
"scripts": {
|
7 |
-
"dev": "vite",
|
8 |
-
"build": "tsc -b && vite build && cp ./dist/index.html ../index.html",
|
9 |
"lint": "eslint .",
|
10 |
"format": "npm run lint && prettier --write .",
|
11 |
"preview": "vite preview"
|
|
|
4 |
"version": "0.0.0",
|
5 |
"type": "module",
|
6 |
"scripts": {
|
7 |
+
"dev": "VITE_TEST_TOKEN=$(cat ~/.cache/huggingface/token) vite",
|
8 |
+
"build": "npm run format && tsc -b && vite build && cp ./dist/index.html ../index.html",
|
9 |
"lint": "eslint .",
|
10 |
"format": "npm run lint && prettier --write .",
|
11 |
"preview": "vite preview"
|
front/src/App.tsx
CHANGED
@@ -5,6 +5,7 @@ import { ScriptMaker } from './components/ScriptMaker';
|
|
5 |
import { AuthCard } from './components/AuthCard';
|
6 |
|
7 |
function App() {
|
|
|
8 |
const [genratedScript, setGeneratedScript] = useState<string>('');
|
9 |
const [busy, setBusy] = useState<boolean>(false);
|
10 |
|
@@ -21,19 +22,27 @@ function App() {
|
|
21 |
</p>
|
22 |
</div>
|
23 |
|
24 |
-
<AuthCard />
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
37 |
</div>
|
38 |
</div>
|
39 |
);
|
|
|
5 |
import { AuthCard } from './components/AuthCard';
|
6 |
|
7 |
function App() {
|
8 |
+
const [hfToken, setHfToken] = useState<string>('loading');
|
9 |
const [genratedScript, setGeneratedScript] = useState<string>('');
|
10 |
const [busy, setBusy] = useState<boolean>(false);
|
11 |
|
|
|
22 |
</p>
|
23 |
</div>
|
24 |
|
25 |
+
<AuthCard hfToken={hfToken} setHfToken={setHfToken} />
|
26 |
|
27 |
+
{hfToken === 'loading' ? (
|
28 |
+
<div className="p-4 col-span-1">
|
29 |
+
<div className="loading loading-spinner loading-lg"></div>
|
30 |
+
</div>
|
31 |
+
) : (
|
32 |
+
<>
|
33 |
+
<ScriptMaker
|
34 |
+
setScript={setGeneratedScript}
|
35 |
+
setBusy={setBusy}
|
36 |
+
busy={busy}
|
37 |
+
/>
|
38 |
|
39 |
+
<PodcastGenerator
|
40 |
+
genratedScript={genratedScript}
|
41 |
+
setBusy={setBusy}
|
42 |
+
busy={busy}
|
43 |
+
/>
|
44 |
+
</>
|
45 |
+
)}
|
46 |
</div>
|
47 |
</div>
|
48 |
);
|
front/src/components/AuthCard.tsx
CHANGED
@@ -1,17 +1,65 @@
|
|
1 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
const login = async () => {
|
4 |
const url = await oauthLoginUrl();
|
5 |
window.location.href = url;
|
6 |
-
}
|
7 |
|
8 |
-
export const AuthCard = (
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
<div className="card-body">
|
11 |
-
<h2 className="card-title">
|
|
|
|
|
12 |
<div>
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
</div>
|
|
|
15 |
</div>
|
16 |
-
|
17 |
-
}
|
|
|
1 |
+
import {
|
2 |
+
oauthLoginUrl,
|
3 |
+
oauthHandleRedirectIfPresent,
|
4 |
+
whoAmI,
|
5 |
+
} from '@huggingface/hub';
|
6 |
+
import { useEffect } from 'react';
|
7 |
+
import { isDev, testToken } from '../utils/utils';
|
8 |
|
9 |
const login = async () => {
|
10 |
const url = await oauthLoginUrl();
|
11 |
window.location.href = url;
|
12 |
+
};
|
13 |
|
14 |
+
export const AuthCard = ({
|
15 |
+
setHfToken,
|
16 |
+
hfToken,
|
17 |
+
}: {
|
18 |
+
setHfToken: (token: string) => void;
|
19 |
+
hfToken: string;
|
20 |
+
}) => {
|
21 |
+
useEffect(() => {
|
22 |
+
const checkToken = async () => {
|
23 |
+
if (isDev) {
|
24 |
+
console.log({ testToken });
|
25 |
+
return setHfToken(testToken);
|
26 |
+
}
|
27 |
+
const res = await oauthHandleRedirectIfPresent();
|
28 |
+
console.log('oauthHandleRedirectIfPresent', res);
|
29 |
+
if (res) {
|
30 |
+
try {
|
31 |
+
const myself = whoAmI({ accessToken: res.accessToken });
|
32 |
+
console.log('myself', myself);
|
33 |
+
} catch (e) {
|
34 |
+
console.log(e);
|
35 |
+
return setHfToken('');
|
36 |
+
}
|
37 |
+
return setHfToken(res.accessToken);
|
38 |
+
} else {
|
39 |
+
return setHfToken('');
|
40 |
+
}
|
41 |
+
};
|
42 |
+
checkToken();
|
43 |
+
}, []);
|
44 |
+
|
45 |
+
const isOK = hfToken && hfToken.startsWith('hf_');
|
46 |
+
|
47 |
+
return (
|
48 |
+
<div className="card bg-base-100 w-full shadow-xl">
|
49 |
<div className="card-body">
|
50 |
+
<h2 className="card-title">
|
51 |
+
Step 0: Sign in to use Inference Providers
|
52 |
+
</h2>
|
53 |
<div>
|
54 |
+
{isOK ? (
|
55 |
+
<button className="btn">✅ Nice, you are signed in</button>
|
56 |
+
) : (
|
57 |
+
<button className="btn btn-primary" onClick={login}>
|
58 |
+
🤗 Sign in with Hugging Face
|
59 |
+
</button>
|
60 |
+
)}
|
61 |
</div>
|
62 |
+
</div>
|
63 |
</div>
|
64 |
+
);
|
65 |
+
};
|
front/src/config.ts
CHANGED
@@ -1,17 +1,14 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
return urlParams.get(paramName);
|
4 |
-
}
|
5 |
|
6 |
-
|
7 |
-
const LLM_ENDPOINT =
|
8 |
|
9 |
export const CONFIG = {
|
10 |
llmEndpoint:
|
11 |
-
LLM_ENDPOINT
|
12 |
-
|
13 |
-
|
14 |
-
ttsSpaceId: SPACE_ID || 'ngxson/kokoro-podcast-generator',
|
15 |
};
|
16 |
|
17 |
console.log({ CONFIG });
|
|
|
1 |
+
// @ts-expect-error this is custom
|
2 |
+
const TTS_SPACE_ID = window.huggingface?.variables?.TTS_SPACE_ID;
|
|
|
|
|
3 |
|
4 |
+
// @ts-expect-error this is custom
|
5 |
+
const LLM_ENDPOINT = window.huggingface?.variables?.LLM_ENDPOINT;
|
6 |
|
7 |
export const CONFIG = {
|
8 |
llmEndpoint:
|
9 |
+
LLM_ENDPOINT ||
|
10 |
+
'https://gnb1thady6h3noiz.us-east-1.aws.endpoints.huggingface.cloud/v1/chat/completions',
|
11 |
+
ttsSpaceId: TTS_SPACE_ID || 'ngxson/kokoro-podcast-backend',
|
|
|
12 |
};
|
13 |
|
14 |
console.log({ CONFIG });
|
front/src/utils/utils.ts
CHANGED
@@ -6,6 +6,9 @@ import { Client } from '@gradio/client';
|
|
6 |
import { asyncIterator } from '@sec-ant/readable-stream/ponyfill/asyncIterator';
|
7 |
import { CONFIG } from '../config';
|
8 |
|
|
|
|
|
|
|
9 |
// return URL to the WAV file
|
10 |
export const generateAudio = async (
|
11 |
content: string,
|
|
|
6 |
import { asyncIterator } from '@sec-ant/readable-stream/ponyfill/asyncIterator';
|
7 |
import { CONFIG } from '../config';
|
8 |
|
9 |
+
export const isDev: boolean = import.meta.env.MODE === 'development';
|
10 |
+
export const testToken: string = import.meta.env.VITE_TEST_TOKEN;
|
11 |
+
|
12 |
// return URL to the WAV file
|
13 |
export const generateAudio = async (
|
14 |
content: string,
|
index.html
CHANGED
@@ -13,7 +13,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
13 |
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
14 |
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
15 |
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
16 |
-
var _buf, _allowCR, _returnEmptyLines, _mapperFun, _TextLineStream_instances, handle_fn, _a, _t, _n, _r, _e, _u_instances, s_fn, i_fn;
|
17 |
(function polyfill() {
|
18 |
const relList = document.createElement("link").relList;
|
19 |
if (relList && relList.supports && relList.supports("modulepreload")) {
|
@@ -12337,12 +12337,12 @@ function transform_api_info(api_info, config, api_map) {
|
|
12337 |
transformed_info[category] = {};
|
12338 |
Object.entries(api_info[category]).forEach(
|
12339 |
([endpoint, { parameters, returns }]) => {
|
12340 |
-
var _a2,
|
12341 |
const dependencyIndex = ((_a2 = config.dependencies.find(
|
12342 |
(dep) => dep.api_name === endpoint || dep.api_name === endpoint.replace("/", "")
|
12343 |
)) == null ? void 0 : _a2.id) || api_map[endpoint.replace("/", "")] || -1;
|
12344 |
-
const dependencyTypes = dependencyIndex !== -1 ? (
|
12345 |
-
if (dependencyIndex !== -1 && ((
|
12346 |
const components = config.dependencies.find((dep) => dep.id == dependencyIndex).inputs.map(
|
12347 |
(input) => {
|
12348 |
var _a22;
|
@@ -12821,8 +12821,8 @@ async function walk_and_store_blobs(data, type = void 0, path = [], root = false
|
|
12821 |
return [];
|
12822 |
}
|
12823 |
function skip_queue(id, config) {
|
12824 |
-
var _a2,
|
12825 |
-
let fn_queue = (
|
12826 |
if (fn_queue != null) {
|
12827 |
return !fn_queue;
|
12828 |
}
|
@@ -12908,8 +12908,8 @@ async function handle_blob(endpoint, data, api_info) {
|
|
12908 |
return data;
|
12909 |
}
|
12910 |
async function process_local_file_commands(client2, data) {
|
12911 |
-
var _a2,
|
12912 |
-
const root = ((_a2 = client2.config) == null ? void 0 : _a2.root) || ((
|
12913 |
if (!root) {
|
12914 |
throw new Error(ROOT_URL_ERROR_MSG);
|
12915 |
}
|
@@ -12925,9 +12925,9 @@ async function recursively_process_commands(client2, data, path = []) {
|
|
12925 |
}
|
12926 |
}
|
12927 |
async function process_single_command(client2, data, key) {
|
12928 |
-
var _a2,
|
12929 |
let cmd_item = data[key];
|
12930 |
-
const root = ((_a2 = client2.config) == null ? void 0 : _a2.root) || ((
|
12931 |
if (!root) {
|
12932 |
throw new Error(ROOT_URL_ERROR_MSG);
|
12933 |
}
|
@@ -14775,15 +14775,11 @@ function h(r, { preventCancel: e = false } = {}) {
|
|
14775 |
), s = Object.create(l);
|
14776 |
return s[n] = a, s;
|
14777 |
}
|
14778 |
-
|
14779 |
-
|
14780 |
-
return urlParams.get(paramName);
|
14781 |
-
}
|
14782 |
-
const SPACE_ID = getUrlParam("SPACE_ID");
|
14783 |
-
const LLM_ENDPOINT = getUrlParam("LLM_ENDPOINT");
|
14784 |
const CONFIG = {
|
14785 |
-
llmEndpoint: LLM_ENDPOINT
|
14786 |
-
ttsSpaceId:
|
14787 |
};
|
14788 |
console.log({ CONFIG });
|
14789 |
const generateAudio = async (content, voice, speed = 1.1) => {
|
@@ -15127,19 +15123,19 @@ function initVisitor(visitor) {
|
|
15127 |
return visitor;
|
15128 |
}
|
15129 |
function callVisitor(key, node, visitor, path) {
|
15130 |
-
var _a2,
|
15131 |
if (typeof visitor === "function")
|
15132 |
return visitor(key, node, path);
|
15133 |
if (isMap(node))
|
15134 |
return (_a2 = visitor.Map) == null ? void 0 : _a2.call(visitor, key, node, path);
|
15135 |
if (isSeq(node))
|
15136 |
-
return (
|
15137 |
if (isPair(node))
|
15138 |
-
return (
|
15139 |
if (isScalar(node))
|
15140 |
-
return (
|
15141 |
if (isAlias(node))
|
15142 |
-
return (
|
15143 |
return void 0;
|
15144 |
}
|
15145 |
function replaceNode(key, path, node) {
|
@@ -15592,13 +15588,13 @@ function findTagObject(value, tagName, tags) {
|
|
15592 |
});
|
15593 |
}
|
15594 |
function createNode(value, tagName, ctx) {
|
15595 |
-
var _a2,
|
15596 |
if (isDocument(value))
|
15597 |
value = value.contents;
|
15598 |
if (isNode(value))
|
15599 |
return value;
|
15600 |
if (isPair(value)) {
|
15601 |
-
const map2 = (
|
15602 |
map2.items.push(value);
|
15603 |
return map2;
|
15604 |
}
|
@@ -15637,7 +15633,7 @@ function createNode(value, tagName, ctx) {
|
|
15637 |
onTagObj(tagObj);
|
15638 |
delete ctx.onTagObj;
|
15639 |
}
|
15640 |
-
const node = (tagObj == null ? void 0 : tagObj.createNode) ? tagObj.createNode(ctx.schema, value, ctx) : typeof ((
|
15641 |
if (tagName)
|
15642 |
node.tag = tagName;
|
15643 |
else if (!tagObj.default)
|
@@ -21486,7 +21482,7 @@ const ScriptMaker = ({
|
|
21486 |
setBusy(isGenerating);
|
21487 |
}, [isGenerating]);
|
21488 |
const generate = async () => {
|
21489 |
-
var _a2,
|
21490 |
setIsGenerating(true);
|
21491 |
setThought("");
|
21492 |
try {
|
@@ -21514,7 +21510,7 @@ const ScriptMaker = ({
|
|
21514 |
const chunks = getSSEStreamAsync(fetchResponse);
|
21515 |
for await (const chunk of chunks) {
|
21516 |
if (chunk.error) {
|
21517 |
-
throw new Error(((
|
21518 |
}
|
21519 |
const addedContent = chunk.choices[0].delta.content;
|
21520 |
responseContent += addedContent;
|
@@ -21625,11 +21621,11 @@ var __publicField = (obj, key, value) => {
|
|
21625 |
};
|
21626 |
var HUB_URL = "https://huggingface.co";
|
21627 |
async function createApiError(response, opts) {
|
21628 |
-
var _a2,
|
21629 |
const error2 = new HubApiError(response.url, response.status, (_a2 = response.headers.get("X-Request-Id")) != null ? _a2 : void 0);
|
21630 |
error2.message = `Api error with status ${error2.statusCode}${""}`;
|
21631 |
const trailer = [`URL: ${error2.url}`, error2.requestId ? `Request ID: ${error2.requestId}` : void 0].filter(Boolean).join(". ");
|
21632 |
-
if ((
|
21633 |
const json = await response.json();
|
21634 |
error2.message = json.error || json.message || error2.message;
|
21635 |
if (json.error_description) {
|
@@ -21654,6 +21650,22 @@ var HubApiError = class extends Error {
|
|
21654 |
this.url = url;
|
21655 |
}
|
21656 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21657 |
new Promise((r) => {
|
21658 |
});
|
21659 |
function base64FromBytes(arr) {
|
@@ -21667,8 +21679,131 @@ function base64FromBytes(arr) {
|
|
21667 |
return globalThis.btoa(bin.join(""));
|
21668 |
}
|
21669 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21670 |
async function oauthLoginUrl(opts) {
|
21671 |
-
var _a2,
|
21672 |
if (typeof window === "undefined" && true) {
|
21673 |
throw new Error("oauthLogin is only available in the browser, unless you provide clientId and redirectUrl");
|
21674 |
}
|
@@ -21705,7 +21840,7 @@ async function oauthLoginUrl(opts) {
|
|
21705 |
});
|
21706 |
const variables = (
|
21707 |
// @ts-expect-error window.huggingface is defined inside static Spaces.
|
21708 |
-
typeof window !== "undefined" ? (
|
21709 |
);
|
21710 |
const clientId = variables == null ? void 0 : variables.OAUTH_CLIENT_ID;
|
21711 |
if (!clientId) {
|
@@ -21727,17 +21862,58 @@ async function oauthLoginUrl(opts) {
|
|
21727 |
code_challenge_method: "S256"
|
21728 |
}).toString()}`;
|
21729 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21730 |
const login = async () => {
|
21731 |
const url = await oauthLoginUrl();
|
21732 |
window.location.href = url;
|
21733 |
};
|
21734 |
-
const AuthCard = (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21735 |
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "card bg-base-100 w-full shadow-xl", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "card-body", children: [
|
21736 |
/* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "card-title", children: "Step 0: Sign in to use Inference Providers" }),
|
21737 |
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("button", { className: "btn btn-primary", onClick: login, children: "🤗 Sign in with Hugging Face" }) })
|
21738 |
] }) });
|
21739 |
};
|
21740 |
function App() {
|
|
|
21741 |
const [genratedScript, setGeneratedScript] = reactExports.useState("");
|
21742 |
const [busy, setBusy] = reactExports.useState(false);
|
21743 |
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "bg-base-300 min-h-screen", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "max-w-screen-lg mx-auto p-4 pb-32 grid gap-4 grid-cols-1", children: [
|
@@ -21749,23 +21925,25 @@ function App() {
|
|
21749 |
/* @__PURE__ */ jsxRuntimeExports.jsx(OpenInNewTab, { href: "https://hf.co/ngxson", children: "🤗 ngxson" })
|
21750 |
] })
|
21751 |
] }),
|
21752 |
-
/* @__PURE__ */ jsxRuntimeExports.jsx(AuthCard, {}),
|
21753 |
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
21754 |
-
|
21755 |
-
|
21756 |
-
|
21757 |
-
|
21758 |
-
|
21759 |
-
|
21760 |
-
|
21761 |
-
|
21762 |
-
|
21763 |
-
|
21764 |
-
|
21765 |
-
|
21766 |
-
|
21767 |
-
|
21768 |
-
|
|
|
|
|
21769 |
] }) });
|
21770 |
}
|
21771 |
if (!localStorage.getItem("debug")) {
|
@@ -26905,6 +27083,9 @@ html {
|
|
26905 |
.loading-sm {
|
26906 |
width: 1.25rem;
|
26907 |
}
|
|
|
|
|
|
|
26908 |
.mockup-browser .mockup-browser-toolbar .input {
|
26909 |
position: relative;
|
26910 |
margin-left: auto;
|
|
|
13 |
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
14 |
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
15 |
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
16 |
+
var _buf, _allowCR, _returnEmptyLines, _mapperFun, _TextLineStream_instances, handle_fn, _a, _t, _n, _r, _e, _u_instances, s_fn, i_fn, _b, _c, _d, _e2;
|
17 |
(function polyfill() {
|
18 |
const relList = document.createElement("link").relList;
|
19 |
if (relList && relList.supports && relList.supports("modulepreload")) {
|
|
|
12337 |
transformed_info[category] = {};
|
12338 |
Object.entries(api_info[category]).forEach(
|
12339 |
([endpoint, { parameters, returns }]) => {
|
12340 |
+
var _a2, _b2, _c2, _d2;
|
12341 |
const dependencyIndex = ((_a2 = config.dependencies.find(
|
12342 |
(dep) => dep.api_name === endpoint || dep.api_name === endpoint.replace("/", "")
|
12343 |
)) == null ? void 0 : _a2.id) || api_map[endpoint.replace("/", "")] || -1;
|
12344 |
+
const dependencyTypes = dependencyIndex !== -1 ? (_b2 = config.dependencies.find((dep) => dep.id == dependencyIndex)) == null ? void 0 : _b2.types : { generator: false, cancel: false };
|
12345 |
+
if (dependencyIndex !== -1 && ((_d2 = (_c2 = config.dependencies.find((dep) => dep.id == dependencyIndex)) == null ? void 0 : _c2.inputs) == null ? void 0 : _d2.length) !== parameters.length) {
|
12346 |
const components = config.dependencies.find((dep) => dep.id == dependencyIndex).inputs.map(
|
12347 |
(input) => {
|
12348 |
var _a22;
|
|
|
12821 |
return [];
|
12822 |
}
|
12823 |
function skip_queue(id, config) {
|
12824 |
+
var _a2, _b2;
|
12825 |
+
let fn_queue = (_b2 = (_a2 = config == null ? void 0 : config.dependencies) == null ? void 0 : _a2.find((dep) => dep.id == id)) == null ? void 0 : _b2.queue;
|
12826 |
if (fn_queue != null) {
|
12827 |
return !fn_queue;
|
12828 |
}
|
|
|
12908 |
return data;
|
12909 |
}
|
12910 |
async function process_local_file_commands(client2, data) {
|
12911 |
+
var _a2, _b2;
|
12912 |
+
const root = ((_a2 = client2.config) == null ? void 0 : _a2.root) || ((_b2 = client2.config) == null ? void 0 : _b2.root_url);
|
12913 |
if (!root) {
|
12914 |
throw new Error(ROOT_URL_ERROR_MSG);
|
12915 |
}
|
|
|
12925 |
}
|
12926 |
}
|
12927 |
async function process_single_command(client2, data, key) {
|
12928 |
+
var _a2, _b2;
|
12929 |
let cmd_item = data[key];
|
12930 |
+
const root = ((_a2 = client2.config) == null ? void 0 : _a2.root) || ((_b2 = client2.config) == null ? void 0 : _b2.root_url);
|
12931 |
if (!root) {
|
12932 |
throw new Error(ROOT_URL_ERROR_MSG);
|
12933 |
}
|
|
|
14775 |
), s = Object.create(l);
|
14776 |
return s[n] = a, s;
|
14777 |
}
|
14778 |
+
const TTS_SPACE_ID = (_c = (_b = window.huggingface) == null ? void 0 : _b.variables) == null ? void 0 : _c.TTS_SPACE_ID;
|
14779 |
+
const LLM_ENDPOINT = (_e2 = (_d = window.huggingface) == null ? void 0 : _d.variables) == null ? void 0 : _e2.LLM_ENDPOINT;
|
|
|
|
|
|
|
|
|
14780 |
const CONFIG = {
|
14781 |
+
llmEndpoint: LLM_ENDPOINT || "https://gnb1thady6h3noiz.us-east-1.aws.endpoints.huggingface.cloud/v1/chat/completions",
|
14782 |
+
ttsSpaceId: TTS_SPACE_ID || "ngxson/kokoro-podcast-backend"
|
14783 |
};
|
14784 |
console.log({ CONFIG });
|
14785 |
const generateAudio = async (content, voice, speed = 1.1) => {
|
|
|
15123 |
return visitor;
|
15124 |
}
|
15125 |
function callVisitor(key, node, visitor, path) {
|
15126 |
+
var _a2, _b2, _c2, _d2, _e3;
|
15127 |
if (typeof visitor === "function")
|
15128 |
return visitor(key, node, path);
|
15129 |
if (isMap(node))
|
15130 |
return (_a2 = visitor.Map) == null ? void 0 : _a2.call(visitor, key, node, path);
|
15131 |
if (isSeq(node))
|
15132 |
+
return (_b2 = visitor.Seq) == null ? void 0 : _b2.call(visitor, key, node, path);
|
15133 |
if (isPair(node))
|
15134 |
+
return (_c2 = visitor.Pair) == null ? void 0 : _c2.call(visitor, key, node, path);
|
15135 |
if (isScalar(node))
|
15136 |
+
return (_d2 = visitor.Scalar) == null ? void 0 : _d2.call(visitor, key, node, path);
|
15137 |
if (isAlias(node))
|
15138 |
+
return (_e3 = visitor.Alias) == null ? void 0 : _e3.call(visitor, key, node, path);
|
15139 |
return void 0;
|
15140 |
}
|
15141 |
function replaceNode(key, path, node) {
|
|
|
15588 |
});
|
15589 |
}
|
15590 |
function createNode(value, tagName, ctx) {
|
15591 |
+
var _a2, _b2, _c2;
|
15592 |
if (isDocument(value))
|
15593 |
value = value.contents;
|
15594 |
if (isNode(value))
|
15595 |
return value;
|
15596 |
if (isPair(value)) {
|
15597 |
+
const map2 = (_b2 = (_a2 = ctx.schema[MAP]).createNode) == null ? void 0 : _b2.call(_a2, ctx.schema, null, ctx);
|
15598 |
map2.items.push(value);
|
15599 |
return map2;
|
15600 |
}
|
|
|
15633 |
onTagObj(tagObj);
|
15634 |
delete ctx.onTagObj;
|
15635 |
}
|
15636 |
+
const node = (tagObj == null ? void 0 : tagObj.createNode) ? tagObj.createNode(ctx.schema, value, ctx) : typeof ((_c2 = tagObj == null ? void 0 : tagObj.nodeClass) == null ? void 0 : _c2.from) === "function" ? tagObj.nodeClass.from(ctx.schema, value, ctx) : new Scalar(value);
|
15637 |
if (tagName)
|
15638 |
node.tag = tagName;
|
15639 |
else if (!tagObj.default)
|
|
|
21482 |
setBusy(isGenerating);
|
21483 |
}, [isGenerating]);
|
21484 |
const generate = async () => {
|
21485 |
+
var _a2, _b2;
|
21486 |
setIsGenerating(true);
|
21487 |
setThought("");
|
21488 |
try {
|
|
|
21510 |
const chunks = getSSEStreamAsync(fetchResponse);
|
21511 |
for await (const chunk of chunks) {
|
21512 |
if (chunk.error) {
|
21513 |
+
throw new Error(((_b2 = chunk.error) == null ? void 0 : _b2.message) || "Unknown error");
|
21514 |
}
|
21515 |
const addedContent = chunk.choices[0].delta.content;
|
21516 |
responseContent += addedContent;
|
|
|
21621 |
};
|
21622 |
var HUB_URL = "https://huggingface.co";
|
21623 |
async function createApiError(response, opts) {
|
21624 |
+
var _a2, _b2;
|
21625 |
const error2 = new HubApiError(response.url, response.status, (_a2 = response.headers.get("X-Request-Id")) != null ? _a2 : void 0);
|
21626 |
error2.message = `Api error with status ${error2.statusCode}${""}`;
|
21627 |
const trailer = [`URL: ${error2.url}`, error2.requestId ? `Request ID: ${error2.requestId}` : void 0].filter(Boolean).join(". ");
|
21628 |
+
if ((_b2 = response.headers.get("Content-Type")) == null ? void 0 : _b2.startsWith("application/json")) {
|
21629 |
const json = await response.json();
|
21630 |
error2.message = json.error || json.message || error2.message;
|
21631 |
if (json.error_description) {
|
|
|
21650 |
this.url = url;
|
21651 |
}
|
21652 |
};
|
21653 |
+
function checkAccessToken(accessToken) {
|
21654 |
+
if (!accessToken.startsWith("hf_")) {
|
21655 |
+
throw new TypeError("Your access token must start with 'hf_'");
|
21656 |
+
}
|
21657 |
+
}
|
21658 |
+
function checkCredentials(params) {
|
21659 |
+
var _a2;
|
21660 |
+
if (params.accessToken) {
|
21661 |
+
checkAccessToken(params.accessToken);
|
21662 |
+
return params.accessToken;
|
21663 |
+
}
|
21664 |
+
if ((_a2 = params.credentials) == null ? void 0 : _a2.accessToken) {
|
21665 |
+
checkAccessToken(params.credentials.accessToken);
|
21666 |
+
return params.credentials.accessToken;
|
21667 |
+
}
|
21668 |
+
}
|
21669 |
new Promise((r) => {
|
21670 |
});
|
21671 |
function base64FromBytes(arr) {
|
|
|
21679 |
return globalThis.btoa(bin.join(""));
|
21680 |
}
|
21681 |
}
|
21682 |
+
async function oauthHandleRedirect(opts) {
|
21683 |
+
var _a2, _b2, _c2;
|
21684 |
+
if (typeof window === "undefined" && true) {
|
21685 |
+
throw new Error("oauthHandleRedirect is only available in the browser, unless you provide redirectedUrl");
|
21686 |
+
}
|
21687 |
+
if (typeof localStorage === "undefined" && true) {
|
21688 |
+
throw new Error(
|
21689 |
+
"oauthHandleRedirect requires localStorage to be available, unless you provide nonce and codeVerifier"
|
21690 |
+
);
|
21691 |
+
}
|
21692 |
+
const redirectedUrl = (_a2 = void 0) != null ? _a2 : window.location.href;
|
21693 |
+
const searchParams = (() => {
|
21694 |
+
try {
|
21695 |
+
return new URL(redirectedUrl).searchParams;
|
21696 |
+
} catch (err) {
|
21697 |
+
throw new Error("Failed to parse redirected URL: " + redirectedUrl);
|
21698 |
+
}
|
21699 |
+
})();
|
21700 |
+
const [error2, errorDescription] = [searchParams.get("error"), searchParams.get("error_description")];
|
21701 |
+
if (error2) {
|
21702 |
+
throw new Error(`${error2}: ${errorDescription}`);
|
21703 |
+
}
|
21704 |
+
const code = searchParams.get("code");
|
21705 |
+
const nonce = (_b2 = void 0) != null ? _b2 : localStorage.getItem("huggingface.co:oauth:nonce");
|
21706 |
+
if (!code) {
|
21707 |
+
throw new Error("Missing oauth code from query parameters in redirected URL: " + redirectedUrl);
|
21708 |
+
}
|
21709 |
+
if (!nonce) {
|
21710 |
+
throw new Error("Missing oauth nonce from localStorage");
|
21711 |
+
}
|
21712 |
+
const codeVerifier = (_c2 = void 0) != null ? _c2 : localStorage.getItem("huggingface.co:oauth:code_verifier");
|
21713 |
+
if (!codeVerifier) {
|
21714 |
+
throw new Error("Missing oauth code_verifier from localStorage");
|
21715 |
+
}
|
21716 |
+
const state = searchParams.get("state");
|
21717 |
+
if (!state) {
|
21718 |
+
throw new Error("Missing oauth state from query parameters in redirected URL");
|
21719 |
+
}
|
21720 |
+
let parsedState;
|
21721 |
+
try {
|
21722 |
+
parsedState = JSON.parse(state);
|
21723 |
+
} catch (e) {
|
21724 |
+
throw new Error("Invalid oauth state in redirected URL, unable to parse JSON: " + state);
|
21725 |
+
}
|
21726 |
+
if (parsedState.nonce !== nonce) {
|
21727 |
+
throw new Error("Invalid oauth state in redirected URL");
|
21728 |
+
}
|
21729 |
+
const hubUrl = HUB_URL;
|
21730 |
+
const openidConfigUrl = `${new URL(hubUrl).origin}/.well-known/openid-configuration`;
|
21731 |
+
const openidConfigRes = await fetch(openidConfigUrl, {
|
21732 |
+
headers: {
|
21733 |
+
Accept: "application/json"
|
21734 |
+
}
|
21735 |
+
});
|
21736 |
+
if (!openidConfigRes.ok) {
|
21737 |
+
throw await createApiError(openidConfigRes);
|
21738 |
+
}
|
21739 |
+
const openidConfig = await openidConfigRes.json();
|
21740 |
+
const tokenRes = await fetch(openidConfig.token_endpoint, {
|
21741 |
+
method: "POST",
|
21742 |
+
headers: {
|
21743 |
+
"Content-Type": "application/x-www-form-urlencoded"
|
21744 |
+
},
|
21745 |
+
body: new URLSearchParams({
|
21746 |
+
grant_type: "authorization_code",
|
21747 |
+
code,
|
21748 |
+
redirect_uri: parsedState.redirectUri,
|
21749 |
+
code_verifier: codeVerifier
|
21750 |
+
}).toString()
|
21751 |
+
});
|
21752 |
+
{
|
21753 |
+
localStorage.removeItem("huggingface.co:oauth:code_verifier");
|
21754 |
+
}
|
21755 |
+
{
|
21756 |
+
localStorage.removeItem("huggingface.co:oauth:nonce");
|
21757 |
+
}
|
21758 |
+
if (!tokenRes.ok) {
|
21759 |
+
throw await createApiError(tokenRes);
|
21760 |
+
}
|
21761 |
+
const token = await tokenRes.json();
|
21762 |
+
const accessTokenExpiresAt = new Date(Date.now() + token.expires_in * 1e3);
|
21763 |
+
const userInfoRes = await fetch(openidConfig.userinfo_endpoint, {
|
21764 |
+
headers: {
|
21765 |
+
Authorization: `Bearer ${token.access_token}`
|
21766 |
+
}
|
21767 |
+
});
|
21768 |
+
if (!userInfoRes.ok) {
|
21769 |
+
throw await createApiError(userInfoRes);
|
21770 |
+
}
|
21771 |
+
const userInfo = await userInfoRes.json();
|
21772 |
+
return {
|
21773 |
+
accessToken: token.access_token,
|
21774 |
+
accessTokenExpiresAt,
|
21775 |
+
userInfo,
|
21776 |
+
state: parsedState.state,
|
21777 |
+
scope: token.scope
|
21778 |
+
};
|
21779 |
+
}
|
21780 |
+
async function oauthHandleRedirectIfPresent(opts) {
|
21781 |
+
var _a2;
|
21782 |
+
if (typeof window === "undefined" && true) {
|
21783 |
+
throw new Error("oauthHandleRedirect is only available in the browser, unless you provide redirectedUrl");
|
21784 |
+
}
|
21785 |
+
if (typeof localStorage === "undefined" && true) {
|
21786 |
+
throw new Error(
|
21787 |
+
"oauthHandleRedirect requires localStorage to be available, unless you provide nonce and codeVerifier"
|
21788 |
+
);
|
21789 |
+
}
|
21790 |
+
const searchParams = new URLSearchParams((_a2 = void 0) != null ? _a2 : window.location.search);
|
21791 |
+
if (searchParams.has("error")) {
|
21792 |
+
return oauthHandleRedirect();
|
21793 |
+
}
|
21794 |
+
if (searchParams.has("code")) {
|
21795 |
+
if (!localStorage.getItem("huggingface.co:oauth:nonce")) {
|
21796 |
+
console.warn(
|
21797 |
+
"Missing oauth nonce from localStorage. This can happen when the user refreshes the page after logging in, without changing the URL."
|
21798 |
+
);
|
21799 |
+
return false;
|
21800 |
+
}
|
21801 |
+
return oauthHandleRedirect();
|
21802 |
+
}
|
21803 |
+
return false;
|
21804 |
+
}
|
21805 |
async function oauthLoginUrl(opts) {
|
21806 |
+
var _a2, _b2;
|
21807 |
if (typeof window === "undefined" && true) {
|
21808 |
throw new Error("oauthLogin is only available in the browser, unless you provide clientId and redirectUrl");
|
21809 |
}
|
|
|
21840 |
});
|
21841 |
const variables = (
|
21842 |
// @ts-expect-error window.huggingface is defined inside static Spaces.
|
21843 |
+
typeof window !== "undefined" ? (_b2 = (_a2 = window.huggingface) == null ? void 0 : _a2.variables) != null ? _b2 : null : null
|
21844 |
);
|
21845 |
const clientId = variables == null ? void 0 : variables.OAUTH_CLIENT_ID;
|
21846 |
if (!clientId) {
|
|
|
21862 |
code_challenge_method: "S256"
|
21863 |
}).toString()}`;
|
21864 |
}
|
21865 |
+
async function whoAmI(params) {
|
21866 |
+
var _a2, _b2, _c2;
|
21867 |
+
const accessToken = checkCredentials(params);
|
21868 |
+
const res = await ((_a2 = params.fetch) != null ? _a2 : fetch)(`${(_b2 = params.hubUrl) != null ? _b2 : HUB_URL}/api/whoami-v2`, {
|
21869 |
+
headers: {
|
21870 |
+
Authorization: `Bearer ${accessToken}`
|
21871 |
+
}
|
21872 |
+
});
|
21873 |
+
if (!res.ok) {
|
21874 |
+
throw await createApiError(res);
|
21875 |
+
}
|
21876 |
+
const response = await res.json();
|
21877 |
+
if (typeof ((_c2 = response.auth.accessToken) == null ? void 0 : _c2.createdAt) === "string") {
|
21878 |
+
response.auth.accessToken.createdAt = new Date(response.auth.accessToken.createdAt);
|
21879 |
+
}
|
21880 |
+
return response;
|
21881 |
+
}
|
21882 |
const login = async () => {
|
21883 |
const url = await oauthLoginUrl();
|
21884 |
window.location.href = url;
|
21885 |
};
|
21886 |
+
const AuthCard = ({
|
21887 |
+
setHfToken,
|
21888 |
+
hfToken
|
21889 |
+
}) => {
|
21890 |
+
reactExports.useEffect(() => {
|
21891 |
+
const checkToken = async () => {
|
21892 |
+
const res = await oauthHandleRedirectIfPresent();
|
21893 |
+
console.log("oauthHandleRedirectIfPresent", res);
|
21894 |
+
if (res) {
|
21895 |
+
try {
|
21896 |
+
const myself = whoAmI({ accessToken: res.accessToken });
|
21897 |
+
console.log("myself", myself);
|
21898 |
+
} catch (e) {
|
21899 |
+
console.log(e);
|
21900 |
+
return setHfToken("");
|
21901 |
+
}
|
21902 |
+
return setHfToken(res.accessToken);
|
21903 |
+
} else {
|
21904 |
+
return setHfToken("");
|
21905 |
+
}
|
21906 |
+
};
|
21907 |
+
checkToken();
|
21908 |
+
}, []);
|
21909 |
+
const isOK = hfToken && hfToken.startsWith("hf_");
|
21910 |
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "card bg-base-100 w-full shadow-xl", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "card-body", children: [
|
21911 |
/* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "card-title", children: "Step 0: Sign in to use Inference Providers" }),
|
21912 |
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: isOK ? /* @__PURE__ */ jsxRuntimeExports.jsx("button", { className: "btn", children: "✅ Nice, you are signed in" }) : /* @__PURE__ */ jsxRuntimeExports.jsx("button", { className: "btn btn-primary", onClick: login, children: "🤗 Sign in with Hugging Face" }) })
|
21913 |
] }) });
|
21914 |
};
|
21915 |
function App() {
|
21916 |
+
const [hfToken, setHfToken] = reactExports.useState("loading");
|
21917 |
const [genratedScript, setGeneratedScript] = reactExports.useState("");
|
21918 |
const [busy, setBusy] = reactExports.useState(false);
|
21919 |
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "bg-base-300 min-h-screen", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "max-w-screen-lg mx-auto p-4 pb-32 grid gap-4 grid-cols-1", children: [
|
|
|
21925 |
/* @__PURE__ */ jsxRuntimeExports.jsx(OpenInNewTab, { href: "https://hf.co/ngxson", children: "🤗 ngxson" })
|
21926 |
] })
|
21927 |
] }),
|
21928 |
+
/* @__PURE__ */ jsxRuntimeExports.jsx(AuthCard, { hfToken, setHfToken }),
|
21929 |
+
hfToken === "loading" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 col-span-1", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "loading loading-spinner loading-lg" }) }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
21930 |
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
21931 |
+
ScriptMaker,
|
21932 |
+
{
|
21933 |
+
setScript: setGeneratedScript,
|
21934 |
+
setBusy,
|
21935 |
+
busy
|
21936 |
+
}
|
21937 |
+
),
|
21938 |
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
21939 |
+
PodcastGenerator,
|
21940 |
+
{
|
21941 |
+
genratedScript,
|
21942 |
+
setBusy,
|
21943 |
+
busy
|
21944 |
+
}
|
21945 |
+
)
|
21946 |
+
] })
|
21947 |
] }) });
|
21948 |
}
|
21949 |
if (!localStorage.getItem("debug")) {
|
|
|
27083 |
.loading-sm {
|
27084 |
width: 1.25rem;
|
27085 |
}
|
27086 |
+
.loading-lg {
|
27087 |
+
width: 2.5rem;
|
27088 |
+
}
|
27089 |
.mockup-browser .mockup-browser-toolbar .input {
|
27090 |
position: relative;
|
27091 |
margin-left: auto;
|