-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLex.py
50 lines (42 loc) · 1.7 KB
/
Lex.py
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
import httpx
import random
import string
import uuid
import re
class Lexica:
def __init__(self, query, negativePrompt="", guidanceScale: int = 7, portrait: bool = True, cookie=None):
self.query = query
self.negativePrompt = negativePrompt
self.guidanceScale = guidanceScale
self.portrait = portrait
self.cookie = cookie
def images(self):
response = httpx.post("https://lexica.art/api/infinite-prompts", json={
"text": self.query,
"searchMode": "images",
"source": "search",
"model": "lexica-aperture-v2"
})
prompts = [f"https://image.lexica.art/full_jpg/{ids['id']}" for ids in response.json()["images"]]
return prompts
def _generate_random_string(self, length):
chars = string.ascii_letters + string.digits
result_str = ''.join(random.choice(chars) for _ in range(length))
return result_str
def generate(self):
response = httpx.post("https://z.lexica.art/api/generator", headers={
"cookie": self.cookie
}, json={
"requestId": str(uuid.uuid4()),
"id": self._generate_random_string(20),
"prompt": self.query,
"negativePrompt": self.negativePrompt,
"guidanceScale": self.guidanceScale,
"width": 512 if self.portrait else 768,
"height": 768 if self.portrait else 512,
"enableHiresFix": False,
"model": "lexica-aperture-v2",
"generateSources": []
}, timeout=50
)
return [f"https://image.lexica.art/full_jpg/{ids['id']}" for ids in response.json()["images"]]