github-actions commited on
Commit
e493f59
·
1 Parent(s): 1a03105

Update for version v7.1.4

Browse files
Files changed (4) hide show
  1. README.md +2 -6
  2. app.py +296 -0
  3. pr1.txt +183 -0
  4. pr2.txt +0 -0
README.md CHANGED
@@ -1,14 +1,10 @@
1
  ---
2
  title: Prompt Generator
3
- emoji: 😻
4
  colorFrom: indigo
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 5.20.0
8
- app_file: app.py
9
  pinned: false
10
- license: apache-2.0
11
- short_description: Simple prompt generation script for Midjourney, DALLe, Stabl
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Prompt Generator
3
+ emoji: ♾️
4
  colorFrom: indigo
5
+ colorTo: red
6
  sdk: gradio
 
 
7
  pinned: false
 
 
8
  ---
9
 
10
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,296 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import eventlet
2
+
3
+ eventlet.monkey_patch()
4
+
5
+ import os
6
+ import sys
7
+ import tempfile
8
+ import subprocess
9
+ import shutil
10
+ from pathlib import Path
11
+ import threading
12
+ from appdirs import user_data_dir
13
+ import socketio
14
+ import eventlet
15
+ import requests
16
+
17
+ EK_VERSION = "7.1.4"
18
+ APP_DATA_DIR = Path(user_data_dir("embykeeper"))
19
+ VERSION_CACHE_DIR = APP_DATA_DIR / "hf" / "version"
20
+
21
+
22
+ def setup_embykeeper():
23
+ try:
24
+ # 确保缓存目录存在
25
+ VERSION_CACHE_DIR.mkdir(parents=True, exist_ok=True)
26
+ cached_version = VERSION_CACHE_DIR / f"emby-keeper-{EK_VERSION}"
27
+ cached_tarball = VERSION_CACHE_DIR / f"emby-keeper-{EK_VERSION}.tar.gz"
28
+
29
+ if cached_version.exists():
30
+ print(f"Using cached version from {cached_version}", flush=True)
31
+ return True
32
+
33
+ # 创建临时目录
34
+ temp_dir = tempfile.mkdtemp()
35
+
36
+ # 下载并解压(使用系统代理)
37
+ print("Downloading EK...", flush=True)
38
+ tarball_path = os.path.join(temp_dir, "embykeeper.tar.gz")
39
+
40
+ if cached_tarball.exists():
41
+ print(f"Using cached tarball from {cached_tarball}", flush=True)
42
+ shutil.copy2(cached_tarball, tarball_path)
43
+ else:
44
+ # 使用固定的GitHub release下载地址
45
+ release_url = f"https://github.com/emby-keeper/emby-keeper/archive/refs/tags/v{EK_VERSION}.tar.gz"
46
+ subprocess.run(["wget", "-q", release_url, "-O", tarball_path], check=True)
47
+ # 缓存下载的文件
48
+ shutil.copy2(tarball_path, cached_tarball)
49
+
50
+ subprocess.run(["tar", "xf", tarball_path, "-C", temp_dir], check=True)
51
+ os.remove(tarball_path) # 删除临时的 tar.gz 文件
52
+
53
+ # 获取解压后的目录名
54
+ extracted_dir = os.path.join(temp_dir, f"emby-keeper-{EK_VERSION}")
55
+
56
+ # 混淆代码
57
+ print("Obfuscating code...", flush=True)
58
+ if not obfuscate_with_pyarmor(extracted_dir):
59
+ raise Exception("Obfuscation failed")
60
+
61
+ # 安装依赖
62
+ print("Installing dependencies...", flush=True)
63
+ subprocess.run(
64
+ [sys.executable, "-m", "pip", "install", "-r", os.path.join(extracted_dir, "requirements.txt")],
65
+ check=True,
66
+ )
67
+ subprocess.run([sys.executable, "-m", "pip", "install", extracted_dir], check=True)
68
+
69
+ # 将处理好的文件复制到缓存目录
70
+ shutil.copytree(extracted_dir, cached_version, dirs_exist_ok=True)
71
+
72
+ # 清理临时目录
73
+ shutil.rmtree(temp_dir)
74
+
75
+ return True
76
+ except Exception as e:
77
+ print(f"Error setting up EK: {e}", flush=True)
78
+ return False
79
+
80
+
81
+ def obfuscate_with_pyarmor(package_path):
82
+ try:
83
+ # 安装 pyarmor(如果还没安装)
84
+ subprocess.run([sys.executable, "-m", "pip", "install", "pyarmor"], check=True)
85
+
86
+ # 混淆两个包
87
+ for pkg in ["embykeeper", "embykeeperweb"]:
88
+ pkg_dir = os.path.join(package_path, pkg)
89
+ if not os.path.exists(pkg_dir):
90
+ print(f"Package directory not found: {pkg_dir}", flush=True)
91
+ continue
92
+
93
+ print(f"Obfuscating {pkg}...", flush=True)
94
+ # 使用新版 pyarmor 命令,指定整个目录
95
+ subprocess.run(
96
+ [
97
+ "pyarmor",
98
+ "gen",
99
+ "--recursive",
100
+ pkg_dir,
101
+ ],
102
+ check=True,
103
+ )
104
+
105
+ # 将混淆后的文件移回原位置
106
+ dist_dir = os.path.join(package_path, "dist")
107
+ pkg_dist_dir = os.path.join(dist_dir, pkg)
108
+ runtime_dir = os.path.join(dist_dir, "pyarmor_runtime_000000")
109
+
110
+ if os.path.exists(pkg_dist_dir) and os.path.exists(runtime_dir):
111
+ # 复制混淆后的文件
112
+ shutil.copytree(pkg_dist_dir, pkg_dir, dirs_exist_ok=True)
113
+ # 复制运行时文件到包目录
114
+ shutil.copy2(os.path.join(runtime_dir, "pyarmor_runtime.so"), pkg_dir)
115
+ # 清理 dist 目录
116
+ shutil.rmtree(dist_dir)
117
+ else:
118
+ print(f"Missing expected files in dist directory for {pkg}", flush=True)
119
+ return False
120
+
121
+ return True
122
+ except Exception as e:
123
+ print(f"Error during obfuscation: {e}", flush=True)
124
+ return False
125
+
126
+
127
+ def run_gradio():
128
+ import gradio as gr
129
+ import random
130
+ from time import time, ctime
131
+
132
+ def promptgen(choice, num, artist):
133
+ t = time()
134
+ print(ctime(t))
135
+
136
+ if choice == "Prompt Generator v0.1(Better quality)":
137
+ prompt = open("pr1.txt").read().splitlines()
138
+ elif choice == "Prompt Generator v0.2(More tags)":
139
+ prompt = open("pr2.txt").read().splitlines()
140
+
141
+ if int(num) < 1 or int(num) > 20:
142
+ num = 10
143
+
144
+ if int(artist) < 0 or int(artist) > 40:
145
+ artist = 2
146
+
147
+ vocab = len(prompt)
148
+ generated = []
149
+ artists_num = 0
150
+ while len(sorted(set(generated), key=lambda d: generated.index(d))) < int(num):
151
+ rand = random.choice(prompt)
152
+ if rand.startswith("art by") and artists_num < int(artist):
153
+ artists_num += 1
154
+ generated.append(rand)
155
+ elif not rand.startswith("art by"):
156
+ generated.append(rand)
157
+ print(", ".join(set(generated)) + "\n\n")
158
+ return ", ".join(set(generated))
159
+
160
+ demo = gr.Blocks()
161
+
162
+ with demo:
163
+ gr.HTML(
164
+ """
165
+ <div style="text-align: center; margin: 0 auto;">
166
+ <div style="display: inline-flex;align-items: center;gap: 0.8rem;font-size: 1.75rem;">
167
+ <h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">
168
+ Simple Prompt Generator v0.6 (Gradio Demo)
169
+ </h1>
170
+ </div>
171
+ <p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
172
+ Simple prompt generation script for Midjourney, DALLe, Stable and Disco diffusion and etc neural networks. <br> <p>More examples in <a class='link-info' href="https://github.com/WiNE-iNEFF/Simple_Prompt_Generator" target="_blank">Github</a> and <a class='link-info' href="https://wine-ineff.github.io/Simple_Prompt_Generator/" target="_blank">Project site</a></p>
173
+ </p>
174
+ <center>
175
+ <img style="display: inline-block, margin-right: 1%;" src='https://visitor-badge.laobi.icu/badge?page_id=WiNE-iNEFF.Simple_Prompt_Generator&left_color=red&right_color=green&left_text=Visitors' alt='visitor badge'>
176
+ <img style="display: inline-block, margin-right: 1%;" src='https://visitor-badge.laobi.icu/badge?page_id=WiNE-iNEFF.HF_Simple_Prompt_Generator&left_color=red&right_color=green&left_text=Visitors' alt='visitor badge'>
177
+ </center>
178
+ </div>
179
+ """
180
+ )
181
+ with gr.Column():
182
+ model_size = gr.Radio(
183
+ ["Prompt Generator v0.1(Better quality)", "Prompt Generator v0.2(More tags)"],
184
+ label="Model Variant",
185
+ value="Prompt Generator v0.1(Better quality)",
186
+ )
187
+ number = gr.Number(value="10", label="Num of tag (MAX 20)", show_label=True)
188
+ artist = gr.Number(value="2", label="Num of artist (Standart 2)", show_label=True)
189
+ out = gr.Textbox(lines=4, label="Generated Prompts")
190
+ greet_btn = gr.Button("Generate")
191
+ greet_btn.click(fn=promptgen, inputs=[model_size, number, artist], outputs=out, concurrency_limit=4)
192
+ gr.HTML(
193
+ """
194
+ <div class="footer">
195
+ <div style='text-align: center;'>Simple Prompt Generator by <a href='https://twitter.com/wine_ineff' target='_blank'>Artsem Holub (WiNE-iNEFF)</a><br>More information about this demo and script your can find in <a class='link-info' href="https://github.com/WiNE-iNEFF/Simple_Prompt_Generator" target="_blank">Github</a> and <a class='link-info' href="https://wine-ineff.github.io/Simple_Prompt_Generator/" target="_blank">Project site</a></div>
196
+ </div>
197
+ """
198
+ )
199
+
200
+ demo.queue()
201
+ demo.launch(server_name="127.0.0.1", server_port=7861, share=False)
202
+
203
+
204
+ def run_proxy():
205
+ sio_server = socketio.Server(async_mode="eventlet")
206
+ app = socketio.WSGIApp(sio_server)
207
+
208
+ sio_client = socketio.Client()
209
+
210
+ # 存储 sid 映射关系
211
+ client_sessions = {}
212
+
213
+ @sio_server.on("connect", namespace="/pty")
214
+ def connect(sid, environ):
215
+ print(f"Client connected: {sid}")
216
+ if not sio_client.connected:
217
+ sio_client.connect("http://127.0.0.1:7862", namespaces=["/pty"])
218
+ client_sessions[sid] = True
219
+
220
+ @sio_server.on("disconnect", namespace="/pty")
221
+ def disconnect(sid):
222
+ print(f"Client disconnected: {sid}")
223
+ client_sessions.pop(sid, None)
224
+ if not client_sessions:
225
+ sio_client.disconnect()
226
+
227
+ @sio_server.on("*", namespace="/pty")
228
+ def catch_all(event, sid, *args):
229
+ if event not in ["connect", "disconnect"]:
230
+ print(f"Forward to ek: {event}")
231
+ sio_client.emit(event, *args, namespace="/pty")
232
+
233
+ @sio_client.on("*", namespace="/pty")
234
+ def forward_from_ek(event, *args):
235
+ if event not in ["connect", "disconnect"]:
236
+ print(f"Forward from ek: {event}")
237
+ sio_server.emit(event, *args, namespace="/pty")
238
+
239
+ def proxy_handler(environ, start_response):
240
+ path = environ["PATH_INFO"]
241
+
242
+ if path.startswith("/ek"):
243
+ target = "http://127.0.0.1:7862"
244
+ else:
245
+ target = "http://127.0.0.1:7861"
246
+
247
+ url = f"{target}{path}"
248
+ headers = {}
249
+ for key, value in environ.items():
250
+ if key.startswith("HTTP_"):
251
+ header_key = key[5:].replace("_", "-").title()
252
+ if header_key.lower() not in ["connection", "upgrade", "proxy-connection"]:
253
+ headers[header_key] = value
254
+ content_length = environ.get("CONTENT_LENGTH")
255
+ body = None
256
+ if content_length:
257
+ content_length = int(content_length)
258
+ body = environ["wsgi.input"].read(content_length)
259
+
260
+ if environ.get("CONTENT_TYPE"):
261
+ headers["Content-Type"] = environ["CONTENT_TYPE"]
262
+ resp = requests.request(
263
+ method=environ["REQUEST_METHOD"],
264
+ url=url,
265
+ headers=headers,
266
+ data=body,
267
+ stream=True,
268
+ allow_redirects=False,
269
+ )
270
+
271
+ start_response(f"{resp.status_code} {resp.reason}", list(resp.headers.items()))
272
+ return resp.iter_content(chunk_size=4096)
273
+
274
+ app.wsgi_app = proxy_handler
275
+ eventlet.wsgi.server(eventlet.listen(("", 7860)), app)
276
+
277
+
278
+ if __name__ == "__main__":
279
+ print("Setting up EK...", flush=True)
280
+ if not setup_embykeeper():
281
+ print("Failed to setup EK!", flush=True)
282
+ sys.exit(1)
283
+
284
+ gradio_thread = threading.Thread(target=run_gradio)
285
+ gradio_thread.daemon = True
286
+ gradio_thread.start()
287
+
288
+ ek_thread = threading.Thread(
289
+ target=lambda: subprocess.run(["embykeeperweb", "--port", "7862", "--prefix", "/ek", "--public"])
290
+ )
291
+ ek_thread.daemon = True
292
+ ek_thread.start()
293
+
294
+ # 启动代理服务器(主线程)
295
+ print("Starting proxy server...", flush=True)
296
+ run_proxy()
pr1.txt ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ photorealistic
2
+ dramatic
3
+ dramatic color
4
+ liquid
5
+ Psychedelic
6
+ anime
7
+ render
8
+ detailed
9
+ super detailed
10
+ hyper detailed
11
+ colorful
12
+ atmosphere
13
+ cinematic
14
+ art by peter mohrbacher
15
+ art by ilya kuvshinov
16
+ art by hajime sorayama
17
+ art by wayne barlowe
18
+ art by boris vallejo
19
+ art by aaron horkey
20
+ art by gaston bussiere
21
+ art by craig mullins
22
+ art by wlop
23
+ art by ismail inceoglu
24
+ art by cory loftis
25
+ art by akihiko yoshida
26
+ art by james gilleard
27
+ art by atey ghailan
28
+ art by makoto shinkai
29
+ art by goro fujita
30
+ art by peter mohrbacher
31
+ art by greg rutkowski
32
+ art by artgerm
33
+ art by alphonse mucha
34
+ Chromatic aberration
35
+ glitch art
36
+ glitchy
37
+ Space art
38
+ abstract art
39
+ space
40
+ galaxy
41
+ smoke
42
+ dark fantasy
43
+ ivy
44
+ flowers
45
+ epic
46
+ stylized
47
+ sketch
48
+ bold sketch
49
+ character design
50
+ ice gate
51
+ central composition
52
+ baroqueart nouveau
53
+ epic sky
54
+ cinematic light
55
+ hanging vines
56
+ post-apocalypse
57
+ magical
58
+ volumetric fog
59
+ black background
60
+ shadow
61
+ soft shadow
62
+ concept art
63
+ design concept art
64
+ cyberpunk art
65
+ steampunk blueprint
66
+ volumetric
67
+ volumetric lighting
68
+ goddess of illusion
69
+ stunning
70
+ breathtaking
71
+ mirrors
72
+ glass
73
+ magic circle
74
+ unreal engine
75
+ unreal engine 5
76
+ octane render
77
+ vray render
78
+ arnold render
79
+ houdini
80
+ terragen
81
+ soft painting
82
+ clear focus
83
+ vfx
84
+ 8k
85
+ 8k 3d
86
+ 4k
87
+ 4k 3d
88
+ realistic
89
+ super realistic
90
+ hyper realistic
91
+ ufotable art style
92
+ ghibli art style
93
+ mappa art style
94
+ global illumination
95
+ pixiv
96
+ artstation
97
+ trending on pixiv
98
+ tranding on artstation
99
+ ray tracing
100
+ god rays
101
+ rossdraws global illumination
102
+ anime key visual
103
+ action shot
104
+ fanbox
105
+ moody lighting
106
+ lord of the rings
107
+ sharp contrast
108
+ light nover
109
+ light nover cover
110
+ Korean light novel
111
+ Japenese light novel
112
+ Korean light novel cover
113
+ Japenese light novel cover
114
+ game
115
+ visual novel
116
+ full body
117
+ full hd
118
+ dream word
119
+ landscape
120
+ beautiful landscape
121
+ realistic landscape
122
+ photorealistic landscape
123
+ photorealistic dramatic
124
+ photorealistic dramatic anime
125
+ photorealistic dramatic anime boy
126
+ photorealistic dramatic anime girl
127
+ photorealistic dramatic liquid anime girl
128
+ photorealistic dramatic liquid anime boy
129
+ horror
130
+ creepy
131
+ scary
132
+ detailed face
133
+ horror art
134
+ scary art
135
+ creepe art
136
+ funny art
137
+ scary art
138
+ ugly art
139
+ block cities
140
+ Funky pop
141
+ wearing in punk outfit
142
+ Flat Design Vector Illustrations
143
+ Vector Illustrations
144
+ Flat Design
145
+ RPG Item Icons
146
+ Item Icons
147
+ 3D Anime Avatar
148
+ round cute face
149
+ horizon zero dawn
150
+ world war
151
+ world war 2
152
+ world war 3
153
+ Everlasting summer
154
+ Fate/Stay night
155
+ hdr
156
+ fanart
157
+ artworks
158
+ other dimention
159
+ digital painting
160
+ smooth
161
+ radiant light
162
+ gold
163
+ silver
164
+ rose
165
+ ethereal
166
+ diamond
167
+ biomechanical
168
+ microbes
169
+ Anime Avatar
170
+ Nature Landscape Backgrounds - Winter
171
+ Nature Landscape Backgrounds
172
+ Comic Book Characters
173
+ Sci-Fi
174
+ Sci-Fi Zoom Backgrounds
175
+ Anime / Manga
176
+ Retro Psychedelic Posters
177
+ Techno Marble
178
+ Synth
179
+ Synthwave art
180
+ Your Name anime art style
181
+ Nature Sunsets
182
+ Sunsets
183
+ Synthwave
pr2.txt ADDED
The diff for this file is too large to render. See raw diff