28 lines
723 B
Python
Executable File
28 lines
723 B
Python
Executable File
from bs4 import BeautifulSoup
|
|
import base64
|
|
import httpx
|
|
import tempfile
|
|
|
|
|
|
async def generate_image(ip, port, positives, negatives, steps):
|
|
url = "http://" + ip + ":" + port + "/sdapi/v1/txt2img"
|
|
|
|
json_data = {
|
|
"prompt": positives,
|
|
"negative_prompt": negatives,
|
|
"steps": steps,
|
|
"hr_upscale": 2,
|
|
"alwayson_scripts": {"ADetailer": {"args": [{"ad_model": "face_yolov8n.pt"}]}},
|
|
}
|
|
|
|
client = httpx.AsyncClient()
|
|
|
|
response = await client.post(url, json=json_data, timeout=1200)
|
|
b64_image = response.json()["images"][0]
|
|
file, file_path = tempfile.mkstemp()
|
|
|
|
with open(file_path, "wb") as f:
|
|
f.write(base64.b64decode(b64_image))
|
|
|
|
return file_path
|