Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,9 @@ from diffusers import StableDiffusionXLImg2ImgPipeline, StableDiffusionXLPipelin
|
|
10 |
from huggingface_hub import hf_hub_download, InferenceClient
|
11 |
|
12 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
|
|
|
|
|
|
13 |
|
14 |
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", vae=vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
15 |
refiner.to("cuda")
|
@@ -47,15 +50,13 @@ pipe_edit = StableDiffusionXLInstructPix2PixPipeline.from_single_file( edit_file
|
|
47 |
pipe_edit.scheduler = EDMEulerScheduler(sigma_min=0.002, sigma_max=120.0, sigma_data=1.0, prediction_type="v_prediction")
|
48 |
pipe_edit.to("cuda")
|
49 |
|
50 |
-
client1 = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
|
51 |
-
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. Reply with optimized prompt only.[USER]"
|
52 |
-
|
53 |
def promptifier(prompt):
|
|
|
|
|
54 |
formatted_prompt = f"{system_instructions1} {prompt} [OPTIMIZED_PROMPT]"
|
55 |
-
stream = client1.text_generation(formatted_prompt, max_new_tokens=
|
56 |
return "".join([response.token.text for response in stream if response.token.text != "</s>"])
|
57 |
|
58 |
-
client_image = InferenceClient("stabilityai/stable-diffusion-3-medium-diffusers")
|
59 |
# Generator
|
60 |
@spaces.GPU(duration=60, queue=False)
|
61 |
def king(type ,
|
@@ -108,12 +109,15 @@ def king(type ,
|
|
108 |
generator = generator,
|
109 |
).images[0]
|
110 |
else:
|
111 |
-
image =
|
112 |
negative_prompt=negative_prompt,
|
113 |
guidance_scale = guidance_scale,
|
114 |
num_inference_steps = steps,
|
115 |
-
width = width, height = height
|
116 |
-
|
|
|
|
|
|
|
117 |
negative_prompt = negative_prompt,
|
118 |
guidance_scale = 7.5,
|
119 |
num_inference_steps= steps,
|
|
|
10 |
from huggingface_hub import hf_hub_download, InferenceClient
|
11 |
|
12 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
13 |
+
pipe = StableDiffusionXLPipeline.from_pretrained("SG161222/RealVisXL_V4.0", torch_dtype=torch.float16, vae=vae)
|
14 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True, algorithm_type="sde-dpmsolver++")
|
15 |
+
pipe.to("cuda")
|
16 |
|
17 |
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", vae=vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
18 |
refiner.to("cuda")
|
|
|
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 |
def promptifier(prompt):
|
54 |
+
client1 = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
|
55 |
+
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]"
|
56 |
formatted_prompt = f"{system_instructions1} {prompt} [OPTIMIZED_PROMPT]"
|
57 |
+
stream = client1.text_generation(formatted_prompt, max_new_tokens=80, stream=True, details=True, return_full_text=False)
|
58 |
return "".join([response.token.text for response in stream if response.token.text != "</s>"])
|
59 |
|
|
|
60 |
# Generator
|
61 |
@spaces.GPU(duration=60, queue=False)
|
62 |
def king(type ,
|
|
|
109 |
generator = generator,
|
110 |
).images[0]
|
111 |
else:
|
112 |
+
image = pipe_fast( prompt = instruction,
|
113 |
negative_prompt=negative_prompt,
|
114 |
guidance_scale = guidance_scale,
|
115 |
num_inference_steps = steps,
|
116 |
+
width = width, height = height,
|
117 |
+
generator = generator, output_type="latent",
|
118 |
+
).images
|
119 |
+
|
120 |
+
refine = refiner( prompt=instruction,
|
121 |
negative_prompt = negative_prompt,
|
122 |
guidance_scale = 7.5,
|
123 |
num_inference_steps= steps,
|