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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -32
app.py CHANGED
@@ -1,39 +1,31 @@
 
 
1
  import gradio as gr
2
- from transformers import DalleBartProcessor, FlaxDalleBartForConditionalGeneration
3
- from PIL import Image
4
- import numpy as np
5
- import jax
6
- import jax.numpy as jnp
7
 
8
- # Load the DALL-E Mega model and processor
9
- processor = DalleBartProcessor.from_pretrained("dalle-mini/dalle-mega")
10
- model = FlaxDalleBartForConditionalGeneration.from_pretrained("dalle-mini/dalle-mega")
11
 
12
- # Function to generate an image from a text prompt
13
  def generate_image(prompt):
14
- # Process the prompt
15
- inputs = processor([prompt], return_tensors="jax", padding="max_length", truncation=True, max_length=64)
16
-
17
- # Generate the images
18
- outputs = model.generate(**inputs, do_sample=True, num_beams=4, num_return_sequences=1)
19
-
20
- # Decode the images and convert them to displayable format
21
- images = model.decode(outputs.sequences)
22
- images = jax.device_get(images)
23
-
24
- # Convert to a PIL image
25
- pil_img = Image.fromarray(np.asarray(images[0]).astype(np.uint8))
26
-
27
- return pil_img
28
 
29
- # Create Gradio interface
30
- iface = gr.Interface(
31
- fn=generate_image, # Function to generate the image
32
- inputs=gr.Textbox(lines=2, placeholder="Enter your text prompt"), # Input textbox for the prompt
33
- outputs="image", # Output as an image
34
- title="DALL-E Mini/Mega Image Generator",
35
- description="Generate images from text prompts using the DALL-E Mega model."
36
  )
37
 
38
- # Launch the app
39
- iface.launch()
 
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()