Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers import BriaPipeline
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
MODEL_ID = "briaai/BRIA-3.2"
|
| 8 |
+
pipe = BriaPipeline.from_pretrained(MODEL_ID, torch_dtype=torch.bfloat16)
|
| 9 |
+
pipe.to("cuda")
|
| 10 |
+
|
| 11 |
+
@spaces.GPU(duration=1500)
|
| 12 |
+
def compile_transformer():
|
| 13 |
+
with spaces.aoti_capture(pipe.transformer) as call:
|
| 14 |
+
pipe("arbitrary example prompt")
|
| 15 |
+
|
| 16 |
+
exported = torch.export.export(
|
| 17 |
+
pipe.transformer,
|
| 18 |
+
args=call.args,
|
| 19 |
+
kwargs=call.kwargs,
|
| 20 |
+
)
|
| 21 |
+
return spaces.aoti_compile(exported)
|
| 22 |
+
|
| 23 |
+
compiled_transformer = compile_transformer()
|
| 24 |
+
spaces.aoti_apply(compiled_transformer, pipe.transformer)
|
| 25 |
+
|
| 26 |
+
@spaces.GPU(duration=60)
|
| 27 |
+
def generate_image(prompt, seed=0):
|
| 28 |
+
torch.manual_seed(seed)
|
| 29 |
+
image = pipe(prompt).images[0]
|
| 30 |
+
return image
|
| 31 |
+
|
| 32 |
+
with gr.Blocks() as demo:
|
| 33 |
+
gr.Markdown("# BRIA-3.2 Text-to-Image Generator")
|
| 34 |
+
gr.Markdown("Generate images from text prompts using the BRIA-3.2 model.")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
prompt = gr.Textbox(
|
| 38 |
+
label="Prompt",
|
| 39 |
+
value="a cat sitting on a chair",
|
| 40 |
+
interactive=True
|
| 41 |
+
)
|
| 42 |
+
seed = gr.Number(
|
| 43 |
+
label="Seed (0 for random)",
|
| 44 |
+
value=0,
|
| 45 |
+
precision=0
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
generate_btn = gr.Button("Generate Image")
|
| 49 |
+
output = gr.Image(label="Generated Image", type="pil")
|
| 50 |
+
|
| 51 |
+
generate_btn.click(
|
| 52 |
+
fn=generate_image,
|
| 53 |
+
inputs=[prompt, seed],
|
| 54 |
+
outputs=output
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
gr.Examples(
|
| 58 |
+
examples=[
|
| 59 |
+
["a futuristic cityscape at sunset"],
|
| 60 |
+
["a forest with glowing mushrooms"],
|
| 61 |
+
["a steampunk robot drinking tea"],
|
| 62 |
+
["an astronaut riding a horse on mars"]
|
| 63 |
+
],
|
| 64 |
+
inputs=[prompt],
|
| 65 |
+
outputs=output,
|
| 66 |
+
fn=generate_image,
|
| 67 |
+
cache_examples="lazy"
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
demo.launch()
|