Spaces:
Running
Running
Update image.js
Browse files
image.js
CHANGED
|
@@ -8,7 +8,7 @@ const { HfInference } = require("@huggingface/inference");
|
|
| 8 |
require("dotenv").config()
|
| 9 |
|
| 10 |
// Cache directory to store generated images
|
| 11 |
-
const CACHE_DIR =
|
| 12 |
|
| 13 |
|
| 14 |
if (!fs.existsSync(CACHE_DIR)) {
|
|
@@ -70,6 +70,7 @@ const generateImage = async(requestPayload, res, responseFormat) => {
|
|
| 70 |
console.log(cachePath)
|
| 71 |
// Check if the image already exists in the cache
|
| 72 |
if (fs.existsSync(cachePath)) {
|
|
|
|
| 73 |
return res.sendFile(cachePath);
|
| 74 |
}
|
| 75 |
|
|
@@ -114,8 +115,9 @@ const generateImage = async(requestPayload, res, responseFormat) => {
|
|
| 114 |
res.json({"image_url": "https://defactofficial-mmapi.hf.space/image_out/"+ cachePath.split("/").at(-1)})
|
| 115 |
res.end()
|
| 116 |
} else {
|
| 117 |
-
res.setHeader('Content-Type', '
|
| 118 |
res.sendFile(cachePath);
|
|
|
|
| 119 |
}
|
| 120 |
} catch (error) {
|
| 121 |
res.status(500).send(`Error: Failed to generate image - ${error.message}`);
|
|
|
|
| 8 |
require("dotenv").config()
|
| 9 |
|
| 10 |
// Cache directory to store generated images
|
| 11 |
+
const CACHE_DIR = `/home/root/code/public/image_out`
|
| 12 |
|
| 13 |
|
| 14 |
if (!fs.existsSync(CACHE_DIR)) {
|
|
|
|
| 70 |
console.log(cachePath)
|
| 71 |
// Check if the image already exists in the cache
|
| 72 |
if (fs.existsSync(cachePath)) {
|
| 73 |
+
console.log("Found in cache! "+cacheKey)
|
| 74 |
return res.sendFile(cachePath);
|
| 75 |
}
|
| 76 |
|
|
|
|
| 115 |
res.json({"image_url": "https://defactofficial-mmapi.hf.space/image_out/"+ cachePath.split("/").at(-1)})
|
| 116 |
res.end()
|
| 117 |
} else {
|
| 118 |
+
res.setHeader('Content-Type', 'application/octet-stream');
|
| 119 |
res.sendFile(cachePath);
|
| 120 |
+
res.end()
|
| 121 |
}
|
| 122 |
} catch (error) {
|
| 123 |
res.status(500).send(`Error: Failed to generate image - ${error.message}`);
|