Update server.js
Browse files
server.js
CHANGED
@@ -1,11 +1,14 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
4 |
|
5 |
const app = express();
|
6 |
const port = 3000;
|
|
|
7 |
|
8 |
-
// Используем body-parser для обработки JSON данных
|
9 |
app.use(bodyParser.json());
|
10 |
|
11 |
app.post('/generate-image', async (req, res) => {
|
@@ -19,7 +22,7 @@ app.post('/generate-image', async (req, res) => {
|
|
19 |
const response = await fetch('https://api-inference.huggingface.co/models/your-model-name', {
|
20 |
method: 'POST',
|
21 |
headers: {
|
22 |
-
'Authorization': `Bearer ${
|
23 |
'Content-Type': 'application/json'
|
24 |
},
|
25 |
body: JSON.stringify({
|
|
|
1 |
+
import express from 'express';
|
2 |
+
import fetch from 'node-fetch';
|
3 |
+
import bodyParser from 'body-parser';
|
4 |
+
import dotenv from 'dotenv';
|
5 |
+
|
6 |
+
dotenv.config();
|
7 |
|
8 |
const app = express();
|
9 |
const port = 3000;
|
10 |
+
const apiKey = process.env.KEY;
|
11 |
|
|
|
12 |
app.use(bodyParser.json());
|
13 |
|
14 |
app.post('/generate-image', async (req, res) => {
|
|
|
22 |
const response = await fetch('https://api-inference.huggingface.co/models/your-model-name', {
|
23 |
method: 'POST',
|
24 |
headers: {
|
25 |
+
'Authorization': `Bearer ${apiKey}`,
|
26 |
'Content-Type': 'application/json'
|
27 |
},
|
28 |
body: JSON.stringify({
|