Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -135,6 +135,51 @@ app.get('/yt/convert', async (req, res) => {
|
|
135 |
}
|
136 |
})
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
const PORT = process.env.PORT || 7860
|
139 |
app.listen(PORT, () => console.log('App running on port', PORT))
|
140 |
|
|
|
135 |
}
|
136 |
})
|
137 |
|
138 |
+
app.all('/stablediff/illusion', async (req, res) => {
|
139 |
+
if (!['GET', 'POST'].includes(req.method)) return res.json({ success: false, message: 'Method Not Allowed' })
|
140 |
+
try {
|
141 |
+
const {
|
142 |
+
prompt,
|
143 |
+
negative_prompt = 'low quality',
|
144 |
+
image_url,
|
145 |
+
num_inference_steps = 25,
|
146 |
+
controlnet_conditioning_scale = 1
|
147 |
+
} = req.method !== 'GET' ? req.body : req.query
|
148 |
+
|
149 |
+
if (!(prompt && image_url)) return res.json({ success: false, message: 'Required parameter prompt & image_url' })
|
150 |
+
|
151 |
+
const headers = {
|
152 |
+
'Content-Type': 'application/json',
|
153 |
+
Authorization: `Key ${process.env.falAIKey}`
|
154 |
+
}
|
155 |
+
|
156 |
+
const { detail, response_url } = await fetch('https://54285744-illusion-diffusion.gateway.alpha.fal.ai/fal/queue/submit', {
|
157 |
+
method: 'POST',
|
158 |
+
body: JSON.stringify({
|
159 |
+
prompt, negative_prompt, image_url,
|
160 |
+
num_inference_steps, controlnet_conditioning_scale
|
161 |
+
}),
|
162 |
+
headers
|
163 |
+
})
|
164 |
+
if (detail) return res.json({ success: false, message: detail })
|
165 |
+
|
166 |
+
let retry = 0
|
167 |
+
while (true) {
|
168 |
+
await new Promise(resolve => setTimeout(resolve, 2500))
|
169 |
+
const prediction = await fetch(response_url, { headers })
|
170 |
+
console.log(prediction)
|
171 |
+
if (retry > 10) return res.json({ success: false, message: prediction.detail || 'Max retry has reached' })
|
172 |
+
if (prediction.image) return res.json({ success: true, result: prediction })
|
173 |
+
retry += 1
|
174 |
+
}
|
175 |
+
|
176 |
+
} catch (e) {
|
177 |
+
console.log(e)
|
178 |
+
e = String(e)
|
179 |
+
res.status(500).json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
180 |
+
}
|
181 |
+
})
|
182 |
+
|
183 |
const PORT = process.env.PORT || 7860
|
184 |
app.listen(PORT, () => console.log('App running on port', PORT))
|
185 |
|