CoolSnow commited on
Commit
671eb1a
0 Parent(s):

feat: init

Browse files
Files changed (3) hide show
  1. .github/workflows/main.yml +19 -0
  2. README.md +12 -0
  3. app.py +144 -0
.github/workflows/main.yml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ # to run this workflow manually from the Actions tab
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ sync-to-hub:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ with:
14
+ fetch-depth: 0
15
+ lfs: true
16
+ - name: Push to hub
17
+ env:
18
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
19
+ run: git push -f https://CoolSnow:[email protected]/spaces/CoolSnow/HF-SpaceDemo main
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Stable Diffusion Models
3
+ emoji: 😻
4
+ colorFrom: red
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 3.23.0
8
+ app_file: app.py
9
+ pinned: true
10
+ ---
11
+
12
+ <!--Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference-->
app.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ # import os
3
+ # import sys
4
+ # from pathlib import Path
5
+ import time
6
+
7
+ models =[
8
+ "playgroundai/playground-v2-1024px-aesthetic",
9
+ "playgroundai/playground-v2-1024px-aesthetic",
10
+ "tkurtulus/sdxl_tk",
11
+ "Daniil-plotnikov/deepvision-v6-0",
12
+ "AVIIAX/majic6",
13
+ "digiplay/RunDiffusionFXPhotorealistic_v1",
14
+ "ARDICAI/stable-diffusion-2-1-finetuned",
15
+ "coinz/Imaginashin-xl-v0.1",
16
+ "robindon/lora-trained-xl-TOK-person",
17
+ ]
18
+
19
+
20
+ model_functions = {}
21
+ model_idx = 1
22
+ for model_path in models:
23
+ try:
24
+ model_functions[model_idx] = gr.Interface.load(f"models/{model_path}", live=False, preprocess=True, postprocess=False)
25
+ except Exception as error:
26
+ def the_fn(txt):
27
+ return None
28
+ model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
29
+ model_idx+=1
30
+
31
+
32
+ def send_it_idx(idx):
33
+ def send_it_fn(prompt):
34
+ output = (model_functions.get(str(idx)) or model_functions.get(str(1)))(prompt)
35
+ return output
36
+ return send_it_fn
37
+
38
+ def get_prompts(prompt_text):
39
+ return prompt_text
40
+
41
+ def clear_it(val):
42
+ if int(val) != 0:
43
+ val = 0
44
+ else:
45
+ val = 0
46
+ pass
47
+ return val
48
+
49
+ def all_task_end(cnt,t_stamp):
50
+ to = t_stamp + 60
51
+ et = time.time()
52
+ if et > to and t_stamp != 0:
53
+ d = gr.update(value=0)
54
+ tog = gr.update(value=1)
55
+ #print(f'to: {to} et: {et}')
56
+ else:
57
+ if cnt != 0:
58
+ d = gr.update(value=et)
59
+ else:
60
+ d = gr.update(value=0)
61
+ tog = gr.update(value=0)
62
+ #print (f'passing: to: {to} et: {et}')
63
+ pass
64
+ return d, tog
65
+
66
+ def all_task_start():
67
+ print("\n\n\n\n\n\n\n")
68
+ t = time.gmtime()
69
+ t_stamp = time.time()
70
+ current_time = time.strftime("%H:%M:%S", t)
71
+ return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
72
+
73
+ def clear_fn():
74
+ nn = len(models)
75
+ return tuple([None, *[None for _ in range(nn)]])
76
+
77
+
78
+
79
+ with gr.Blocks(title="SD Models") as my_interface:
80
+ with gr.Column(scale=12):
81
+ # with gr.Row():
82
+ # gr.Markdown("""- Primary prompt: 你想画的内容(英文单词,如 a cat, 加英文逗号效果更好;点 Improve 按钮进行完善)\n- Real prompt: 完善后的提示词,出现后再点右边的 Run 按钮开始运行""")
83
+ with gr.Row():
84
+ with gr.Row(scale=6):
85
+ primary_prompt=gr.Textbox(label="Prompt", value="")
86
+ # real_prompt=gr.Textbox(label="Real prompt")
87
+ with gr.Row(scale=6):
88
+ # improve_prompts_btn=gr.Button("Improve")
89
+ with gr.Row():
90
+ run=gr.Button("Run",variant="primary")
91
+ clear_btn=gr.Button("Clear")
92
+ with gr.Row():
93
+ sd_outputs = {}
94
+ model_idx = 1
95
+ for model_path in models:
96
+ with gr.Column(scale=3, min_width=320):
97
+ with gr.Box():
98
+ sd_outputs[model_idx] = gr.Image(label=model_path)
99
+ pass
100
+ model_idx += 1
101
+ pass
102
+ pass
103
+
104
+ with gr.Row(visible=False):
105
+ start_box=gr.Number(interactive=False)
106
+ end_box=gr.Number(interactive=False)
107
+ tog_box=gr.Textbox(value=0,interactive=False)
108
+
109
+ start_box.change(
110
+ all_task_end,
111
+ [start_box, end_box],
112
+ [start_box, tog_box],
113
+ every=1,
114
+ show_progress=False)
115
+
116
+ primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
117
+ run.click(all_task_start, None, [start_box, end_box, tog_box])
118
+ runs_dict = {}
119
+ model_idx = 1
120
+ for model_path in models:
121
+ runs_dict[model_idx] = run.click(model_functions[model_idx], inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
122
+ model_idx += 1
123
+ pass
124
+ pass
125
+
126
+ # improve_prompts_btn_clicked=improve_prompts_btn.click(
127
+ # get_prompts,
128
+ # inputs=[primary_prompt],
129
+ # outputs=[primary_prompt],
130
+ # cancels=list(runs_dict.values()))
131
+ clear_btn.click(
132
+ clear_fn,
133
+ None,
134
+ [primary_prompt, *list(sd_outputs.values())],
135
+ cancels=[*list(runs_dict.values())])
136
+ tog_box.change(
137
+ clear_it,
138
+ tog_box,
139
+ tog_box,
140
+ cancels=[*list(runs_dict.values())])
141
+
142
+ my_interface.queue(concurrency_count=600, status_update_rate=1)
143
+ my_interface.launch(inline=True, show_api=False)
144
+