File size: 423 Bytes
77d3f6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const generate = async (text) => {
 const token = 'Your API Token'
 const model = 'facebook/musicgen-large'
 const prompt = text
 const url = `https://api.huggingface.co/v1/models/${model}`
 const response = await fetch(url, {
    method: 'POST',
    body: JSON.stringify({ token, prompt }),
    headers: {
      'Content-Type': 'application/json'
    }
 })
 const json = await response.json()
 return json.generated_text
}