Spaces:
Running
Running
handle incorrect yaml
Browse files- front/src/components/PodcastGenerator.tsx +12 -1
- front/src/components/ScriptMaker.tsx +2 -2
- index.html +33 -2
front/src/components/PodcastGenerator.tsx
CHANGED
@@ -73,6 +73,17 @@ const getRandomSpeakerPair = (): { s1: string; s2: string } => {
|
|
73 |
return { s1, s2 };
|
74 |
};
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
export const PodcastGenerator = ({
|
77 |
genratedScript,
|
78 |
setBusy,
|
@@ -107,7 +118,7 @@ export const PodcastGenerator = ({
|
|
107 |
setWav(null);
|
108 |
setBusy(true);
|
109 |
try {
|
110 |
-
const podcast
|
111 |
const { speakerNames, turns } = podcast;
|
112 |
for (const turn of turns) {
|
113 |
// normalize it
|
|
|
73 |
return { s1, s2 };
|
74 |
};
|
75 |
|
76 |
+
const parseYAML = (yaml: string): Podcast => {
|
77 |
+
try {
|
78 |
+
return parse(yaml);
|
79 |
+
} catch (e) {
|
80 |
+
console.error(e);
|
81 |
+
throw new Error(
|
82 |
+
'invalid YAML, please re-generate the script: ' + (e as any).message
|
83 |
+
);
|
84 |
+
}
|
85 |
+
};
|
86 |
+
|
87 |
export const PodcastGenerator = ({
|
88 |
genratedScript,
|
89 |
setBusy,
|
|
|
118 |
setWav(null);
|
119 |
setBusy(true);
|
120 |
try {
|
121 |
+
const podcast = parseYAML(script);
|
122 |
const { speakerNames, turns } = podcast;
|
123 |
for (const turn of turns) {
|
124 |
// normalize it
|
front/src/components/ScriptMaker.tsx
CHANGED
@@ -209,7 +209,7 @@ export const ScriptMaker = ({
|
|
209 |
)}
|
210 |
</button>
|
211 |
|
212 |
-
|
213 |
<svg
|
214 |
xmlns="http://www.w3.org/2000/svg"
|
215 |
fill="none"
|
@@ -228,7 +228,7 @@ export const ScriptMaker = ({
|
|
228 |
re-generate the script or adding a note to force it to follow YAML
|
229 |
format.
|
230 |
</span>
|
231 |
-
</div>
|
232 |
</div>
|
233 |
</div>
|
234 |
);
|
|
|
209 |
)}
|
210 |
</button>
|
211 |
|
212 |
+
<div role="alert" className="alert text-sm">
|
213 |
<svg
|
214 |
xmlns="http://www.w3.org/2000/svg"
|
215 |
fill="none"
|
|
|
228 |
re-generate the script or adding a note to force it to follow YAML
|
229 |
format.
|
230 |
</span>
|
231 |
+
</div>
|
232 |
</div>
|
233 |
</div>
|
234 |
);
|
index.html
CHANGED
@@ -20997,6 +20997,16 @@ const getRandomSpeakerPair = () => {
|
|
20997 |
).value;
|
20998 |
return { s1, s2 };
|
20999 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21000 |
const PodcastGenerator = ({
|
21001 |
genratedScript,
|
21002 |
setBusy,
|
@@ -21023,7 +21033,7 @@ const PodcastGenerator = ({
|
|
21023 |
setWav(null);
|
21024 |
setBusy(true);
|
21025 |
try {
|
21026 |
-
const podcast =
|
21027 |
const { speakerNames, turns } = podcast;
|
21028 |
for (const turn of turns) {
|
21029 |
turn.nextGapMilisecs = Math.max(-600, Math.min(300, turn.nextGapMilisecs)) - 100;
|
@@ -22801,7 +22811,28 @@ const ScriptMaker = ({
|
|
22801 |
"Generating..."
|
22802 |
] }) : "Generate script"
|
22803 |
}
|
22804 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22805 |
] }) });
|
22806 |
};
|
22807 |
var __defProp2 = Object.defineProperty;
|
|
|
20997 |
).value;
|
20998 |
return { s1, s2 };
|
20999 |
};
|
21000 |
+
const parseYAML = (yaml) => {
|
21001 |
+
try {
|
21002 |
+
return parse$3(yaml);
|
21003 |
+
} catch (e) {
|
21004 |
+
console.error(e);
|
21005 |
+
throw new Error(
|
21006 |
+
"invalid YAML, please re-generate the script: " + e.message
|
21007 |
+
);
|
21008 |
+
}
|
21009 |
+
};
|
21010 |
const PodcastGenerator = ({
|
21011 |
genratedScript,
|
21012 |
setBusy,
|
|
|
21033 |
setWav(null);
|
21034 |
setBusy(true);
|
21035 |
try {
|
21036 |
+
const podcast = parseYAML(script);
|
21037 |
const { speakerNames, turns } = podcast;
|
21038 |
for (const turn of turns) {
|
21039 |
turn.nextGapMilisecs = Math.max(-600, Math.min(300, turn.nextGapMilisecs)) - 100;
|
|
|
22811 |
"Generating..."
|
22812 |
] }) : "Generate script"
|
22813 |
}
|
22814 |
+
),
|
22815 |
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { role: "alert", className: "alert text-sm", children: [
|
22816 |
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
22817 |
+
"svg",
|
22818 |
+
{
|
22819 |
+
xmlns: "http://www.w3.org/2000/svg",
|
22820 |
+
fill: "none",
|
22821 |
+
viewBox: "0 0 24 24",
|
22822 |
+
className: "stroke-info h-6 w-6 shrink-0",
|
22823 |
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
22824 |
+
"path",
|
22825 |
+
{
|
22826 |
+
strokeLinecap: "round",
|
22827 |
+
strokeLinejoin: "round",
|
22828 |
+
strokeWidth: "2",
|
22829 |
+
d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
22830 |
+
}
|
22831 |
+
)
|
22832 |
+
}
|
22833 |
+
),
|
22834 |
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "The LLM may generate an incorrect YAML. If it fails on Step 2, re-generate the script or adding a note to force it to follow YAML format." })
|
22835 |
+
] })
|
22836 |
] }) });
|
22837 |
};
|
22838 |
var __defProp2 = Object.defineProperty;
|