import axios from "axios"; export const config = { "name": "upscaler", "url": "/api/upscaler", "description": "Get response from Upscaler AI Model. Upscaler AI can restore the image to its original state.", "query": "url", "response": "text", "testURL": "./api/upscaler?url=https%3A%2F%2Fscontent.fdac27-2.fna.fbcdn.net%2Fv%2Ft39.30808-1%2F386334419_843740254146283_32129838220110611_n.jpg%3Fstp%3Dc0.29.100.100a_dst-jpg_p100x100%26_nc_cat%3D105%26ccb%3D1-7%26_nc_sid%3D5f2048%26_nc_eui2%3DAeGirXPT1E56jzWOq3tJatv5HsWuBCzqiQIexa4ELOqJAuncqimdF8tQfaP-IQsyWKB1k2KRJgwsjLnqlMdyG0gS%26_nc_ohc%3Dic3HON0M4RoAb5e2J7a%26_nc_ad%3Dz-m%26_nc_cid%3D0%26_nc_ht%3Dscontent.fdac27-2.fna%26oh%3D00_AfDQQEelZWQ1AL6mhd32t45Lk5ioYN43ZjAj__UW5d_wuQ%26oe%3D661D418E" } export default async function handler(req, res) { const url = req.query.url; const axios = require("axios"); const postData = async () => { try { const response = await axios.post( "https://replicate-reverse-engineered.vercel.app/post", {dataToPost:{ input: { jpeg: 40, image: url, noise: 15, task_type: "Real-World Image Super-Resolution-Large", }, stream: false, }, replicateURL: "https://replicate.com/api/models/jingyunliang/swinir/versions/660d922d33153019e8c263a3bba265de882e7f4f70396546b6c9c8f9d47a021a/predictions"} ); console.log(response.data); let nurl = 'https://replicate.com/api/predictions/' + response.data.id; nurl = 'https://replicate-reverse-engineered.vercel.app/get?url='+nurl let isProcessing = true; while (isProcessing) { const { data } = await axios.get(nurl); //console.log(data); if (data.status === "succeeded") { console.log(data._extras.output_files[0]); isProcessing = false; return data._extras.output_files[0]; } } } catch (error) { console.error("Error:", error); } }; postData().then((data) => { res.status(200).json({url: data}); }); }