Spaces:
Sleeping
Sleeping
tokeron
commited on
Commit
•
2ec2ebd
1
Parent(s):
2d58fea
init
Browse files- app.py +77 -0
- diffusion_lens.py +8 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import sys
|
3 |
+
# sys.path.append("LaVi-Bridge/test")
|
4 |
+
# from llama2_unet_diffusion_lens import call_diffusion_lens
|
5 |
+
from diffusion_lens import get_images
|
6 |
+
|
7 |
+
import os
|
8 |
+
import subprocess
|
9 |
+
|
10 |
+
def prepare_images(images):
|
11 |
+
return images
|
12 |
+
|
13 |
+
|
14 |
+
# def call_diffusion_lens(prompt):
|
15 |
+
# # os.chdir('LaVi-Bridge/test')
|
16 |
+
# command = f"python -u llama2_unet.py --ckpt_dir 'LaVi-Bridge/llama2_unet' --output_dir 'output' --llama2_dir 'meta-llama/Llama-2-7b-hf' --prompt '{prompt}'"
|
17 |
+
# subprocess.run(command, shell=True)
|
18 |
+
# return 'output'
|
19 |
+
|
20 |
+
|
21 |
+
def get_prompt(prompt):
|
22 |
+
print('prompt:', prompt)
|
23 |
+
print('calling diffusion lens')
|
24 |
+
|
25 |
+
# parser.add_argument("--ckpt_dir", type=str, default="")
|
26 |
+
# parser.add_argument("--output_dir", type=str, default="")
|
27 |
+
# parser.add_argument("--llama2_dir", type=str, default="")
|
28 |
+
# parser.add_argument("--prompts_path", type=str, default="inputs/in.txt")
|
29 |
+
# parser.add_argument("--use_chat", action="store_true")
|
30 |
+
# parser.add_argument("--generate_text", action="store_true")
|
31 |
+
# parser.add_argument("--dont_use_lora", action="store_true")
|
32 |
+
# parser.add_argument("--is_gradio", action="store_true")
|
33 |
+
|
34 |
+
# args = {
|
35 |
+
# 'ckpt_dir': 'LaVi-Bridge/LaVi-Bridge/llama2_unet',
|
36 |
+
# 'output_dir': 'output',
|
37 |
+
# 'llama2_dir': 'meta-llama/Llama-2-7b-hf',
|
38 |
+
# 'prompt': prompt,
|
39 |
+
# 'use_chat': False,
|
40 |
+
# 'generate_text': False,
|
41 |
+
# 'dont_use_lora': False,
|
42 |
+
# 'is_gradio': True,
|
43 |
+
# 'prompts_path': None
|
44 |
+
# }
|
45 |
+
# images = call_diffusion_lens(args, prompt)
|
46 |
+
# print('done calling diffusion lens')
|
47 |
+
# print('number of images:', len(images))
|
48 |
+
# images = prepare_images(images)
|
49 |
+
# print('done preparing images')
|
50 |
+
image = get_images(prompt)
|
51 |
+
return image
|
52 |
+
|
53 |
+
if __name__ == '__main__':
|
54 |
+
print('starting')
|
55 |
+
get_prompt("A photo of a cat")
|
56 |
+
print('done')
|
57 |
+
|
58 |
+
|
59 |
+
# iface = gr.Interface(fn=get_prompt, inputs="text", outputs="image", title="Diffusion Lens")
|
60 |
+
# iface.launch()
|
61 |
+
|
62 |
+
import gradio as gr
|
63 |
+
|
64 |
+
def display_images(images):
|
65 |
+
# Prepare images for display
|
66 |
+
return [gr.Image(image) for image in images]
|
67 |
+
|
68 |
+
if __name__ == '__main__':
|
69 |
+
with gr.Blocks() as demo:
|
70 |
+
gallery = gr.Gallery(
|
71 |
+
label="Generated images", show_label=False, elem_id="gallery",
|
72 |
+
columns=[1], rows=[1], object_fit="contain", height="auto")
|
73 |
+
btn = gr.Button("Generate images", scale=0)
|
74 |
+
|
75 |
+
btn.click(get_prompt, 'text', gallery)
|
76 |
+
|
77 |
+
demo.launch()
|
diffusion_lens.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
|
2 |
+
|
3 |
+
pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
|
4 |
+
pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)
|
5 |
+
|
6 |
+
def get_images(prompt, skip_layers=0):
|
7 |
+
images = pipeline(prompt, skip_layers=skip_layers, num_images_per_prompt=1)
|
8 |
+
return images
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
diffusers
|
3 |
+
gradio
|