Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- Lex.py +50 -0
- custom.css +32 -0
Lex.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import httpx
|
2 |
+
import random
|
3 |
+
import string
|
4 |
+
import uuid
|
5 |
+
import re
|
6 |
+
|
7 |
+
class Lexica:
|
8 |
+
def __init__(self, query, negativePrompt="", guidanceScale: int = 7, portrait: bool = True, cookie=None):
|
9 |
+
self.query = query
|
10 |
+
self.negativePrompt = negativePrompt
|
11 |
+
self.guidanceScale = guidanceScale
|
12 |
+
self.portrait = portrait
|
13 |
+
self.cookie = cookie
|
14 |
+
|
15 |
+
def images(self):
|
16 |
+
response = httpx.post("https://lexica.art/api/infinite-prompts", json={
|
17 |
+
"text": self.query,
|
18 |
+
"searchMode": "images",
|
19 |
+
"source": "search",
|
20 |
+
"model": "lexica-aperture-v2"
|
21 |
+
})
|
22 |
+
|
23 |
+
prompts = [f"https://image.lexica.art/full_jpg/{ids['id']}" for ids in response.json()["images"]]
|
24 |
+
|
25 |
+
return prompts
|
26 |
+
|
27 |
+
def _generate_random_string(self, length):
|
28 |
+
chars = string.ascii_letters + string.digits
|
29 |
+
result_str = ''.join(random.choice(chars) for _ in range(length))
|
30 |
+
|
31 |
+
return result_str
|
32 |
+
|
33 |
+
def generate(self):
|
34 |
+
response = httpx.post("https://z.lexica.art/api/generator", headers={
|
35 |
+
"cookie": self.cookie
|
36 |
+
}, json={
|
37 |
+
"requestId": str(uuid.uuid4()),
|
38 |
+
"id": self._generate_random_string(20),
|
39 |
+
"prompt": self.query,
|
40 |
+
"negativePrompt": self.negativePrompt,
|
41 |
+
"guidanceScale": self.guidanceScale,
|
42 |
+
"width": 512 if self.portrait else 768,
|
43 |
+
"height": 768 if self.portrait else 512,
|
44 |
+
"enableHiresFix": False,
|
45 |
+
"model": "lexica-aperture-v2",
|
46 |
+
"generateSources": []
|
47 |
+
}, timeout=50
|
48 |
+
)
|
49 |
+
|
50 |
+
return [f"https://image.lexica.art/full_jpg/{ids['id']}" for ids in response.json()["images"]]
|
custom.css
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#title{text-align: center;}
|
2 |
+
#title h1{font-size: 3em; display:inline-flex; align-items:center}
|
3 |
+
#title img{width: 100px; margin-right: 0.5em}
|
4 |
+
#prompt input{width: calc(100% - 160px);border-top-right-radius: 0px;border-bottom-right-radius: 0px;}
|
5 |
+
#run_button{position:absolute;margin-top: 11px;right: 0;margin-right: 0.8em;border-bottom-left-radius: 0px;border-top-left-radius: 0px;}
|
6 |
+
#gallery{display:flex;}
|
7 |
+
#gallery .grid-wrap{min-height: 100%;}
|
8 |
+
#accordion code{word-break: break-all;word-wrap: break-word;white-space: pre-wrap}
|
9 |
+
#soon{opacity: 0.55; pointer-events: none}
|
10 |
+
#soon button{width: 100%}
|
11 |
+
#share-btn-container {padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; max-width: 13rem; margin-left: auto;}
|
12 |
+
div#share-btn-container > div {flex-direction: row;background: black;align-items: center}
|
13 |
+
#share-btn-container:hover {background-color: #060606}
|
14 |
+
#share-btn {all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.5rem !important; padding-bottom: 0.5rem !important;right:0;}
|
15 |
+
#share-btn * {all: unset}
|
16 |
+
#share-btn-container div:nth-child(-n+2){width: auto !important;min-height: 0px !important;}
|
17 |
+
#share-btn-container .wrap {display: none !important}
|
18 |
+
#share-btn-container.hidden {display: none!important}
|
19 |
+
#extra_info{margin-top: 1em}
|
20 |
+
.pending .min {min-height: auto}
|
21 |
+
#gallery_box{padding-top: 0}
|
22 |
+
#gallery_box .form{border: 0 !important}
|
23 |
+
#order_radio{border: 0;padding-left: 0}
|
24 |
+
#order_radio .form{border:0 !important; padding-bottom: 0.25em}
|
25 |
+
#order_radio [data-testid="block-info"]{float: left;margin-top: 2px;margin-right: 6px}
|
26 |
+
#order_radio label{padding: 0.25em 0.75em !important;font-size: 85% !important}
|
27 |
+
@media (max-width: 512px) {
|
28 |
+
#title h1{font-size: 2.2em}
|
29 |
+
#title img{width: 80px;}
|
30 |
+
#gallery {max-height: 370px}
|
31 |
+
#main_app{flex-direction: column}
|
32 |
+
}
|