github-actions commited on
Commit
e915cc7
·
1 Parent(s): a4de351

Update for version v7.1.12

Browse files
Files changed (1) hide show
  1. app.py +113 -85
app.py CHANGED
@@ -1,108 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
1
  W='/ek'
2
- V='embykeeperweb'
3
- U='embykeeper'
4
- Q='install'
5
- P='pip'
6
- O='-m'
7
- L=set
8
- N=Exception
9
  G=False
10
- F=int
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 X,subprocess as D,shutil as E
16
  from pathlib import Path
17
- import threading as R
18
- from appdirs import user_data_dir as Y
19
- import socketio as K,eventlet as H,requests as Z
20
- J='7.1.11'
21
- a=Path(Y(U))
22
- M=a/'hf'/'version'
23
- def b():
24
  try:
25
- M.mkdir(parents=A,exist_ok=A);R=M/f"emby-keeper-{J}";H=M/f"emby-keeper-{J}.tar.gz"
26
- if R.exists():B(f"Using cached version from {R}",flush=A);return A
27
- K=X.mkdtemp();B('Downloading EK...',flush=A);F=C.path.join(K,'embykeeper.tar.gz')
28
- if H.exists():B(f"Using cached tarball from {H}",flush=A);E.copy2(H,F)
29
- else:S=f"https://github.com/emby-keeper/emby-keeper/archive/refs/tags/v{J}.tar.gz";D.run(['wget','-q',S,'-O',F],check=A);E.copy2(F,H)
30
- D.run(['tar','xf',F,'-C',K],check=A);C.remove(F);L=C.path.join(K,f"emby-keeper-{J}");B('Obfuscating code...',flush=A)
31
- if not c(L):raise N('Obfuscation failed')
32
- B('Installing dependencies...',flush=A);D.run([I.executable,O,P,Q,'-r',C.path.join(L,'requirements.txt')],check=A);D.run([I.executable,O,P,Q,L],check=A);E.copytree(L,R,dirs_exist_ok=A);E.rmtree(K);return A
33
- except N as T:B(f"Error setting up EK: {T}",flush=A);return G
34
- def c(package_path):
35
- T='dist';S='pyarmor';J=package_path
36
  try:
37
- D.run([I.executable,O,P,Q,S],check=A)
38
- for K in[U,V]:
39
- F=C.path.join(J,K)
40
- if not C.path.exists(F):B(f"Package directory not found: {F}",flush=A);continue
41
- B(f"Obfuscating {K}...",flush=A);D.run([S,'gen','--recursive','--output',C.path.join(J,T),F],check=A);H=C.path.join(J,T)
42
  if C.path.exists(H):
43
  for M in C.listdir(H):
44
- L=C.path.join(H,M);R=C.path.join(F,M)
45
- if C.path.isdir(L):E.copytree(L,R,dirs_exist_ok=A)
46
- else:E.copy2(L,R)
47
- E.rmtree(H)
48
  else:B(f"Dist directory not found after obfuscation for {K}",flush=A);return G
49
  return A
50
- except N as W:B(f"Error during obfuscation: {W}",flush=A);return G
51
- def d():
52
- I='Prompt Generator v0.2(More tags)';H='Prompt Generator v0.1(Better quality)';import gradio as C,random as N;from time import time,ctime
53
- def E(choice,num,artist):
54
- M='art by';J=choice;D=artist;C=num;O=time();B(ctime(O))
 
 
55
  if J==H:G=open('pr1.txt').read().splitlines()
56
  elif J==I:G=open('pr2.txt').read().splitlines()
57
- if F(C)<1 or F(C)>20:C=10
58
- if F(D)<0 or F(D)>40:D=2
59
- P=len(G);A=[];K=0
60
- while len(sorted(L(A),key=lambda d:A.index(d)))<F(C):
61
- E=N.choice(G)
62
- if E.startswith(M)and K<F(D):K+=1;A.append(E)
63
- elif not E.startswith(M):A.append(E)
64
- B(', '.join(L(A))+'\n\n');return', '.join(L(A))
65
- D=C.Blocks()
66
- with D:
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():J=C.Radio([H,I],label='Model Variant',value=H);K=C.Number(value='10',label='Num of tag (MAX 20)',show_label=A);M=C.Number(value='2',label='Num of artist (Standart 2)',show_label=A);O=C.Textbox(lines=4,label='Generated Prompts')
69
- P=C.Button('Generate');P.click(fn=E,inputs=[J,K,M],outputs=O,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 ')
70
- D.queue();D.launch(server_name='127.0.0.1',server_port=7861,share=G)
71
- def e():
72
- N='http://127.0.0.1:7862';L='disconnect';J='connect';C='/pty';D=K.Server(async_mode='eventlet');M=K.WSGIApp(D);E=K.Client();I={}
73
- @D.on(J,namespace=C)
74
- def P(sid,environ):
75
  B(f"Client connected: {sid}")
76
- if not E.connected:E.connect(N,namespaces=[C])
77
  I[sid]=A
78
- @D.on(L,namespace=C)
79
- def Q(sid):
80
- B(f"Client disconnected: {sid}");I.pop(sid,None)
81
- if not I:E.disconnect()
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 S(event,*E):
 
 
 
 
88
  A=event
89
- if A not in[J,L]:B(f"Forward from ek: {A}");D.emit(A,*E,namespace=C)
90
- def O(environ,start_response):
91
- M='CONTENT_TYPE';B=environ;H=B['PATH_INFO']
92
- if H.startswith(W):I=N
93
- else:I='http://127.0.0.1:7861'
94
- O=f"{I}{H}";E={}
95
- for(J,P)in B.items():
96
- if J.startswith('HTTP_'):
97
- K=J[5:].replace('_','-').title()
98
- if K.lower()not in['connection','upgrade','proxy-connection']:E[K]=P
99
- C=B.get('CONTENT_LENGTH');L=None
100
  if C:
101
- C=F(C);L=B['wsgi.input'].read(C)
102
- if B.get(M):E['Content-Type']=B[M]
103
- D=Z.request(method=B['REQUEST_METHOD'],url=O,headers=E,data=L,stream=A,allow_redirects=G);start_response(f"{D.status_code} {D.reason}",list(D.headers.items()));return D.iter_content(chunk_size=4096)
104
- M.wsgi_app=O;H.wsgi.server(H.listen(('',7860)),M)
105
  if __name__=='__main__':
106
  B('Setting up EK...',flush=A)
107
- if not b():B('Failed to setup EK!',flush=A);I.exit(1)
108
- S=R.Thread(target=d);S.daemon=A;S.start();T=R.Thread(target=lambda:D.run([V,'--port','7862','--prefix',W,'--public']));T.daemon=A;T.start();B('Starting proxy server...',flush=A);e()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()