Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
# Function to generate an image from a text prompt
|
| 13 |
def generate_image(prompt):
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 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 |
-
#
|
| 30 |
-
|
| 31 |
-
fn=generate_image,
|
| 32 |
-
inputs=gr.Textbox(
|
| 33 |
-
outputs="
|
| 34 |
-
title="
|
| 35 |
-
description="Generate images
|
| 36 |
)
|
| 37 |
|
| 38 |
-
# Launch the app
|
| 39 |
-
|
|
|
|
| 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()
|