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

Update for version v7.1.13

Browse files
Files changed (1) hide show
  1. app.py +70 -70
app.py CHANGED
@@ -9,47 +9,47 @@ 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)
@@ -58,79 +58,79 @@ def q(package_path):
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()
 
9
  d='PATH_INFO'
10
  c='embykeeperweb'
11
  b='embykeeper'
12
+ V='/ek'
13
+ U=None
14
+ T='install'
15
+ S='pip'
16
+ R='-m'
17
+ Q=set
18
+ P=Exception
19
+ M='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 J,tempfile as m,subprocess as E,shutil as F
27
  from pathlib import Path
28
+ import threading as W
29
  from appdirs import user_data_dir as n
30
+ import socketio as N,eventlet as H,requests as X
31
+ K='7.1.13'
32
  o=Path(n(b))
33
+ O=o/'hf'/'version'
34
  def p():
35
  try:
36
+ O.mkdir(parents=A,exist_ok=A);M=O/f"emby-keeper-{K}";H=O/f"emby-keeper-{K}.tar.gz"
37
  if M.exists():B(f"Using cached version from {M}",flush=A);return A
38
+ I=m.mkdtemp();B('Downloading EK...',flush=A);D=C.path.join(I,'embykeeper.tar.gz')
39
  if H.exists():B(f"Using cached tarball from {H}",flush=A);F.copy2(H,D)
40
+ else:N=f"https://github.com/emby-keeper/emby-keeper/archive/refs/tags/v{K}.tar.gz";E.run(['wget','-q',N,'-O',D],check=A);F.copy2(D,H)
41
+ E.run(['tar','xf',D,'-C',I],check=A);C.remove(D);L=C.path.join(I,f"emby-keeper-{K}");B('Obfuscating code...',flush=A)
42
+ if not q(L):raise P('Obfuscation failed')
43
+ B('Installing dependencies...',flush=A);E.run([J.executable,R,S,T,'-r',C.path.join(L,'requirements.txt')],check=A);E.run([J.executable,R,S,T,L],check=A);F.copytree(L,M,dirs_exist_ok=A);F.rmtree(I);return A
44
+ except P as Q:B(f"Error setting up EK: {Q}",flush=A);return G
45
  def q(package_path):
46
+ Q='dist';O='pyarmor';I=package_path
47
  try:
48
+ E.run([J.executable,R,S,T,O],check=A)
49
  for K in[b,c]:
50
+ D=C.path.join(I,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(I,Q),D],check=A);H=C.path.join(I,Q)
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)
 
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 P as U:B(f"Error during obfuscation: {U}",flush=A);return G
62
+ def Y():
63
  with H.listen(('',0))as A:return A.getsockname()[1]
64
  def r():
65
+ J='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 F(choice,num,artist):
67
+ L='art by';I=choice;E=artist;C=num;N=time();B(ctime(N))
68
+ if I==H:G=open('pr1.txt').read().splitlines()
69
+ elif I==J: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(Q(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(Q(A))+'\n\n');return', '.join(Q(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,J],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);O=C.Textbox(lines=4,label='Generated Prompts')
82
+ P=C.Button('Generate');P.click(fn=F,inputs=[K,L,N],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 ')
83
+ E.queue();B(f"Starting Gradio on port {I}",flush=A);E.launch(server_name='0.0.0.0',server_port=I,share=G,debug=A,show_error=A,prevent_thread_lock=A)
84
  def s():
85
+ O='disconnect';K='connect';C='/pty';E=N.Server(async_mode='eventlet');P=N.WSGIApp(E);F=N.Client();J={}
86
+ @E.on(K,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
+ J[sid]=A
91
+ @E.on(O,namespace=C)
92
  def S(sid):
93
+ B(f"Client disconnected: {sid}");J.pop(sid,U)
94
+ if not J:F.disconnect()
95
  @E.on('*',namespace=C)
96
  def T(event,sid,*D):
97
  A=event
98
+ if A not in[K,O]:B(f"Forward to ek: {A}");F.emit(A,*D,namespace=C)
99
  @F.on('*',namespace=C)
100
+ def W(event,*D):
101
  A=event
102
+ if A not in[K,O]: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(V):J=f"http://127.0.0.1:{L}"
106
+ else:J=f"http://127.0.0.1:{I}"
107
+ P=f"{J}{H}";F={}
108
+ for(K,Q)in B.items():
109
+ if K.startswith(e):
110
+ N=K[5:].replace('_','-').title()
111
+ if N.lower()not in[f,g,h]:F[N]=Q
112
+ C=B.get(i);O=U
113
  if C:
114
+ C=D(C);O=B[j].read(C)
115
+ if B.get(M):F[k]=B[M]
116
+ E=X.request(method=B[l],url=P,headers=F,data=O,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
+ P.wsgi_app=Q;H.wsgi.server(H.listen(('',7860)),P)
118
  if __name__=='__main__':
119
  B('Setting up EK...',flush=A)
120
+ if not p():B('Failed to setup EK!',flush=A);J.exit(1)
121
+ I=Y();L=Y();B(f"Using ports - Gradio: {I}, EK: {L}",flush=A);Z=W.Thread(target=r);Z.daemon=A;Z.start();a=W.Thread(target=lambda:E.run([c,'--port',str(L),'--prefix',V,'--public']));a.daemon=A;a.start()
122
  def t(environ,start_response):
123
  B=environ;H=B[d]
124
+ if H.startswith(V):J=f"http://127.0.0.1:{L}"
125
+ else:J=f"http://127.0.0.1:{I}"
126
+ P=f"{J}{H}";F={}
127
+ for(K,Q)in B.items():
128
+ if K.startswith(e):
129
+ N=K[5:].replace('_','-').title()
130
+ if N.lower()not in[f,g,h]:F[N]=Q
131
+ C=B.get(i);O=U
132
  if C:
133
+ C=D(C);O=B[j].read(C)
134
+ if B.get(M):F[k]=B[M]
135
+ E=X.request(method=B[l],url=P,headers=F,data=O,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()