My-AI-Projects commited on
Commit
3b42df3
Β·
verified Β·
1 Parent(s): 98959a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -24
app.py CHANGED
@@ -1,31 +1,24 @@
1
- import torch
2
- from diffusers import FluxPipeline
3
  import gradio as gr
 
 
4
 
5
- # Initialize the model
6
- pipe = FluxPipeline.from_pretrained("Shakker-Labs/AWPortrait-FL", torch_dtype=torch.bfloat16)
7
- pipe.to("cuda")
8
 
 
9
  def generate_image(prompt):
10
- # Generate the image
11
- image = pipe(prompt,
12
- num_inference_steps=24,
13
- guidance_scale=3.5,
14
- width=768, height=1024,
15
- ).images[0]
16
- # Save the image
17
- image_path = "generated_image.png"
18
- image.save(image_path)
19
- return image_path
20
 
21
- # Define the Gradio interface
22
- interface = gr.Interface(
23
- fn=generate_image,
24
- inputs=gr.Textbox(label="Prompt", placeholder="Enter your prompt here..."),
25
- outputs=gr.Image(type="file", label="Generated Image"),
26
- title="Image Generator",
27
- description="Generate images based on the given prompt using the FluxPipeline model."
28
  )
29
 
30
- # Launch the Gradio app
31
- interface.launch()
 
 
 
1
  import gradio as gr
2
+ from diffusers import DiffusionPipeline
3
+ import torch
4
 
5
+ # Load the Kwai-Kolors diffusion model
6
+ pipeline = DiffusionPipeline.from_pretrained("Kwai-Kolors/Kolors").to("cuda" if torch.cuda.is_available() else "cpu")
 
7
 
8
+ # Function to generate image from prompt
9
  def generate_image(prompt):
10
+ # Use the pipeline to generate an image from the text prompt
11
+ image = pipeline(prompt).images[0]
12
+ return image
 
 
 
 
 
 
 
13
 
14
+ # Create Gradio interface
15
+ iface = gr.Interface(
16
+ fn=generate_image, # Function that generates the image
17
+ inputs=gr.Textbox(lines=2, placeholder="Enter your prompt"), # Textbox input for the prompt
18
+ outputs="image", # Output is an image
19
+ title="Kwai-Kolors Image Generator",
20
+ description="Generate images from text prompts using the Kwai-Kolors diffusion model."
21
  )
22
 
23
+ # Launch the app
24
+ iface.launch()