Rooni commited on
Commit
94f215f
·
verified ·
1 Parent(s): ffc35f2

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +8 -2
server.js CHANGED
@@ -31,6 +31,8 @@ app.post('/generate-image', async (req, res) => {
31
  // Динамический импорт node-fetch
32
  const fetch = (await import('node-fetch')).default;
33
 
 
 
34
  const response = await fetch('https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3-medium', {
35
  method: 'POST',
36
  headers: {
@@ -39,19 +41,23 @@ app.post('/generate-image', async (req, res) => {
39
  },
40
  body: JSON.stringify({
41
  inputs: prompt
42
- })
 
 
43
  });
44
 
45
  if (!response.ok) {
46
  throw new Error(`Error from Hugging Face API: ${response.statusText}`);
47
  }
48
 
 
 
49
  const imageBuffer = await response.buffer();
50
  const base64Image = imageBuffer.toString('base64');
51
 
52
  res.json({ image: base64Image });
53
  } catch (error) {
54
- console.error('Error generating image:', error);
55
  res.status(500).send('Error generating image');
56
  }
57
  });
 
31
  // Динамический импорт node-fetch
32
  const fetch = (await import('node-fetch')).default;
33
 
34
+ console.log('Sending request to Hugging Face API...');
35
+
36
  const response = await fetch('https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3-medium', {
37
  method: 'POST',
38
  headers: {
 
41
  },
42
  body: JSON.stringify({
43
  inputs: prompt
44
+ }),
45
+ // Добавляем тайм-аут в 60 секунд
46
+ timeout: 60000
47
  });
48
 
49
  if (!response.ok) {
50
  throw new Error(`Error from Hugging Face API: ${response.statusText}`);
51
  }
52
 
53
+ console.log('Received response from Hugging Face API, processing image...');
54
+
55
  const imageBuffer = await response.buffer();
56
  const base64Image = imageBuffer.toString('base64');
57
 
58
  res.json({ image: base64Image });
59
  } catch (error) {
60
+ console.error('Error generating image:', error.message);
61
  res.status(500).send('Error generating image');
62
  }
63
  });