Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -8,7 +8,7 @@ import { fileTypeFromBuffer } from "file-type";
|
|
8 |
import { Client } from "@gradio/client";
|
9 |
import { stablediff } from "./lib/diffusion.js";
|
10 |
import { askOpenGPT4o } from "./lib/chatgpt.js";
|
11 |
-
import {
|
12 |
|
13 |
const app = express();
|
14 |
app.set('json spaces', 4);
|
@@ -80,8 +80,10 @@ app.post('/api/img2img', async (req, res) => {
|
|
80 |
app.post('/api/upscaler', async (req, res) => {
|
81 |
try {
|
82 |
console.log(req.body)
|
83 |
-
const { images, status } = req.body
|
84 |
if (!images) return res.json({ success: false, message: 'Required an images!' })
|
|
|
|
|
85 |
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
86 |
|
87 |
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
@@ -91,14 +93,14 @@ app.post('/api/upscaler', async (req, res) => {
|
|
91 |
url: images,
|
92 |
responseType: "arraybuffer"
|
93 |
})
|
94 |
-
const response = await
|
95 |
-
|
96 |
-
|
97 |
res.json(response)
|
98 |
} else if (images && typeof images == 'string' && isBase64(images)) {
|
99 |
-
const response = await
|
100 |
-
|
101 |
-
|
102 |
res.json(response)
|
103 |
} else {
|
104 |
res.json({
|
|
|
8 |
import { Client } from "@gradio/client";
|
9 |
import { stablediff } from "./lib/diffusion.js";
|
10 |
import { askOpenGPT4o } from "./lib/chatgpt.js";
|
11 |
+
import { processImageUpscaler } from "./lib/enchance.js";
|
12 |
|
13 |
const app = express();
|
14 |
app.set('json spaces', 4);
|
|
|
80 |
app.post('/api/upscaler', async (req, res) => {
|
81 |
try {
|
82 |
console.log(req.body)
|
83 |
+
const { images, filenames, mimetype, status } = req.body
|
84 |
if (!images) return res.json({ success: false, message: 'Required an images!' })
|
85 |
+
if (!filenames) return res.json({ success: false, message: 'Required an filenames!' })
|
86 |
+
if (!mimetype) return res.json({ success: false, message: 'Required an mimetype!' })
|
87 |
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
88 |
|
89 |
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
|
|
93 |
url: images,
|
94 |
responseType: "arraybuffer"
|
95 |
})
|
96 |
+
const response = await processImageUpscaler({buffer: data_img.data, method: "enchance", filenames, mimetype})
|
97 |
+
const type_img = await fileTypeFromBuffer(response)
|
98 |
+
res.setHeader('Content-Type', type_img.mime)
|
99 |
res.json(response)
|
100 |
} else if (images && typeof images == 'string' && isBase64(images)) {
|
101 |
+
const response = await processImageUpscaler({buffer: Buffer.from(data_img.data, "base64"), method: "enchance", filenames, mimetype})
|
102 |
+
const type_img = await fileTypeFromBuffer(response)
|
103 |
+
res.setHeader('Content-Type', type_img.mime)
|
104 |
res.json(response)
|
105 |
} else {
|
106 |
res.json({
|