Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from accelerate.utils import write_basic_config
|
2 |
+
from diffusers import DiffusionPipeline
|
3 |
+
import torch
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
|
7 |
+
write_basic_config()
|
8 |
+
|
9 |
+
base = DiffusionPipeline.from_pretrained(
|
10 |
+
"Mahdy225/JAMAL",
|
11 |
+
torch_dtype=torch.float16,
|
12 |
+
use_safetensors=True
|
13 |
+
)
|
14 |
+
base.to("cuda")
|
15 |
+
|
16 |
+
def text2Image(prompt, steps=50, scale=7, Width=1024, Height=1024):
|
17 |
+
image = base(prompt, num_inference_steps=steps, guidance_scale=scale,
|
18 |
+
width=Width, height=Height, cross_attention_kwargs={"scale": 1}).images[0]
|
19 |
+
return image
|
20 |
+
|
21 |
+
ui = gr.Interface(fn=text2Image,
|
22 |
+
inputs=[
|
23 |
+
gr.Textbox(label="Enter Text Prompt"),
|
24 |
+
gr.Slider(minimum=10, maximum=150, value=50, label="Number of Inference Steps"),
|
25 |
+
gr.Slider(minimum=4, maximum=10, value=7, step=0.1, label="Guidance Scale"),
|
26 |
+
gr.Number(label="Image Width", value=1024),
|
27 |
+
gr.Number(label="Image Height"), value=1024],
|
28 |
+
outputs="image",
|
29 |
+
title="JAMAL/چمال: Transforming Words into Reality"
|
30 |
+
)
|
31 |
+
|
32 |
+
# ui.launch(share=True)
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
ui.launch()
|