Khrisna commited on
Commit
b91ad22
·
verified ·
1 Parent(s): d362ebf

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +39 -0
index.js CHANGED
@@ -9,6 +9,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);
@@ -114,6 +116,43 @@ app.post('/api/upscaler', async (req, res) => {
114
  }
115
  })
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  app.post('/api/openai/gpt4', async (req, res) => {
118
  try {
119
  console.log(req.body)
 
9
  import { stablediff } from "./lib/diffusion.js";
10
  import { askOpenGPT4o } from "./lib/chatgpt.js";
11
  import { processImageUpscaler } from "./lib/enchance.js";
12
+ import { toAnime } from "./lib/toanime.js";
13
+ import { convertWebpToPng } from "./lib/converting.js";
14
 
15
  const app = express();
16
  app.set('json spaces', 4);
 
116
  }
117
  })
118
 
119
+ app.post('/api/toanime', async (req, res) => {
120
+ try {
121
+ console.log(req.body)
122
+ const { images, filenames, mimetype, status } = req.body
123
+ if (!images) return res.json({ success: false, message: 'Required an images!' })
124
+ if (!status) return res.json({ success: false, message: 'Required an status text!' })
125
+
126
+ if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
127
+ if (/^(https?|http):\/\//i.test(images)) {
128
+ const data_img = await axios.request({
129
+ method: "GET",
130
+ url: images,
131
+ responseType: "arraybuffer"
132
+ })
133
+ const response = await toAnime(data_img.data);
134
+ const converting = await convertWebpToPng(response[0][0]?.image?.url)
135
+ const type_img = await fileTypeFromBuffer(converting)
136
+ res.setHeader('Content-Type', type_img.mime)
137
+ res.json(converting)
138
+ } else if (images && typeof images == 'string' && isBase64(images)) {
139
+ const response = await await toAnime(Buffer.from(images, "base64"));
140
+ const converting = await convertWebpToPng(response[0][0]?.image?.url)
141
+ const type_img = await fileTypeFromBuffer(converting)
142
+ res.setHeader('Content-Type', type_img.mime)
143
+ res.json(converting)
144
+ } else {
145
+ res.json({
146
+ success: false, message: 'No url or base64 detected!!'
147
+ })
148
+ }
149
+ } catch (e) {
150
+ console.log(e)
151
+ e = String(e)
152
+ res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
153
+ }
154
+ })
155
+
156
  app.post('/api/openai/gpt4', async (req, res) => {
157
  try {
158
  console.log(req.body)