Spaces:
Running
Running
File size: 1,754 Bytes
7f5156b e6cc3a0 fa70cf8 7f5156b fa70cf8 7f5156b fa70cf8 7f5156b e6cc3a0 fa70cf8 e6cc3a0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import axios from "axios";
async function stablediff(prompt) {
try {
const BASE_URL = "https://stabilityai-stable-diffusion-3-medium.hf.space/";
const session_hash = Math.random().toString(36).substring(2).slice(1);
const resp = await axios({
method: "POST",
url: BASE_URL + "queue/join?__theme=light",
data: {
data: [
prompt,
"",
0,
true,
1024,
1024,
5,
28
],
event_data: null,
fn_index: 1,
session_hash,
trigger_id: 4
}
});
if(resp.data.event_id) {
const response = await axios({
method: "GET",
url: BASE_URL + "queue/data?session_hash=" + session_hash
});
const splited = response.data.split("\n");
const processStartsLine = splited.find(line => line.includes('process_completed'));
const processStartsData = JSON.parse(processStartsLine.replace('data: ', ''));
const processStartsLine2 = splited.find(line => line.includes('progress'));
const processStartsData2 = JSON.parse(processStartsLine.replace('data: ', ''));
if(processStartsData?.success) {
return processStartsData.output.data;
} else if(processStartsData?.success) {
return processStartsData2.output.data;
}
}
} catch(e) {
console.log("error:" + e.message);
return e.message;
}
}
export { stablediff } |