KingNish commited on
Commit
52d72c6
1 Parent(s): a88ad2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -50,12 +50,13 @@ pipe_edit = StableDiffusionXLInstructPix2PixPipeline.from_single_file( edit_file
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)
@@ -193,7 +194,7 @@ examples=[
193
  ]
194
 
195
  with gr.Blocks(css=css) as demo:
196
- gr.Markdown("# Image Generator Pro")
197
  with gr.Row():
198
  instruction = gr.Textbox(lines=1, label="Instruction", interactive=True)
199
  generate_button = gr.Button("Run", scale=0)
@@ -220,13 +221,7 @@ with gr.Blocks(css=css) as demo:
220
  width = gr.Slider( label="Width", minimum=256, maximum=2048, step=64, value=1024)
221
  height = gr.Slider( label="Height", minimum=256, maximum=2048, step=64, value=1024)
222
  with gr.Row():
223
- randomize_seed = gr.Radio(
224
- ["Fix Seed", "Randomize Seed"],
225
- value="Randomize Seed",
226
- type="index",
227
- show_label=False,
228
- interactive=True,
229
- )
230
  seed = gr.Number(value=2404, step=1, label="Seed", interactive=True)
231
 
232
  gr.Examples(
 
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("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=100)
59
+ return stream
60
 
61
  # Generator
62
  @spaces.GPU(duration=60, queue=False)
 
194
  ]
195
 
196
  with gr.Blocks(css=css) as demo:
197
+ gr.Markdown("# Image Generaation , Image Editing \n ### Note: First image generation takes time")
198
  with gr.Row():
199
  instruction = gr.Textbox(lines=1, label="Instruction", interactive=True)
200
  generate_button = gr.Button("Run", scale=0)
 
221
  width = gr.Slider( label="Width", minimum=256, maximum=2048, step=64, value=1024)
222
  height = gr.Slider( label="Height", minimum=256, maximum=2048, step=64, value=1024)
223
  with gr.Row():
224
+ randomize_seed = gr.Checkbox(label="Randomize Seed", value = True, interactive=True )
 
 
 
 
 
 
225
  seed = gr.Number(value=2404, step=1, label="Seed", interactive=True)
226
 
227
  gr.Examples(