KingNish commited on
Commit
9ceccb1
1 Parent(s): 33f283d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -8
app.py CHANGED
@@ -10,9 +10,6 @@ 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
- 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")
@@ -51,11 +48,11 @@ pipe_edit.scheduler = EDMEulerScheduler(sigma_min=0.002, sigma_max=120.0, sigma_
51
  pipe_edit.to("cuda")
52
 
53
  client1 = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
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):
57
  formatted_prompt = f"{system_instructions1} {prompt} [OPTIMIZED_PROMPT]"
58
- stream = client1.text_generation(formatted_prompt, max_new_tokens=80, stream=True, details=True, return_full_text=False)
59
  return "".join([response.token.text for response in stream if response.token.text != "</s>"])
60
 
61
  client_image = InferenceClient("stabilityai/stable-diffusion-3-medium-diffusers")
@@ -115,9 +112,7 @@ def king(type ,
115
  negative_prompt=negative_prompt,
116
  guidance_scale = guidance_scale,
117
  num_inference_steps = steps,
118
- width = width, height = height
119
- )
120
-
121
  refine = refiner( prompt=f"{instruction}, 4k, hd, high quality, masterpiece",
122
  negative_prompt = negative_prompt,
123
  guidance_scale = 7.5,
 
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")
 
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=120, stream=True, details=True, return_full_text=False)
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")
 
112
  negative_prompt=negative_prompt,
113
  guidance_scale = guidance_scale,
114
  num_inference_steps = steps,
115
+ width = width, height = height )
 
 
116
  refine = refiner( prompt=f"{instruction}, 4k, hd, high quality, masterpiece",
117
  negative_prompt = negative_prompt,
118
  guidance_scale = 7.5,