enzostvs HF staff commited on
Commit
4f93fde
1 Parent(s): 781c2a5

test sharing function

Browse files
Files changed (2) hide show
  1. components/form.tsx +4 -1
  2. utils/index.ts +1 -2
components/form.tsx CHANGED
@@ -39,6 +39,7 @@ export const Form = ({ children }: { children: React.ReactNode }) => {
39
  const [loadProgress, setLoadProgress] = useState({});
40
  const [track, setTrack] = useState("");
41
  const [shareLoading, setShareLoading] = useState(false);
 
42
 
43
  const {
44
  form,
@@ -131,6 +132,7 @@ export const Form = ({ children }: { children: React.ReactNode }) => {
131
  const sampling_rate = model.config.audio_encoder.sampling_rate;
132
  const wav = encodeWAV(audio_values.data, sampling_rate);
133
  const blob = new Blob([wav], { type: "audio/wav" });
 
134
  setTrack(URL.createObjectURL(blob));
135
  setStatusText("Done!");
136
  };
@@ -183,6 +185,7 @@ export const Form = ({ children }: { children: React.ReactNode }) => {
183
  onClick={() => {
184
  if (loading || !modelLoaded) return;
185
  setResults({ cover: null, title: null });
 
186
  setTrack("");
187
  generate();
188
  generateMusic();
@@ -226,7 +229,7 @@ export const Form = ({ children }: { children: React.ReactNode }) => {
226
  if (shareLoading) return;
227
  setShareLoading(true);
228
  await share(
229
- track,
230
  {
231
  mood: form.mood,
232
  style: form.style,
 
39
  const [loadProgress, setLoadProgress] = useState({});
40
  const [track, setTrack] = useState("");
41
  const [shareLoading, setShareLoading] = useState(false);
42
+ const [blob, setBlob] = useState<Blob | null>(null);
43
 
44
  const {
45
  form,
 
132
  const sampling_rate = model.config.audio_encoder.sampling_rate;
133
  const wav = encodeWAV(audio_values.data, sampling_rate);
134
  const blob = new Blob([wav], { type: "audio/wav" });
135
+ setBlob(blob);
136
  setTrack(URL.createObjectURL(blob));
137
  setStatusText("Done!");
138
  };
 
185
  onClick={() => {
186
  if (loading || !modelLoaded) return;
187
  setResults({ cover: null, title: null });
188
+ setBlob(null);
189
  setTrack("");
190
  generate();
191
  generateMusic();
 
229
  if (shareLoading) return;
230
  setShareLoading(true);
231
  await share(
232
+ blob,
233
  {
234
  mood: form.mood,
235
  style: form.style,
utils/index.ts CHANGED
@@ -269,8 +269,7 @@ function writeString(view: any, offset: number, string: string) {
269
  export const MODEL_ID = 'Xenova/musicgen-small';
270
 
271
  export async function share(body: any, settings: Record<string, any>, results: Record<string, any>) {
272
- const blobAudio = new Blob([body], { type: 'audio/wav' });
273
- const response = await fetch('https://huggingface.co/uploads', { method: 'POST', body: blobAudio });
274
  if (!response.ok) throw new Error(`Failed to upload audio: ${response.statusText}`);
275
  const url = await response.text();
276
 
 
269
  export const MODEL_ID = 'Xenova/musicgen-small';
270
 
271
  export async function share(body: any, settings: Record<string, any>, results: Record<string, any>) {
272
+ const response = await fetch('https://huggingface.co/uploads', { method: 'POST', body });
 
273
  if (!response.ok) throw new Error(`Failed to upload audio: ${response.statusText}`);
274
  const url = await response.text();
275