76 lines
1.7 KiB
Python
Executable File
76 lines
1.7 KiB
Python
Executable File
from bs4 import BeautifulSoup
|
|
import base64
|
|
import httpx
|
|
import json
|
|
import requests
|
|
import socket
|
|
import tempfile
|
|
|
|
|
|
async def generate_image(ip, port, positives, negatives, steps):
|
|
url = "http://" + ip + ":" + port + "/run/predict/"
|
|
headers = {
|
|
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0",
|
|
"Accept": "*/*",
|
|
"Accept-Language": "en-US,en;q=0.5",
|
|
"DNT": "1",
|
|
"Connection": "keep-alive",
|
|
}
|
|
|
|
json_data = {
|
|
"fn_index": 52,
|
|
"data": [
|
|
positives,
|
|
negatives,
|
|
"None",
|
|
"None",
|
|
steps,
|
|
"Euler a",
|
|
True,
|
|
False,
|
|
1,
|
|
1,
|
|
7,
|
|
-1,
|
|
-1,
|
|
0,
|
|
0,
|
|
0,
|
|
False,
|
|
512,
|
|
512,
|
|
True,
|
|
0.7,
|
|
0,
|
|
0,
|
|
"None",
|
|
False,
|
|
False,
|
|
False,
|
|
False,
|
|
"",
|
|
"Seed",
|
|
"",
|
|
"Nothing",
|
|
"",
|
|
True,
|
|
False,
|
|
False,
|
|
None,
|
|
],
|
|
}
|
|
client = httpx.AsyncClient()
|
|
response = await client.post(url, headers=headers, json=json_data, timeout=1200)
|
|
file_path = response.json()["data"][0][0]["name"]
|
|
|
|
imgdata = await client.get("http://%s:%s/file=%s" % (ip, port, file_path))
|
|
file, file_path = tempfile.mkstemp()
|
|
|
|
with open(file_path, "wb") as f:
|
|
f.write(imgdata.content)
|
|
|
|
soup = BeautifulSoup(response.json()["data"][2], "html.parser")
|
|
time_taken = soup.find("p", class_="time").text
|
|
|
|
return file_path, time_taken
|