Spaces:
Runtime error
Runtime error
Create app.js
Browse files
app.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const axios = require('axios');
|
| 3 |
+
const app = express();
|
| 4 |
+
const port = process.env.PORT || 3000;
|
| 5 |
+
|
| 6 |
+
app.use(express.json());
|
| 7 |
+
|
| 8 |
+
app.post('/generate-image', async (req, res) => {
|
| 9 |
+
const { modelId, prompt } = req.body;
|
| 10 |
+
|
| 11 |
+
try {
|
| 12 |
+
const response = await axios.post('https://api.civitai.com/generate', {
|
| 13 |
+
modelId: modelId,
|
| 14 |
+
prompt: prompt
|
| 15 |
+
}, {
|
| 16 |
+
headers: {
|
| 17 |
+
'Authorization': `Bearer ${process.env.CIVITAI_API_KEY}`
|
| 18 |
+
}
|
| 19 |
+
});
|
| 20 |
+
|
| 21 |
+
res.json(response.data);
|
| 22 |
+
} catch (error) {
|
| 23 |
+
res.status(500).send(error.message);
|
| 24 |
+
}
|
| 25 |
+
});
|
| 26 |
+
|
| 27 |
+
app.listen(port, () => {
|
| 28 |
+
console.log(`Civitai Generator listening at http://localhost:${port}`);
|
| 29 |
+
});
|