enzostvs HF staff commited on
Commit
8cf3257
1 Parent(s): e5bdbf7

test sharing function

Browse files
app/api/generate/title/route.ts CHANGED
@@ -18,7 +18,7 @@ export async function POST(
18
  parameters: {
19
  num_return_sequences: 1,
20
  return_full_text: false,
21
- do_sample: true
22
  }
23
  }),
24
  })
 
18
  parameters: {
19
  num_return_sequences: 1,
20
  return_full_text: false,
21
+ do_sample: false,
22
  }
23
  }),
24
  })
components/form.tsx CHANGED
@@ -158,7 +158,11 @@ export const Form = ({ children }: { children: React.ReactNode }) => {
158
  />
159
  </div>
160
  <div className="max-lg:pb-16">
161
- <div className="w-full sticky top-0">
 
 
 
 
162
  <div className="border rounded-xl p-6 bg-stone-900/40 border-white/5">
163
  <p className="text-amber-200 font-semibold text-xs uppercase mb-3">
164
  Generated prompt
@@ -218,8 +222,9 @@ export const Form = ({ children }: { children: React.ReactNode }) => {
218
  "animate-pulse": shareLoading,
219
  }
220
  )}
221
- onClick={async (e) => {
222
  if (shareLoading) return;
 
223
  await share(
224
  track,
225
  {
@@ -231,9 +236,10 @@ export const Form = ({ children }: { children: React.ReactNode }) => {
231
  },
232
  results
233
  );
 
234
  }}
235
  >
236
- Share my song
237
  </button>
238
  )}
239
  </div>
 
158
  />
159
  </div>
160
  <div className="max-lg:pb-16">
161
+ <div
162
+ className={classNames("w-full", {
163
+ "sticky top-0": !track,
164
+ })}
165
+ >
166
  <div className="border rounded-xl p-6 bg-stone-900/40 border-white/5">
167
  <p className="text-amber-200 font-semibold text-xs uppercase mb-3">
168
  Generated prompt
 
222
  "animate-pulse": shareLoading,
223
  }
224
  )}
225
+ onClick={async () => {
226
  if (shareLoading) return;
227
+ setShareLoading(true);
228
  await share(
229
  track,
230
  {
 
236
  },
237
  results
238
  );
239
+ setShareLoading(false);
240
  }}
241
  >
242
+ {shareLoading ? "Sharing..." : "Share my song"}
243
  </button>
244
  )}
245
  </div>
utils/index.ts CHANGED
@@ -269,7 +269,8 @@ 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 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
 
 
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.audio], { 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