Spaces:
Running
Running
github-actions
commited on
Commit
·
e915cc7
1
Parent(s):
a4de351
Update for version v7.1.12
Browse files
app.py
CHANGED
@@ -1,108 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
W='/ek'
|
2 |
-
V=
|
3 |
-
U='
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
G=False
|
10 |
-
|
11 |
B=print
|
12 |
A=True
|
13 |
import eventlet as H
|
14 |
H.monkey_patch()
|
15 |
-
import os as C,sys as I,tempfile as
|
16 |
from pathlib import Path
|
17 |
-
import threading as
|
18 |
-
from appdirs import user_data_dir as
|
19 |
-
import socketio as
|
20 |
-
J='7.1.
|
21 |
-
|
22 |
-
|
23 |
-
def
|
24 |
try:
|
25 |
-
|
26 |
-
if
|
27 |
-
K=
|
28 |
-
if H.exists():B(f"Using cached tarball from {H}",flush=A);
|
29 |
-
else:
|
30 |
-
|
31 |
-
if not
|
32 |
-
B('Installing dependencies...',flush=A);
|
33 |
-
except
|
34 |
-
def
|
35 |
-
|
36 |
try:
|
37 |
-
|
38 |
-
for K in[
|
39 |
-
|
40 |
-
if not C.path.exists(
|
41 |
-
B(f"Obfuscating {K}...",flush=A);
|
42 |
if C.path.exists(H):
|
43 |
for M in C.listdir(H):
|
44 |
-
L=C.path.join(H,M);
|
45 |
-
if C.path.isdir(L):
|
46 |
-
else:
|
47 |
-
|
48 |
else:B(f"Dist directory not found after obfuscation for {K}",flush=A);return G
|
49 |
return A
|
50 |
-
except
|
51 |
-
def
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
55 |
if J==H:G=open('pr1.txt').read().splitlines()
|
56 |
elif J==I:G=open('pr2.txt').read().splitlines()
|
57 |
-
if
|
58 |
-
if
|
59 |
-
|
60 |
-
while len(sorted(
|
61 |
-
|
62 |
-
if
|
63 |
-
elif not
|
64 |
-
B(', '.join(
|
65 |
-
|
66 |
-
with
|
67 |
C.HTML('\n <div style="text-align: center; margin: 0 auto;">\n <div style="display: inline-flex;align-items: center;gap: 0.8rem;font-size: 1.75rem;">\n <h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">\n Simple Prompt Generator v0.6 (Gradio Demo)\n </h1>\n </div>\n <p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">\n 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>\n </p>\n <center>\n <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\'>\n <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\'>\n </center>\n </div>\n ')
|
68 |
-
with C.Column():
|
69 |
-
|
70 |
-
|
71 |
-
def
|
72 |
-
N='
|
73 |
-
@
|
74 |
-
def
|
75 |
B(f"Client connected: {sid}")
|
76 |
-
if not
|
77 |
I[sid]=A
|
78 |
-
@
|
79 |
-
def
|
80 |
-
B(f"Client disconnected: {sid}");I.pop(sid,
|
81 |
-
if not I:
|
82 |
-
@D.on('*',namespace=C)
|
83 |
-
def R(event,sid,*D):
|
84 |
-
A=event
|
85 |
-
if A not in[J,L]:B(f"Forward to ek: {A}");E.emit(A,*D,namespace=C)
|
86 |
@E.on('*',namespace=C)
|
87 |
-
def
|
|
|
|
|
|
|
|
|
88 |
A=event
|
89 |
-
if A not in[J,
|
90 |
-
def
|
91 |
-
|
92 |
-
if H.startswith(W):I=
|
93 |
-
else:I=
|
94 |
-
O=f"{I}{H}";
|
95 |
-
for(J,
|
96 |
-
if J.startswith(
|
97 |
-
|
98 |
-
if
|
99 |
-
C=B.get(
|
100 |
if C:
|
101 |
-
C=
|
102 |
-
if B.get(
|
103 |
-
|
104 |
-
|
105 |
if __name__=='__main__':
|
106 |
B('Setting up EK...',flush=A)
|
107 |
-
if not
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
l='REQUEST_METHOD'
|
2 |
+
k='Content-Type'
|
3 |
+
j='wsgi.input'
|
4 |
+
i='CONTENT_LENGTH'
|
5 |
+
h='proxy-connection'
|
6 |
+
g='upgrade'
|
7 |
+
f='connection'
|
8 |
+
e='HTTP_'
|
9 |
+
d='PATH_INFO'
|
10 |
+
c='embykeeperweb'
|
11 |
+
b='embykeeper'
|
12 |
W='/ek'
|
13 |
+
V=None
|
14 |
+
U='install'
|
15 |
+
T='pip'
|
16 |
+
S='-m'
|
17 |
+
R=set
|
18 |
+
Q=Exception
|
19 |
+
L='CONTENT_TYPE'
|
20 |
G=False
|
21 |
+
D=int
|
22 |
B=print
|
23 |
A=True
|
24 |
import eventlet as H
|
25 |
H.monkey_patch()
|
26 |
+
import os as C,sys as I,tempfile as m,subprocess as E,shutil as F
|
27 |
from pathlib import Path
|
28 |
+
import threading as X
|
29 |
+
from appdirs import user_data_dir as n
|
30 |
+
import socketio as M,eventlet as H,requests as Y
|
31 |
+
J='7.1.12'
|
32 |
+
o=Path(n(b))
|
33 |
+
N=o/'hf'/'version'
|
34 |
+
def p():
|
35 |
try:
|
36 |
+
N.mkdir(parents=A,exist_ok=A);M=N/f"emby-keeper-{J}";H=N/f"emby-keeper-{J}.tar.gz"
|
37 |
+
if M.exists():B(f"Using cached version from {M}",flush=A);return A
|
38 |
+
K=m.mkdtemp();B('Downloading EK...',flush=A);D=C.path.join(K,'embykeeper.tar.gz')
|
39 |
+
if H.exists():B(f"Using cached tarball from {H}",flush=A);F.copy2(H,D)
|
40 |
+
else:O=f"https://github.com/emby-keeper/emby-keeper/archive/refs/tags/v{J}.tar.gz";E.run(['wget','-q',O,'-O',D],check=A);F.copy2(D,H)
|
41 |
+
E.run(['tar','xf',D,'-C',K],check=A);C.remove(D);L=C.path.join(K,f"emby-keeper-{J}");B('Obfuscating code...',flush=A)
|
42 |
+
if not q(L):raise Q('Obfuscation failed')
|
43 |
+
B('Installing dependencies...',flush=A);E.run([I.executable,S,T,U,'-r',C.path.join(L,'requirements.txt')],check=A);E.run([I.executable,S,T,U,L],check=A);F.copytree(L,M,dirs_exist_ok=A);F.rmtree(K);return A
|
44 |
+
except Q as P:B(f"Error setting up EK: {P}",flush=A);return G
|
45 |
+
def q(package_path):
|
46 |
+
P='dist';O='pyarmor';J=package_path
|
47 |
try:
|
48 |
+
E.run([I.executable,S,T,U,O],check=A)
|
49 |
+
for K in[b,c]:
|
50 |
+
D=C.path.join(J,K)
|
51 |
+
if not C.path.exists(D):B(f"Package directory not found: {D}",flush=A);continue
|
52 |
+
B(f"Obfuscating {K}...",flush=A);E.run([O,'gen','--recursive','--output',C.path.join(J,P),D],check=A);H=C.path.join(J,P)
|
53 |
if C.path.exists(H):
|
54 |
for M in C.listdir(H):
|
55 |
+
L=C.path.join(H,M);N=C.path.join(D,M)
|
56 |
+
if C.path.isdir(L):F.copytree(L,N,dirs_exist_ok=A)
|
57 |
+
else:F.copy2(L,N)
|
58 |
+
F.rmtree(H)
|
59 |
else:B(f"Dist directory not found after obfuscation for {K}",flush=A);return G
|
60 |
return A
|
61 |
+
except Q as R:B(f"Error during obfuscation: {R}",flush=A);return G
|
62 |
+
def O():
|
63 |
+
with H.listen(('',0))as A:return A.getsockname()[1]
|
64 |
+
def r():
|
65 |
+
I='Prompt Generator v0.2(More tags)';H='Prompt Generator v0.1(Better quality)';import gradio as C,random as M;from time import time,ctime
|
66 |
+
def J(choice,num,artist):
|
67 |
+
L='art by';J=choice;E=artist;C=num;N=time();B(ctime(N))
|
68 |
if J==H:G=open('pr1.txt').read().splitlines()
|
69 |
elif J==I:G=open('pr2.txt').read().splitlines()
|
70 |
+
if D(C)<1 or D(C)>20:C=10
|
71 |
+
if D(E)<0 or D(E)>40:E=2
|
72 |
+
O=len(G);A=[];K=0
|
73 |
+
while len(sorted(R(A),key=lambda d:A.index(d)))<D(C):
|
74 |
+
F=M.choice(G)
|
75 |
+
if F.startswith(L)and K<D(E):K+=1;A.append(F)
|
76 |
+
elif not F.startswith(L):A.append(F)
|
77 |
+
B(', '.join(R(A))+'\n\n');return', '.join(R(A))
|
78 |
+
E=C.Blocks()
|
79 |
+
with E:
|
80 |
C.HTML('\n <div style="text-align: center; margin: 0 auto;">\n <div style="display: inline-flex;align-items: center;gap: 0.8rem;font-size: 1.75rem;">\n <h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">\n Simple Prompt Generator v0.6 (Gradio Demo)\n </h1>\n </div>\n <p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">\n 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>\n </p>\n <center>\n <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\'>\n <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\'>\n </center>\n </div>\n ')
|
81 |
+
with C.Column():K=C.Radio([H,I],label='Model Variant',value=H);L=C.Number(value='10',label='Num of tag (MAX 20)',show_label=A);N=C.Number(value='2',label='Num of artist (Standart 2)',show_label=A);P=C.Textbox(lines=4,label='Generated Prompts')
|
82 |
+
Q=C.Button('Generate');Q.click(fn=J,inputs=[K,L,N],outputs=P,concurrency_limit=4);C.HTML('\n <div class="footer">\n <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>\n </div>\n ')
|
83 |
+
E.queue();F=O();B(f"Starting Gradio on port {F}",flush=A);E.launch(server_name='127.0.0.1',server_port=F,share=G);return F
|
84 |
+
def s():
|
85 |
+
N='disconnect';J='connect';C='/pty';E=M.Server(async_mode='eventlet');O=M.WSGIApp(E);F=M.Client();I={}
|
86 |
+
@E.on(J,namespace=C)
|
87 |
+
def R(sid,environ):
|
88 |
B(f"Client connected: {sid}")
|
89 |
+
if not F.connected:F.connect('http://127.0.0.1:7862',namespaces=[C])
|
90 |
I[sid]=A
|
91 |
+
@E.on(N,namespace=C)
|
92 |
+
def S(sid):
|
93 |
+
B(f"Client disconnected: {sid}");I.pop(sid,V)
|
94 |
+
if not I:F.disconnect()
|
|
|
|
|
|
|
|
|
95 |
@E.on('*',namespace=C)
|
96 |
+
def T(event,sid,*D):
|
97 |
+
A=event
|
98 |
+
if A not in[J,N]:B(f"Forward to ek: {A}");F.emit(A,*D,namespace=C)
|
99 |
+
@F.on('*',namespace=C)
|
100 |
+
def U(event,*D):
|
101 |
A=event
|
102 |
+
if A not in[J,N]:B(f"Forward from ek: {A}");E.emit(A,*D,namespace=C)
|
103 |
+
def Q(environ,start_response):
|
104 |
+
B=environ;H=B[d]
|
105 |
+
if H.startswith(W):I=f"http://127.0.0.1:{K}"
|
106 |
+
else:I=f"http://127.0.0.1:{P}"
|
107 |
+
O=f"{I}{H}";F={}
|
108 |
+
for(J,Q)in B.items():
|
109 |
+
if J.startswith(e):
|
110 |
+
M=J[5:].replace('_','-').title()
|
111 |
+
if M.lower()not in[f,g,h]:F[M]=Q
|
112 |
+
C=B.get(i);N=V
|
113 |
if C:
|
114 |
+
C=D(C);N=B[j].read(C)
|
115 |
+
if B.get(L):F[k]=B[L]
|
116 |
+
E=Y.request(method=B[l],url=O,headers=F,data=N,stream=A,allow_redirects=G);start_response(f"{E.status_code} {E.reason}",list(E.headers.items()));return E.iter_content(chunk_size=4096)
|
117 |
+
O.wsgi_app=Q;H.wsgi.server(H.listen(('',7860)),O)
|
118 |
if __name__=='__main__':
|
119 |
B('Setting up EK...',flush=A)
|
120 |
+
if not p():B('Failed to setup EK!',flush=A);I.exit(1)
|
121 |
+
P=O();K=O();B(f"Using ports - Gradio: {P}, EK: {K}",flush=A);Z=X.Thread(target=lambda:r());Z.daemon=A;Z.start();a=X.Thread(target=lambda:E.run([c,'--port',str(K),'--prefix',W,'--public']));a.daemon=A;a.start()
|
122 |
+
def t(environ,start_response):
|
123 |
+
B=environ;H=B[d]
|
124 |
+
if H.startswith(W):I=f"http://127.0.0.1:{K}"
|
125 |
+
else:I=f"http://127.0.0.1:{P}"
|
126 |
+
O=f"{I}{H}";F={}
|
127 |
+
for(J,Q)in B.items():
|
128 |
+
if J.startswith(e):
|
129 |
+
M=J[5:].replace('_','-').title()
|
130 |
+
if M.lower()not in[f,g,h]:F[M]=Q
|
131 |
+
C=B.get(i);N=V
|
132 |
+
if C:
|
133 |
+
C=D(C);N=B[j].read(C)
|
134 |
+
if B.get(L):F[k]=B[L]
|
135 |
+
E=Y.request(method=B[l],url=O,headers=F,data=N,stream=A,allow_redirects=G);start_response(f"{E.status_code} {E.reason}",list(E.headers.items()));return E.iter_content(chunk_size=4096)
|
136 |
+
B('Starting proxy server on port 7860...',flush=A);s()
|