Spaces:
Runtime error
Runtime error
Gustavosta
commited on
Commit
β’
505d57d
1
Parent(s):
f8f5184
Update generate function
Browse files
app.py
CHANGED
@@ -8,30 +8,26 @@ with open("ideas.txt", "r") as f:
|
|
8 |
|
9 |
|
10 |
def generate(starting_text):
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
resp
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
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")
|
@@ -42,8 +38,7 @@ 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.<
|
46 |
-
article = ""
|
47 |
|
48 |
grad.Interface(fn=generate,
|
49 |
inputs=txt,
|
@@ -51,7 +46,7 @@ grad.Interface(fn=generate,
|
|
51 |
examples=examples,
|
52 |
title=title,
|
53 |
description=description,
|
54 |
-
article=
|
55 |
allow_flagging='never',
|
56 |
cache_examples=False,
|
57 |
theme="default").launch(enable_queue=True, debug=True)
|
|
|
8 |
|
9 |
|
10 |
def generate(starting_text):
|
11 |
+
seed = random.randint(100, 1000000)
|
12 |
+
set_seed(seed)
|
13 |
+
|
14 |
+
if starting_text == "":
|
15 |
+
starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize()
|
16 |
+
starting_text: str = re.sub(r"[,:\-β.!;?_]", '', starting_text)
|
17 |
+
|
18 |
+
response = gpt2_pipe(starting_text, max_length=(len(starting_text) + random.randint(60, 90)), num_return_sequences=4)
|
19 |
+
response_list = []
|
20 |
+
for x in response:
|
21 |
+
resp = x['generated_text'].strip()
|
22 |
+
if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "β")) is False:
|
23 |
+
response_list.append(resp+'\n')
|
24 |
+
|
25 |
+
response_end = "\n".join(response_list)
|
26 |
+
response_end = re.sub('[^ ]+\.[^ ]+','', response_end)
|
27 |
+
response_end = response_end.replace("<", "").replace(">", "")
|
28 |
+
|
29 |
+
if response_end != "":
|
30 |
+
return response_end
|
|
|
|
|
|
|
|
|
31 |
|
32 |
|
33 |
txt = grad.Textbox(lines=1, label="Initial Text", placeholder="English Text here")
|
|
|
38 |
examples.append(line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize())
|
39 |
|
40 |
title = "Stable Diffusion Prompt Generator"
|
41 |
+
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.<br><br>To learn more about the model, [click here]{https://huggingface.co/Gustavosta/MagicPrompt-Stable-Diffusion}.<br>'
|
|
|
42 |
|
43 |
grad.Interface(fn=generate,
|
44 |
inputs=txt,
|
|
|
46 |
examples=examples,
|
47 |
title=title,
|
48 |
description=description,
|
49 |
+
article='',
|
50 |
allow_flagging='never',
|
51 |
cache_examples=False,
|
52 |
theme="default").launch(enable_queue=True, debug=True)
|