Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,6 @@ import spaces
|
|
5 |
import gradio as gr
|
6 |
import numpy as np
|
7 |
import torch
|
8 |
-
import tempfile
|
9 |
-
import os
|
10 |
-
import uuid
|
11 |
from PIL import Image
|
12 |
from diffusers import StableDiffusionXLImg2ImgPipeline, StableDiffusionXLPipeline, EDMEulerScheduler, StableDiffusionXLInstructPix2PixPipeline, AutoencoderKL, DPMSolverMultistepScheduler
|
13 |
from huggingface_hub import hf_hub_download, InferenceClient
|
@@ -32,11 +29,6 @@ To optimize image results:
|
|
32 |
- **Increase the number of steps** for enhanced edits.
|
33 |
"""
|
34 |
|
35 |
-
def save_image(img):
|
36 |
-
unique_name = str(uuid.uuid4()) + ".png"
|
37 |
-
img.save(unique_name)
|
38 |
-
return unique_name
|
39 |
-
|
40 |
def set_timesteps_patched(self, num_inference_steps: int, device = None):
|
41 |
self.num_inference_steps = num_inference_steps
|
42 |
|
@@ -58,7 +50,7 @@ pipe_edit = StableDiffusionXLInstructPix2PixPipeline.from_single_file( edit_file
|
|
58 |
pipe_edit.scheduler = EDMEulerScheduler(sigma_min=0.002, sigma_max=120.0, sigma_data=1.0, prediction_type="v_prediction")
|
59 |
pipe_edit.to("cuda")
|
60 |
|
61 |
-
client1 = InferenceClient("
|
62 |
system_instructions1 = "<s>[SYSTEM] Act as Image Prompt Generation expert, Your task is to modify prompt by USER to more better prompt for Image Generation in Stable Diffusion XL. \n Modify the user's prompt to generate a high-quality image by incorporating essential keywords and styles according to prompt if none style is mentioned than assume realistic. The optimized prompt may include keywords according to prompt for resolution (4K, HD, 16:9 aspect ratio, , etc.), image quality (cute, masterpiece, high-quality, vivid colors, intricate details, etc.), and desired art styles (realistic, anime, 3D, logo, futuristic, fantasy, etc.). Ensure the prompt is concise, yet comprehensive and choose keywords wisely, to generate an exceptional image that meets the user's expectations. \n Your task is to reply with final optimized prompt only. If you get big prompt make it concise. and Apply all keyword at last of prompt. Reply with optimized prompt only.[USER]"
|
63 |
|
64 |
def promptifier(prompt):
|
@@ -99,9 +91,8 @@ def king(type ,
|
|
99 |
num_inference_steps=steps,
|
100 |
image=output_image,
|
101 |
generator=generator,
|
102 |
-
).images
|
103 |
-
|
104 |
-
return seed, image_paths
|
105 |
else :
|
106 |
if randomize_seed:
|
107 |
seed = random.randint(0, 999999)
|
@@ -117,7 +108,7 @@ def king(type ,
|
|
117 |
num_inference_steps = int(steps/2.5),
|
118 |
width = width, height = height,
|
119 |
generator = generator,
|
120 |
-
).images
|
121 |
else:
|
122 |
image = pipe_fast( prompt = instruction,
|
123 |
negative_prompt=negative_prompt,
|
@@ -132,9 +123,8 @@ def king(type ,
|
|
132 |
guidance_scale = 7.5,
|
133 |
num_inference_steps= steps,
|
134 |
image=image, generator=generator,
|
135 |
-
).images
|
136 |
-
|
137 |
-
return seed, image_paths
|
138 |
|
139 |
client = InferenceClient()
|
140 |
# Prompt classifier
|
|
|
5 |
import gradio as gr
|
6 |
import numpy as np
|
7 |
import torch
|
|
|
|
|
|
|
8 |
from PIL import Image
|
9 |
from diffusers import StableDiffusionXLImg2ImgPipeline, StableDiffusionXLPipeline, EDMEulerScheduler, StableDiffusionXLInstructPix2PixPipeline, AutoencoderKL, DPMSolverMultistepScheduler
|
10 |
from huggingface_hub import hf_hub_download, InferenceClient
|
|
|
29 |
- **Increase the number of steps** for enhanced edits.
|
30 |
"""
|
31 |
|
|
|
|
|
|
|
|
|
|
|
32 |
def set_timesteps_patched(self, num_inference_steps: int, device = None):
|
33 |
self.num_inference_steps = num_inference_steps
|
34 |
|
|
|
50 |
pipe_edit.scheduler = EDMEulerScheduler(sigma_min=0.002, sigma_max=120.0, sigma_data=1.0, prediction_type="v_prediction")
|
51 |
pipe_edit.to("cuda")
|
52 |
|
53 |
+
client1 = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
54 |
system_instructions1 = "<s>[SYSTEM] Act as Image Prompt Generation expert, Your task is to modify prompt by USER to more better prompt for Image Generation in Stable Diffusion XL. \n Modify the user's prompt to generate a high-quality image by incorporating essential keywords and styles according to prompt if none style is mentioned than assume realistic. The optimized prompt may include keywords according to prompt for resolution (4K, HD, 16:9 aspect ratio, , etc.), image quality (cute, masterpiece, high-quality, vivid colors, intricate details, etc.), and desired art styles (realistic, anime, 3D, logo, futuristic, fantasy, etc.). Ensure the prompt is concise, yet comprehensive and choose keywords wisely, to generate an exceptional image that meets the user's expectations. \n Your task is to reply with final optimized prompt only. If you get big prompt make it concise. and Apply all keyword at last of prompt. Reply with optimized prompt only.[USER]"
|
55 |
|
56 |
def promptifier(prompt):
|
|
|
91 |
num_inference_steps=steps,
|
92 |
image=output_image,
|
93 |
generator=generator,
|
94 |
+
).images[0]
|
95 |
+
return seed, refine
|
|
|
96 |
else :
|
97 |
if randomize_seed:
|
98 |
seed = random.randint(0, 999999)
|
|
|
108 |
num_inference_steps = int(steps/2.5),
|
109 |
width = width, height = height,
|
110 |
generator = generator,
|
111 |
+
).images[0]
|
112 |
else:
|
113 |
image = pipe_fast( prompt = instruction,
|
114 |
negative_prompt=negative_prompt,
|
|
|
123 |
guidance_scale = 7.5,
|
124 |
num_inference_steps= steps,
|
125 |
image=image, generator=generator,
|
126 |
+
).images[0]
|
127 |
+
return seed, refine
|
|
|
128 |
|
129 |
client = InferenceClient()
|
130 |
# Prompt classifier
|