raahinaez commited on
Commit
f7fcde9
·
verified ·
1 Parent(s): 9a34b04

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import FluxPipeline
4
+
5
+ # Load model once
6
+ pipe = FluxPipeline.from_pretrained(
7
+ "black-forest-labs/FLUX.1-dev",
8
+ torch_dtype=torch.bfloat16
9
+ )
10
+ pipe.enable_model_cpu_offload() # optional, saves VRAM
11
+
12
+
13
+ def generate_image(text):
14
+ if not text.strip():
15
+ return None
16
+
17
+ prompt = (
18
+ "High resolution A4 document page, clean printed text, "
19
+ "sharp readable black fonts, no distortions. Content:\n" + text
20
+ )
21
+
22
+ image = pipe(
23
+ prompt,
24
+ height=1024,
25
+ width=1024,
26
+ guidance_scale=3.0,
27
+ num_inference_steps=40,
28
+ max_sequence_length=512,
29
+ generator=torch.Generator('cpu').manual_seed(42)
30
+ ).images[0]
31
+
32
+ return image
33
+
34
+
35
+ # Gradio UI
36
+ demo = gr.Interface(
37
+ fn=generate_image,
38
+ inputs=gr.Textbox(lines=8, label="Enter Text Here"),
39
+ outputs=gr.Image(type="pil", label="Generated Image"),
40
+ title="Text ➝ Image Generator (FLUX.1-dev)"
41
+ )
42
+
43
+ demo.launch()