Spaces:
Runtime error
Runtime error
RamAnanth1
commited on
Commit
•
891954c
1
Parent(s):
d79edb1
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
pipe = pipeline('text-generation', model='daspartho/prompt-extend')
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
input_prompt = gr.Text(label="Enter the initial prompt")
|
10 |
sd2_output = gr.Text(label="Extended prompt suitable for Stable Diffusion 2")
|
11 |
|
|
|
12 |
gr.Markdown(""" ## Prompt Extender for SD 2 """)
|
13 |
gr.HTML('''<p style="margin-bottom: 10px; font-size: 94%">
|
14 |
Enter a main initial idea for a prompt, and the model will generate a prompt suitable for Stable Diffusion 2</p>''')
|
15 |
|
16 |
-
demo = gr.Interface(fn=
|
17 |
demo.queue(max_size=10,concurrency_count=20)
|
18 |
demo.launch(enable_queue=True)
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import os
|
4 |
|
5 |
pipe = pipeline('text-generation', model='daspartho/prompt-extend')
|
6 |
|
7 |
+
stable_diffusion = gr.Blocks.load(name="spaces/runwayml/stable-diffusion-v1-5")
|
8 |
+
clip_interrogator_2 = gr.Blocks.load(name="spaces/fffiloni/CLIP-Interrogator-2")
|
9 |
|
10 |
+
def get_images(prompt):
|
11 |
+
gallery_dir = stable_diffusion(prompt, fn_index=2)
|
12 |
+
img_results = [os.path.join(gallery_dir, img) for img in os.listdir(gallery_dir)]
|
13 |
+
return img_results[0]
|
14 |
+
|
15 |
+
def get_new_prompt(img, mode):
|
16 |
+
interrogate = clip_interrogator_2(img, mode, 12, api_name="clipi2")
|
17 |
+
return interrogate
|
18 |
+
|
19 |
+
def infer(input):
|
20 |
+
prompt = pipe(input+',', num_return_sequences=1)[0]["generated_text"]
|
21 |
+
img = get_images(prompt)
|
22 |
+
result = get_new_prompt(img, 'fast')
|
23 |
+
return result[0]
|
24 |
+
|
25 |
input_prompt = gr.Text(label="Enter the initial prompt")
|
26 |
sd2_output = gr.Text(label="Extended prompt suitable for Stable Diffusion 2")
|
27 |
|
28 |
+
|
29 |
gr.Markdown(""" ## Prompt Extender for SD 2 """)
|
30 |
gr.HTML('''<p style="margin-bottom: 10px; font-size: 94%">
|
31 |
Enter a main initial idea for a prompt, and the model will generate a prompt suitable for Stable Diffusion 2</p>''')
|
32 |
|
33 |
+
demo = gr.Interface(fn=infer, inputs=input_prompt, outputs=sd2_output)
|
34 |
demo.queue(max_size=10,concurrency_count=20)
|
35 |
demo.launch(enable_queue=True)
|