| app.post('/generate-video', async (req, res) => { |
| const { prompt } = req.body; |
|
|
| try { |
| const response = await axios({ |
| |
| url: "https://api-inference.huggingface.co/models/guoyww/animatediff-motion-adapter-v1-5-2", |
| method: "POST", |
| headers: { |
| Authorization: `Bearer ${process.env.HF_TOKEN}`, |
| "Content-Type": "application/json", |
| |
| "X-Wait-For-Model": "true" |
| }, |
| data: JSON.stringify({ inputs: prompt }), |
| responseType: 'arraybuffer', |
| timeout: 120000 |
| }); |
|
|
| res.set('Content-Type', 'video/mp4'); |
| res.send(response.data); |
|
|
| } catch (error) { |
| if (error.response && error.response.status === 503) { |
| res.status(503).json({ error: "The AI is still waking up. Please wait 1 minute and try one more time." }); |
| } else { |
| console.error("AI Error:", error.message); |
| res.status(500).json({ error: "Generation timed out. The free API is heavily loaded right now." }); |
| } |
| } |
| }); |