Commit
·
1684436
1
Parent(s):
4e607e1
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,10 @@ from tqdm import tqdm
|
|
| 19 |
from safetensors.torch import load_file
|
| 20 |
from huggingface_hub import hf_hub_download
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
DESCRIPTION = '''# Latent Consistency Model
|
| 23 |
Distilled from [Dreamshaper v7](https://huggingface.co/Lykon/dreamshaper-7) fine-tune of [Stable Diffusion v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5). [Project page](https://latent-consistency-models.github.io)
|
| 24 |
'''
|
|
@@ -40,6 +44,17 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
| 40 |
seed = random.randint(0, MAX_SEED)
|
| 41 |
return seed
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def generate(
|
| 44 |
prompt: str,
|
| 45 |
seed: int = 0,
|
|
@@ -64,9 +79,9 @@ def generate(
|
|
| 64 |
lcm_origin_steps=50,
|
| 65 |
output_type="pil",
|
| 66 |
).images
|
| 67 |
-
|
| 68 |
print(time.time() - start_time)
|
| 69 |
-
return
|
| 70 |
|
| 71 |
examples = [
|
| 72 |
"portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour, style by Dan Winters, Russell James, Steve McCurry, centered, extremely detailed, Nikon D850, award winning photography",
|
|
|
|
| 19 |
from safetensors.torch import load_file
|
| 20 |
from huggingface_hub import hf_hub_download
|
| 21 |
|
| 22 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 23 |
+
import uuid
|
| 24 |
+
import cv2
|
| 25 |
+
|
| 26 |
DESCRIPTION = '''# Latent Consistency Model
|
| 27 |
Distilled from [Dreamshaper v7](https://huggingface.co/Lykon/dreamshaper-7) fine-tune of [Stable Diffusion v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5). [Project page](https://latent-consistency-models.github.io)
|
| 28 |
'''
|
|
|
|
| 44 |
seed = random.randint(0, MAX_SEED)
|
| 45 |
return seed
|
| 46 |
|
| 47 |
+
def save_image(img):
|
| 48 |
+
unique_name = str(uuid.uuid4()) + '.png'
|
| 49 |
+
img.save(unique_name)
|
| 50 |
+
return unique_name
|
| 51 |
+
|
| 52 |
+
def save_images(image_array):
|
| 53 |
+
paths = []
|
| 54 |
+
with ThreadPoolExecutor() as executor:
|
| 55 |
+
paths = list(executor.map(save_image, image_array))
|
| 56 |
+
return paths
|
| 57 |
+
|
| 58 |
def generate(
|
| 59 |
prompt: str,
|
| 60 |
seed: int = 0,
|
|
|
|
| 79 |
lcm_origin_steps=50,
|
| 80 |
output_type="pil",
|
| 81 |
).images
|
| 82 |
+
paths = save_images(result)
|
| 83 |
print(time.time() - start_time)
|
| 84 |
+
return paths, seed
|
| 85 |
|
| 86 |
examples = [
|
| 87 |
"portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour, style by Dan Winters, Russell James, Steve McCurry, centered, extremely detailed, Nikon D850, award winning photography",
|