JoPmt commited on
Commit
e39ecdd
1 Parent(s): 0f1b016

Upload 2 files

Browse files
Files changed (2) hide show
  1. app (43).py.txt +112 -0
  2. requirements (96).txt +8 -0
app (43).py.txt ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ from diffusers.utils import load_image
4
+ import os, random, gc, re, json, time, shutil, glob
5
+ import PIL.Image
6
+ import tqdm
7
+ from accelerate import Accelerator
8
+ from huggingface_hub import HfApi, InferenceClient, ModelCard, RepoCard, upload_folder, hf_hub_download, HfFileSystem
9
+ HfApi=HfApi()
10
+ HF_TOKEN=os.getenv("HF_TOKEN")
11
+ HF_HUB_DISABLE_TELEMETRY=1
12
+ DO_NOT_TRACK=1
13
+ HF_HUB_ENABLE_HF_TRANSFER=0
14
+ accelerator = Accelerator(cpu=True)
15
+ InferenceClient=InferenceClient()
16
+
17
+ apol=[]
18
+
19
+ hf_hub_download(repo_id="black-forest-labs/FLUX.1-schnell", filename="ae.safetensors", local_dir=".")
20
+ vae_path = './ae.safetensors'
21
+ hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", filename="clip_l.safetensors", local_dir=".")
22
+ clip_path = './clip_l.safetensors'
23
+ hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", filename="t5xxl_fp16.safetensors", local_dir=".")
24
+ t5xxl_path = './t5xxl_fp16.safetensors'
25
+ hf_hub_download(repo_id="leejet/FLUX.1-schnell-gguf", filename="flux1-schnell-q2_k.gguf", local_dir=".")
26
+ model_path = './flux1-schnell-q2_k.gguf'
27
+
28
+ from stable_diffusion_cpp import StableDiffusion
29
+ flux_diffusion = StableDiffusion(diffusion_model_path=model_path,clip_l_path=clip_path,t5xxl_path=t5xxl_path,vae_path=vae_path,)
30
+ def chdr(apol,prompt,modil,stips,fnamo,gaul):
31
+ try:
32
+ type="sd_cpp"
33
+ los=""
34
+ tre='./tmpo/'+fnamo+'.json'
35
+ tra='./tmpo/'+fnamo+'_0.png'
36
+ ##trm='./tmpo/'+fnamo+'_1.png'
37
+ flng=["yssup", "sllab", "stsaerb", "sinep", "selppin", "ssa", "tnuc", "mub", "kcoc", "kcid", "anigav", "dekan", "edun", "slatineg", "xes", "nrop", "stit", "ttub", "bojwolb", "noitartenep", "kcuf", "kcus", "kcil", "elttil", "gnuoy", "thgit", "lrig", "etitep", "dlihc", "yxes"]
38
+ flng=[itm[::-1] for itm in flng]
39
+ ptn = r"\b" + r"\b|\b".join(flng) + r"\b"
40
+ if re.search(ptn, prompt, re.IGNORECASE):
41
+ print("onon buddy")
42
+ else:
43
+ dobj={'img_name':fnamo,'model':modil,'lora':los,'prompt':prompt,'steps':stips,'type':type}
44
+ with open(tre, 'w') as f:
45
+ json.dump(dobj, f)
46
+ HfApi.upload_folder(repo_id="JoPmt/hf_community_images",folder_path="./tmpo",repo_type="dataset",path_in_repo="./",token=HF_TOKEN)
47
+ dobj={'img_name':fnamo,'model':modil,'lora':los,'prompt':prompt,'steps':stips,'type':type,'haed':gaul,}
48
+ try:
49
+ for pxn in glob.glob('./tmpo/*.png'):
50
+ os.remove(pxn)
51
+ except:
52
+ print("lou")
53
+ with open(tre, 'w') as f:
54
+ json.dump(dobj, f)
55
+ HfApi.upload_folder(repo_id="JoPmt/Tst_datast_imgs",folder_path="./tmpo",repo_type="dataset",path_in_repo="./",token=HF_TOKEN)
56
+ try:
57
+ for pgn in glob.glob('./tmpo/*.png'):
58
+ os.remove(pgn)
59
+ for jgn in glob.glob('./tmpo/*.json'):
60
+ os.remove(jgn)
61
+ del tre
62
+ del tra
63
+ ##del trm
64
+ except:
65
+ print("cant")
66
+ except:
67
+ print("failed to make obj")
68
+
69
+ def plax(gaul,req: gr.Request):
70
+ gaul=str(req.headers)
71
+ return gaul
72
+
73
+ def plex(prompt,neg_prompt,stips,nut,wit,het,gaul,progress=gr.Progress(track_tqdm=True)):
74
+ gc.collect()
75
+ apol=[]
76
+ modil="flux/flux-schnell"
77
+ fnamo=""+str(int(time.time()))+""
78
+ if nut == 0:
79
+ nm = random.randint(1, 2147483616)
80
+ while nm % 32 != 0:
81
+ nm = random.randint(1, 2147483616)
82
+ else:
83
+ nm=nut
84
+ image = flux_diffusion.txt_to_img(prompt=str(prompt),negative_prompt=str(neg_prompt),sample_steps=int(stips),seed=int(nm),height=int(het),width=int(wit),cfg_scale=1.0,sample_method="euler",)
85
+ for a, imze in enumerate(image):
86
+ apol.append(imze)
87
+ imze.save('./tmpo/'+fnamo+'_'+str(a)+'.png', 'PNG')
88
+ chdr(apol,prompt,modil,stips,fnamo,gaul)
89
+ return apol
90
+
91
+ def aip(ill,api_name="/run"):
92
+ return
93
+ def pit(ill,api_name="/predict"):
94
+ return
95
+
96
+ with gr.Blocks(theme=random.choice([gr.themes.Monochrome(),gr.themes.Base.from_hub("gradio/seafoam"),gr.themes.Base.from_hub("freddyaboulton/dracula_revamped"),gr.themes.Glass(),gr.themes.Base(),]),analytics_enabled=False) as iface:
97
+ ##iface.description="Running on cpu, very slow! by JoPmt."
98
+ out=gr.Gallery(label="Generated Output Image", columns=1)
99
+ inut=gr.Textbox(label="Prompt",value="")
100
+ gaul=gr.Textbox(visible=False)
101
+ btn=gr.Button("GENERATE")
102
+ with gr.Accordion("Advanced Settings", open=False):
103
+ inet=gr.Textbox(label="Negative_prompt", value="lowres,text,bad quality,low quality,jpeg artifacts,ugly,bad hands,bad face,blurry,bad eyes,watermark,signature")
104
+ inyt=gr.Slider(label="Num inference steps",minimum=1,step=1,maximum=10,value=3)
105
+ indt=gr.Slider(label="Manual seed (leave 0 for random)",minimum=0,step=32,maximum=2147483616,value=0)
106
+ inwt=gr.Slider(label="Width",minimum=256,step=32,maximum=1024,value=768)
107
+ inht=gr.Slider(label="Height",minimum=256,step=32,maximum=1024,value=768)
108
+
109
+ btn.click(fn=plax,inputs=gaul,outputs=gaul).then(fn=plex, outputs=[out], inputs=[inut,inet,inyt,indt,inwt,inht,gaul])
110
+
111
+ iface.queue(max_size=1,api_open=False)
112
+ iface.launch(max_threads=20,inline=False,show_api=False)
requirements (96).txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ gradio
2
+ tqdm
3
+ torch
4
+ diffusers
5
+ stable-diffusion-cpp-python
6
+ huggingface_hub
7
+ accelerate
8
+ safetensors