switch from request to aiohttp
This commit is contained in:
parent
3c0b9664ff
commit
5473df0e5d
2 changed files with 24 additions and 25 deletions
47
dalle.py
47
dalle.py
|
@ -1,10 +1,9 @@
|
||||||
import json
|
import json
|
||||||
import urllib
|
import urllib
|
||||||
import requests
|
|
||||||
import io
|
import io
|
||||||
import base64
|
import base64
|
||||||
import asyncio
|
import asyncio
|
||||||
import requests
|
import aiohttp
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
@ -107,29 +106,29 @@ class Dalle(Plugin):
|
||||||
"prompt": prompt
|
"prompt": prompt
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post("https://nexra.aryahcr.cc/api/image/complements", headers=headers, data=json.dumps(data))
|
async with aiohttp.request("POST", "https://nexra.aryahcr.cc/api/image/complements", headers=headers, data=json.dumps(data)) as response:
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status != 200:
|
||||||
self.log.warning(f"Unexpected status sending request to nexra.aryahcr.cc: {response.status_code}")
|
self.log.warning(f"Unexpected status sending request to nexra.aryahcr.cc: {response.status_code}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
count = -1
|
||||||
|
response_text = await response.text()
|
||||||
|
for i in range(len(response_text)):
|
||||||
|
if count <= -1:
|
||||||
|
if response_text[i] == "{":
|
||||||
|
count = i
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
count = -1
|
response_json = json.loads(response_text[count:])
|
||||||
for i in range(len(response.text)):
|
content = response_json['images'][0]
|
||||||
if count <= -1:
|
|
||||||
if response.text[i] == "{":
|
|
||||||
count = i
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
response_json = json.loads(response.text[count:])
|
|
||||||
|
|
||||||
content = response_json['images'][0]
|
base64_str = content.replace("data:image/jpeg;base64,", "")
|
||||||
|
mem_file = io.BytesIO(base64.decodebytes(bytes(base64_str, "utf-8")))
|
||||||
base64_str = content.replace("data:image/jpeg;base64,", "")
|
|
||||||
mem_file = io.BytesIO(base64.decodebytes(bytes(base64_str, "utf-8")))
|
pil_image = Image.open(mem_file)
|
||||||
|
pil_image.save(mem_file, format=pil_image.format)
|
||||||
pil_image = Image.open(mem_file)
|
mem_file.seek(0)
|
||||||
pil_image.save(mem_file, format=pil_image.format)
|
|
||||||
mem_file.seek(0)
|
|
||||||
|
|
||||||
return mem_file
|
|
||||||
|
|
||||||
|
return mem_file
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
maubot: 0.1.0
|
maubot: 0.1.0
|
||||||
id: sh.boehm.dalle
|
id: sh.boehm.dalle
|
||||||
version: 0.0.029
|
version: 0.0.03
|
||||||
license: MIT
|
license: MIT
|
||||||
modules:
|
modules:
|
||||||
- dalle
|
- dalle
|
||||||
|
|
Loading…
Reference in a new issue