fix: python code for eidting image

This commit is contained in:
jialin
2026-04-09 12:14:36 +08:00
committed by jialin
parent 7beb5756f7
commit 78bf76e965
+20 -1
View File
@@ -52,7 +52,7 @@ export const generateImageCode = ({
});
// ========================= Python =========================
const pythonCode = `
let pythonCode = `
import requests\n
url="${host}${api}"
headers = {
@@ -63,6 +63,25 @@ data = ${JSON.stringify(parameters, null, 2).replace(/null/g, 'None')}\n
response = requests.post(url, headers=headers, json=data)
print(response.json()['data'][0]['b64_json'])`.trim();
if (edit) {
const files = {
image: `open(image.png, 'rb')`,
mask: `open(mask.png, 'rb')`
};
pythonCode = `
import requests\n
url="${host}${api}"
headers = {
"Content-type": "multipart/form-data",
"Authorization": "Bearer $\{YOUR_GPUSTACK_API_KEY}"
}
data = ${JSON.stringify(_.omit(parameters, ['mask', 'image']), null, 2).replace(/null/g, 'None')}
files = ${JSON.stringify(files, null, 2).replace(/null/g, 'None')}\n
response = requests.post(url, headers=headers, json=data, files=files)
print(response.json()['data'][0]['b64_json'])`.trim();
}
// ========================= Node.js =========================
const nodeJsCode = `
const axios = require('axios');