Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -713,51 +713,52 @@ def generate_map(location_names):
|
|
| 713 |
# return image_1, image_2, image_3
|
| 714 |
|
| 715 |
|
| 716 |
-
import gradio as gr
|
| 717 |
import torch
|
| 718 |
-
from diffusers import
|
| 719 |
-
import
|
|
|
|
|
|
|
| 720 |
|
| 721 |
-
#
|
| 722 |
-
|
|
|
|
| 723 |
|
| 724 |
-
#
|
| 725 |
-
|
| 726 |
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
return pipe
|
| 738 |
-
|
| 739 |
-
# Function to generate image using Flux bot on the specified device
|
| 740 |
-
def generate_image_flux(prompt):
|
| 741 |
-
pipe = initialize_flux_bot()
|
| 742 |
image = pipe(
|
| 743 |
-
prompt,
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
generator=
|
|
|
|
| 748 |
).images[0]
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
# Hardcoded prompts for the images
|
| 752 |
-
hardcoded_prompt_1 = "A high quality cinematic image for Toyota Truck in Birmingham skyline shot in the style of Michael Mann"
|
| 753 |
-
hardcoded_prompt_2 = "A high quality cinematic image for Alabama Quarterback close up emotional shot in the style of Michael Mann"
|
| 754 |
-
hardcoded_prompt_3 = "A high quality cinematic image for Taylor Swift concert in Birmingham skyline style of Michael Mann"
|
| 755 |
|
| 756 |
-
#
|
| 757 |
def update_images():
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 761 |
return image_1, image_2, image_3
|
| 762 |
|
| 763 |
|
|
@@ -1505,7 +1506,7 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
|
| 1505 |
|
| 1506 |
with gr.Column():
|
| 1507 |
|
| 1508 |
-
# Display images
|
| 1509 |
image_output_1 = gr.Image(value=generate_image_flux(hardcoded_prompt_1), width=400, height=400)
|
| 1510 |
image_output_2 = gr.Image(value=generate_image_flux(hardcoded_prompt_2), width=400, height=400)
|
| 1511 |
image_output_3 = gr.Image(value=generate_image_flux(hardcoded_prompt_3), width=400, height=400)
|
|
|
|
| 713 |
# return image_1, image_2, image_3
|
| 714 |
|
| 715 |
|
|
|
|
| 716 |
import torch
|
| 717 |
+
from diffusers import DiffusionPipeline
|
| 718 |
+
import numpy as np
|
| 719 |
+
import random
|
| 720 |
+
import gradio as gr
|
| 721 |
|
| 722 |
+
# Constants for device and dtype
|
| 723 |
+
dtype = torch.bfloat16
|
| 724 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 725 |
|
| 726 |
+
# Load the Flux pipeline model
|
| 727 |
+
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device)
|
| 728 |
|
| 729 |
+
MAX_SEED = np.iinfo(np.int32).max
|
| 730 |
+
MAX_IMAGE_SIZE = 2048
|
| 731 |
+
|
| 732 |
+
# Function for inference using the Flux pipeline
|
| 733 |
+
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4):
|
| 734 |
+
if randomize_seed:
|
| 735 |
+
seed = random.randint(0, MAX_SEED)
|
| 736 |
+
generator = torch.Generator(device).manual_seed(seed)
|
| 737 |
+
|
| 738 |
+
# Generate the image using the pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 739 |
image = pipe(
|
| 740 |
+
prompt=prompt,
|
| 741 |
+
width=width,
|
| 742 |
+
height=height,
|
| 743 |
+
num_inference_steps=num_inference_steps,
|
| 744 |
+
generator=generator,
|
| 745 |
+
guidance_scale=0.0
|
| 746 |
).images[0]
|
| 747 |
+
|
| 748 |
+
return image, seed
|
|
|
|
|
|
|
|
|
|
|
|
|
| 749 |
|
| 750 |
+
# Existing image generation function, updated to use the new Flux pipeline
|
| 751 |
def update_images():
|
| 752 |
+
# Hardcoded prompts for generating images
|
| 753 |
+
hardcoded_prompt_1 = "A high quality cinematic image for Toyota Truck in Birmingham skyline shot in the style of Michael Mann"
|
| 754 |
+
hardcoded_prompt_2 = "A high quality cinematic image for Alabama Quarterback close up emotional shot in the style of Michael Mann"
|
| 755 |
+
hardcoded_prompt_3 = "A high quality cinematic image for Taylor Swift concert in Birmingham skyline style of Michael Mann"
|
| 756 |
+
|
| 757 |
+
# Use the Flux pipeline to generate images based on hardcoded prompts
|
| 758 |
+
image_1, _ = infer(hardcoded_prompt_1)
|
| 759 |
+
image_2, _ = infer(hardcoded_prompt_2)
|
| 760 |
+
image_3, _ = infer(hardcoded_prompt_3)
|
| 761 |
+
|
| 762 |
return image_1, image_2, image_3
|
| 763 |
|
| 764 |
|
|
|
|
| 1506 |
|
| 1507 |
with gr.Column():
|
| 1508 |
|
| 1509 |
+
# Display generated images
|
| 1510 |
image_output_1 = gr.Image(value=generate_image_flux(hardcoded_prompt_1), width=400, height=400)
|
| 1511 |
image_output_2 = gr.Image(value=generate_image_flux(hardcoded_prompt_2), width=400, height=400)
|
| 1512 |
image_output_3 = gr.Image(value=generate_image_flux(hardcoded_prompt_3), width=400, height=400)
|