Puruu Puruu commited on
Commit ·
8065f56
1
Parent(s): 8c49e5c
- Dockerfile +1 -1
- features/image-describe.js +64 -0
- features/upscale.js +1 -1
- index.js +4 -2
- package-lock.json +0 -0
- package.json +6 -4
Dockerfile
CHANGED
|
@@ -5,7 +5,7 @@ WORKDIR /app
|
|
| 5 |
RUN apt-get update && apt-get install -y curl gnupg && \
|
| 6 |
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
| 7 |
apt-get install -y nodejs && \
|
| 8 |
-
npm install express axios && \
|
| 9 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
COPY . .
|
|
|
|
| 5 |
RUN apt-get update && apt-get install -y curl gnupg && \
|
| 6 |
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
| 7 |
apt-get install -y nodejs && \
|
| 8 |
+
npm install express axios form-data && \
|
| 9 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
COPY . .
|
features/image-describe.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Lokasi: features/image-describe.js
|
| 3 |
+
* Versi: v1
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
const axios = require('axios');
|
| 7 |
+
const crypto = require('crypto');
|
| 8 |
+
|
| 9 |
+
async function sendCallback(url, payload) {
|
| 10 |
+
try {
|
| 11 |
+
await axios.post(url, payload, { headers: { 'Content-Type': 'application/json' } });
|
| 12 |
+
} catch (error) {
|
| 13 |
+
console.error('Callback failed:', error.message);
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
module.exports = async function(req, res) {
|
| 18 |
+
const { imageUrl, prompt, jobId, callbackUrl, callbackKey } = req.body;
|
| 19 |
+
|
| 20 |
+
if (!imageUrl || !prompt || !jobId || !callbackUrl || !callbackKey) {
|
| 21 |
+
return res.status(400).json({ error: 'Missing required parameters.' });
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
res.status(202).json({ message: 'Job accepted and is being processed.' });
|
| 25 |
+
|
| 26 |
+
try {
|
| 27 |
+
const visitorId = crypto.randomBytes(16).toString('hex');
|
| 28 |
+
const headerF = crypto.createHash('md5').update(visitorId).digest('hex');
|
| 29 |
+
|
| 30 |
+
const chatPayload = {
|
| 31 |
+
message: prompt,
|
| 32 |
+
image: imageUrl,
|
| 33 |
+
history: [],
|
| 34 |
+
lang: 'en'
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
const chatResponse = await axios.post(
|
| 38 |
+
'https://imagedescriber.online/api/chat-with-image',
|
| 39 |
+
chatPayload,
|
| 40 |
+
{
|
| 41 |
+
headers: {
|
| 42 |
+
'Content-Type': 'application/json',
|
| 43 |
+
'f': headerF,
|
| 44 |
+
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; RMX2185 Build/QP1A.190711.020) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.7151.118 Mobile Safari/537.36',
|
| 45 |
+
'Referer': 'https://imagedescriber.online/tools/chat-with-image-ai'
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
);
|
| 49 |
+
|
| 50 |
+
await sendCallback(callbackUrl, {
|
| 51 |
+
jobId,
|
| 52 |
+
callbackKey,
|
| 53 |
+
status: 'success',
|
| 54 |
+
result: { response: chatResponse.data },
|
| 55 |
+
});
|
| 56 |
+
} catch (e) {
|
| 57 |
+
await sendCallback(callbackUrl, {
|
| 58 |
+
jobId,
|
| 59 |
+
callbackKey,
|
| 60 |
+
status: 'failed',
|
| 61 |
+
result: { error: e.message || 'An unknown error occurred during image description.' },
|
| 62 |
+
});
|
| 63 |
+
}
|
| 64 |
+
};
|
features/upscale.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
/*
|
| 2 |
-
* Lokasi:
|
| 3 |
* Versi: v1
|
| 4 |
*/
|
| 5 |
|
|
|
|
| 1 |
/*
|
| 2 |
+
* Lokasi: /features/upscale.js
|
| 3 |
* Versi: v1
|
| 4 |
*/
|
| 5 |
|
index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
/*
|
| 2 |
-
* Lokasi:
|
| 3 |
-
* Versi:
|
| 4 |
*/
|
| 5 |
|
| 6 |
const express = require('express');
|
| 7 |
const upscaleFeature = require('./features/upscale.js');
|
|
|
|
| 8 |
|
| 9 |
const app = express();
|
| 10 |
const port = process.env.PORT || 7860;
|
|
@@ -16,6 +17,7 @@ app.get('/', (req, res) => {
|
|
| 16 |
});
|
| 17 |
|
| 18 |
app.post('/upscale', upscaleFeature);
|
|
|
|
| 19 |
|
| 20 |
app.listen(port, () => {
|
| 21 |
console.log(`Worker server listening on port ${port}`);
|
|
|
|
| 1 |
/*
|
| 2 |
+
* Lokasi: index.js
|
| 3 |
+
* Versi: v2
|
| 4 |
*/
|
| 5 |
|
| 6 |
const express = require('express');
|
| 7 |
const upscaleFeature = require('./features/upscale.js');
|
| 8 |
+
const imageDescribeFeature = require('./features/image-describe.js');
|
| 9 |
|
| 10 |
const app = express();
|
| 11 |
const port = process.env.PORT || 7860;
|
|
|
|
| 17 |
});
|
| 18 |
|
| 19 |
app.post('/upscale', upscaleFeature);
|
| 20 |
+
app.post('/image-describe', imageDescribeFeature);
|
| 21 |
|
| 22 |
app.listen(port, () => {
|
| 23 |
console.log(`Worker server listening on port ${port}`);
|
package-lock.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
package.json
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
{
|
| 2 |
"name": "workspace",
|
| 3 |
"version": "1.0.0",
|
|
@@ -11,8 +13,8 @@
|
|
| 11 |
"license": "ISC",
|
| 12 |
"description": "",
|
| 13 |
"dependencies": {
|
| 14 |
-
"
|
| 15 |
-
"
|
| 16 |
-
"
|
| 17 |
}
|
| 18 |
-
}
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
{
|
| 4 |
"name": "workspace",
|
| 5 |
"version": "1.0.0",
|
|
|
|
| 13 |
"license": "ISC",
|
| 14 |
"description": "",
|
| 15 |
"dependencies": {
|
| 16 |
+
"axios": "^1.7.2",
|
| 17 |
+
"express": "^4.19.2",
|
| 18 |
+
"form-data": "^4.0.0"
|
| 19 |
}
|
| 20 |
+
}
|