Spaces:
Runtime error
Runtime error
Commit
•
0a86e3a
0
Parent(s):
Duplicate from doevent/Stable-Diffusion-prompt-generator
Browse filesCo-authored-by: Max Skobeev <[email protected]>
- .gitattributes +31 -0
- README.md +14 -0
- app.py +59 -0
- ideas.txt +0 -0
- requirements.txt +4 -0
.gitattributes
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
23 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: MagicPrompt Stable Diffusion
|
3 |
+
emoji: 😻😻
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.9
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: doevent/Stable-Diffusion-prompt-generator
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline, set_seed
|
2 |
+
import gradio as grad, random, re
|
3 |
+
|
4 |
+
|
5 |
+
gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2')
|
6 |
+
with open("ideas.txt", "r") as f:
|
7 |
+
line = f.readlines()
|
8 |
+
|
9 |
+
|
10 |
+
def generate(starting_text):
|
11 |
+
for count in range(4):
|
12 |
+
seed = random.randint(100, 1000000)
|
13 |
+
set_seed(seed)
|
14 |
+
|
15 |
+
if starting_text == "":
|
16 |
+
starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize()
|
17 |
+
starting_text: str = re.sub(r"[,:\-–.!;?_]", '', starting_text)
|
18 |
+
print(starting_text)
|
19 |
+
|
20 |
+
response = gpt2_pipe(starting_text, max_length=random.randint(60, 90), num_return_sequences=4)
|
21 |
+
response_list = []
|
22 |
+
for x in response:
|
23 |
+
resp = x['generated_text'].strip()
|
24 |
+
if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "—")) is False:
|
25 |
+
response_list.append(resp+'\n')
|
26 |
+
|
27 |
+
response_end = "\n".join(response_list)
|
28 |
+
response_end = re.sub('[^ ]+\.[^ ]+','', response_end)
|
29 |
+
response_end = response_end.replace("<", "").replace(">", "")
|
30 |
+
|
31 |
+
if response_end != "":
|
32 |
+
return response_end
|
33 |
+
if count == 4:
|
34 |
+
return response_end
|
35 |
+
|
36 |
+
|
37 |
+
txt = grad.Textbox(lines=1, label="Initial Text", placeholder="English Text here")
|
38 |
+
out = grad.Textbox(lines=4, label="Generated Prompts")
|
39 |
+
|
40 |
+
examples = []
|
41 |
+
for x in range(8):
|
42 |
+
examples.append(line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize())
|
43 |
+
|
44 |
+
title = "Stable Diffusion Prompt Generator"
|
45 |
+
description = 'This is a demo of the model series: "MagicPrompt", in this case, aimed at: Stable Diffusion. To use it, simply submit your text or click on one of the examples.<b><br><br>To learn more about the model, go to the link: https://huggingface.co/Gustavosta/MagicPrompt-Stable-Diffusion<br>'
|
46 |
+
article = "<div><center><img src='https://visitor-badge.glitch.me/badge?page_id=_Stable_Diffusion' alt='visitor badge'></center></div>"
|
47 |
+
|
48 |
+
grad.Interface(fn=generate,
|
49 |
+
inputs=txt,
|
50 |
+
outputs=out,
|
51 |
+
examples=examples,
|
52 |
+
title=title,
|
53 |
+
description=description,
|
54 |
+
article=article,
|
55 |
+
allow_flagging='never',
|
56 |
+
cache_examples=False,
|
57 |
+
theme="default").launch(enable_queue=True, debug=True)
|
58 |
+
|
59 |
+
|
ideas.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
transformers[sentencepiece]
|
4 |
+
|