Commit
·
d8366c4
1
Parent(s):
9d983b8
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
-
import random
|
3 |
-
import re
|
4 |
import numpy as np
|
5 |
import torch
|
6 |
from PIL import Image
|
7 |
from diffusers import StableDiffusionPipeline
|
8 |
-
from transformers import pipeline, set_seed
|
9 |
-
|
10 |
-
gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2')
|
11 |
-
|
12 |
-
def generate(starting_text):
|
13 |
-
seed = random.randint(100, 1000000)
|
14 |
-
set_seed(seed)
|
15 |
-
|
16 |
-
if starting_text == "":
|
17 |
-
starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize()
|
18 |
-
starting_text: str = re.sub(r"[,:\-–.!;?_]", '', starting_text)
|
19 |
-
|
20 |
-
response = gpt2_pipe(starting_text, max_length=(len(starting_text) + 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 |
-
|
34 |
-
|
35 |
-
txt = gr.Textbox(lines=1, label="Initial Text", placeholder="English Text here")
|
36 |
-
out = gr.Textbox(lines=4, label="Generated Prompts")
|
37 |
-
|
38 |
-
title = "Stable Diffusion Prompt Generator"
|
39 |
-
gr.Interface(fn=generate,
|
40 |
-
inputs=txt,
|
41 |
-
outputs=out,
|
42 |
-
title=title,
|
43 |
-
article='',
|
44 |
-
allow_flagging='never',
|
45 |
-
cache_examples=False,
|
46 |
-
theme="default").launch(enable_queue=True, debug=True)
|
47 |
|
48 |
model_id = "runwayml/stable-diffusion-v1-5"
|
49 |
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
from diffusers import StableDiffusionPipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
model_id = "runwayml/stable-diffusion-v1-5"
|
8 |
|