Spaces:
Running
Running
github-actions
commited on
Commit
·
8682ef8
1
Parent(s):
e915cc7
Update for version v7.1.13
Browse files
app.py
CHANGED
@@ -9,47 +9,47 @@ e='HTTP_'
|
|
9 |
d='PATH_INFO'
|
10 |
c='embykeeperweb'
|
11 |
b='embykeeper'
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
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
|
27 |
from pathlib import Path
|
28 |
-
import threading as
|
29 |
from appdirs import user_data_dir as n
|
30 |
-
import socketio as
|
31 |
-
|
32 |
o=Path(n(b))
|
33 |
-
|
34 |
def p():
|
35 |
try:
|
36 |
-
|
37 |
if M.exists():B(f"Using cached version from {M}",flush=A);return A
|
38 |
-
|
39 |
if H.exists():B(f"Using cached tarball from {H}",flush=A);F.copy2(H,D)
|
40 |
-
else:
|
41 |
-
E.run(['tar','xf',D,'-C',
|
42 |
-
if not q(L):raise
|
43 |
-
B('Installing dependencies...',flush=A);E.run([
|
44 |
-
except
|
45 |
def q(package_path):
|
46 |
-
|
47 |
try:
|
48 |
-
E.run([
|
49 |
for K in[b,c]:
|
50 |
-
D=C.path.join(
|
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(
|
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
|
62 |
-
def
|
63 |
with H.listen(('',0))as A:return A.getsockname()[1]
|
64 |
def r():
|
65 |
-
|
66 |
-
def
|
67 |
-
L='art by';
|
68 |
-
if
|
69 |
-
elif J
|
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(
|
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(
|
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,
|
82 |
-
|
83 |
-
E.queue();
|
84 |
def s():
|
85 |
-
|
86 |
-
@E.on(
|
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 |
-
|
91 |
-
@E.on(
|
92 |
def S(sid):
|
93 |
-
B(f"Client disconnected: {sid}");
|
94 |
-
if not
|
95 |
@E.on('*',namespace=C)
|
96 |
def T(event,sid,*D):
|
97 |
A=event
|
98 |
-
if A not in[
|
99 |
@F.on('*',namespace=C)
|
100 |
-
def
|
101 |
A=event
|
102 |
-
if A not in[
|
103 |
def Q(environ,start_response):
|
104 |
B=environ;H=B[d]
|
105 |
-
if H.startswith(
|
106 |
-
else:
|
107 |
-
|
108 |
-
for(
|
109 |
-
if
|
110 |
-
|
111 |
-
if
|
112 |
-
C=B.get(i);
|
113 |
if C:
|
114 |
-
C=D(C);
|
115 |
-
if B.get(
|
116 |
-
E=
|
117 |
-
|
118 |
if __name__=='__main__':
|
119 |
B('Setting up EK...',flush=A)
|
120 |
-
if not p():B('Failed to setup EK!',flush=A);
|
121 |
-
|
122 |
def t(environ,start_response):
|
123 |
B=environ;H=B[d]
|
124 |
-
if H.startswith(
|
125 |
-
else:
|
126 |
-
|
127 |
-
for(
|
128 |
-
if
|
129 |
-
|
130 |
-
if
|
131 |
-
C=B.get(i);
|
132 |
if C:
|
133 |
-
C=D(C);
|
134 |
-
if B.get(
|
135 |
-
E=
|
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()
|