kadirnar commited on
Commit
8166181
·
verified ·
1 Parent(s): df90040

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ from diffusers import AuraFlowPipeline
3
+ import torch
4
+ import gradio as gr
5
+
6
+ def initialize_auraflow_pipeline():
7
+ """Initialize and return the AuraFlowPipeline."""
8
+ pipeline = AuraFlowPipeline.from_pretrained(
9
+ "fal/AuraFlow-v0.3",
10
+ torch_dtype=torch.float16,
11
+ variant="fp16",
12
+ ).to("cuda")
13
+ return pipeline
14
+
15
+ def generate_image(pipeline, prompt, width, height, num_inference_steps, seed, guidance_scale):
16
+ """Generate an image using the AuraFlowPipeline."""
17
+ generator = torch.Generator().manual_seed(seed)
18
+
19
+ image = pipeline(
20
+ prompt=prompt,
21
+ width=width,
22
+ height=height,
23
+ num_inference_steps=num_inference_steps,
24
+ generator=generator,
25
+ guidance_scale=guidance_scale,
26
+ ).images[0]
27
+
28
+ return image
29
+
30
+ # Initialize the pipeline once
31
+ auraflow_pipeline = initialize_auraflow_pipeline()
32
+
33
+ # Gradio interface
34
+ def gradio_generate_image(prompt, width, height, num_inference_steps, seed, guidance_scale):
35
+ return generate_image(auraflow_pipeline, prompt, width, height, num_inference_steps, seed, guidance_scale)
36
+
37
+ # Create Gradio Blocks
38
+ with gr.Blocks() as demo:
39
+ gr.Markdown("# AuraFlow Image Generation")
40
+
41
+ with gr.Row():
42
+ with gr.Column():
43
+ prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your image prompt here...")
44
+ width_input = gr.Slider(minimum=512, maximum=2048, step=64, value=1536, label="Width")
45
+ height_input = gr.Slider(minimum=512, maximum=2048, step=64, value=768, label="Height")
46
+ steps_input = gr.Slider(minimum=10, maximum=100, step=1, value=50, label="Number of Inference Steps")
47
+ seed_input = gr.Number(label="Seed", value=1)
48
+ guidance_input = gr.Slider(minimum=1, maximum=10, step=0.1, value=3.5, label="Guidance Scale")
49
+ generate_btn = gr.Button("Generate Image")
50
+
51
+ with gr.Column():
52
+ image_output = gr.Image(label="Generated Image")
53
+
54
+ generate_btn.click(
55
+ fn=gradio_generate_image,
56
+ inputs=[prompt_input, width_input, height_input, steps_input, seed_input, guidance_input],
57
+ outputs=image_output
58
+ )
59
+
60
+ # Launch the Gradio interface
61
+ demo.launch()