Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from PIL import Image
|
3 |
+
import gradio as gr
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
|
6 |
+
from src_inference.pipeline import FluxPipeline
|
7 |
+
from src_inference.lora_helper import set_single_lora, clear_cache
|
8 |
+
|
9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
+
print("Running on:", device)
|
11 |
+
|
12 |
+
# Download and load model
|
13 |
+
base_path = hf_hub_download(repo_id="showlab/OmniConsistency", filename="OmniConsistency.safetensors", local_dir="./Model")
|
14 |
+
|
15 |
+
pipe = FluxPipeline.from_pretrained(
|
16 |
+
"black-forest-labs/FLUX.1-dev",
|
17 |
+
torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32
|
18 |
+
).to(device)
|
19 |
+
|
20 |
+
set_single_lora(pipe.transformer, base_path, lora_weights=[1], cond_size=512)
|
21 |
+
|
22 |
+
def generate_manga(input_image, prompt):
|
23 |
+
spatial_image = [input_image.convert("RGB")]
|
24 |
+
image = pipe(
|
25 |
+
prompt,
|
26 |
+
height=1024,
|
27 |
+
width=1024,
|
28 |
+
guidance_scale=3.5,
|
29 |
+
num_inference_steps=25,
|
30 |
+
max_sequence_length=512,
|
31 |
+
spatial_images=spatial_image,
|
32 |
+
subject_images=[],
|
33 |
+
cond_size=512,
|
34 |
+
).images[0]
|
35 |
+
|
36 |
+
clear_cache(pipe.transformer)
|
37 |
+
return image
|
38 |
+
|
39 |
+
demo = gr.Interface(
|
40 |
+
fn=generate_manga,
|
41 |
+
inputs=[
|
42 |
+
gr.Image(type="pil", label="Input Character"),
|
43 |
+
gr.Textbox(label="Scene Prompt")
|
44 |
+
],
|
45 |
+
outputs=gr.Image(label="Generated Manga Frame"),
|
46 |
+
title="OmniConsistency Manga Generator"
|
47 |
+
)
|
48 |
+
|
49 |
+
demo.launch()
|