Nymbo commited on
Commit
b5176b4
·
verified ·
1 Parent(s): 764029a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -20
app.py CHANGED
@@ -23,25 +23,24 @@ def flux_krea_generate(
23
  height: int = 1024
24
  ) -> Optional[Image.Image]:
25
  """
26
- Generate high-quality images using the FLUX.1-Krea-dev model from Hugging Face.
27
-
28
- This function creates detailed, ultra-high-quality images based on text prompts using
29
- the advanced FLUX.1-Krea-dev diffusion model. The generated images feature ultra detail,
30
- ultra elaboration, and perfect quality.
31
-
32
  Args:
33
- prompt: Text description of the image to generate. Be detailed and descriptive for best results.
34
- negative_prompt: Text describing what should NOT appear in the image. Helps avoid unwanted elements.
35
- steps: Number of denoising steps (1-100). Higher values generally produce better quality but take longer.
36
- cfg_scale: Classifier-free guidance scale (1-20). Higher values follow the prompt more closely.
37
- sampler: Sampling method to use. Options: "DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM".
38
- seed: Random seed for reproducible results. Use -1 for random seed.
39
- strength: Strength of the generation process (0-1). Higher values give more creative freedom.
40
- width: Width of generated image in pixels (64-1216, must be multiple of 32).
41
- height: Height of generated image in pixels (64-1216, must be multiple of 32).
42
-
43
  Returns:
44
- PIL Image object of the generated image, or None if generation failed.
45
  """
46
  if prompt == "" or prompt is None:
47
  return None
@@ -139,10 +138,29 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
139
 
140
  # Image output area to display the generated image
141
  with gr.Row():
142
- image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
 
143
 
144
- # Bind the button to the flux_krea_generate function with the added width and height inputs
145
- text_button.click(flux_krea_generate, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=image_output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
  # Launch the Gradio app with MCP server enabled
148
  app.launch(show_api=True, share=False, mcp_server=True)
 
23
  height: int = 1024
24
  ) -> Optional[Image.Image]:
25
  """
26
+ Text-to-image generation with FLUX.1-Krea-dev (no input image required).
27
+
28
+ This tool generates a single image from a text prompt using the
29
+ black-forest-labs/FLUX.1-Krea-dev model on Hugging Face Inference.
30
+
 
31
  Args:
32
+ prompt: Text description of the image to generate.
33
+ negative_prompt: What should NOT appear in the image.
34
+ steps: Number of denoising steps (1-100). Higher is slower but can improve quality.
35
+ cfg_scale: Classifier-free guidance scale (1-20). Higher = follow the prompt more closely.
36
+ sampler: Sampling method to use. One of: "DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM".
37
+ seed: Random seed for reproducible results. Use -1 for a random seed per call.
38
+ strength: Generation strength (0-1). Kept for parity; not an input image strength.
39
+ width: Output width in pixels (64-1216, multiple of 32 recommended).
40
+ height: Output height in pixels (64-1216, multiple of 32 recommended).
41
+
42
  Returns:
43
+ A PIL.Image of the generated result. No input image is expected or required.
44
  """
45
  if prompt == "" or prompt is None:
46
  return None
 
138
 
139
  # Image output area to display the generated image
140
  with gr.Row():
141
+ # Output component only; no input image is required by the tool
142
+ image_output = gr.Image(label="Image Output", elem_id="gallery")
143
 
144
+ # Bind the button to the flux_krea_generate function for the UI only
145
+ # Hide this event as an MCP tool to avoid schema confusion (UI wires image output)
146
+ text_button.click(
147
+ flux_krea_generate,
148
+ inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength, width, height],
149
+ outputs=image_output,
150
+ show_api=False,
151
+ api_description=False,
152
+ )
153
+
154
+ # Expose a dedicated MCP/API endpoint with a clear schema (text-to-image only)
155
+ # This avoids clients misinterpreting the UI event as requiring an input image.
156
+ gr.api(
157
+ flux_krea_generate,
158
+ api_name="generate_image",
159
+ api_description=(
160
+ "Generate an image from a text prompt using FLUX.1-Krea-dev. "
161
+ "Inputs are text and numeric parameters only; no input image is required."
162
+ ),
163
+ )
164
 
165
  # Launch the Gradio app with MCP server enabled
166
  app.launch(show_api=True, share=False, mcp_server=True)