nx210 commited on
Commit
a02cb3a
·
verified ·
1 Parent(s): 43bfe01

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusionInstructPix2PixPipeline
4
+ from PIL import Image
5
+
6
+ # মডেল লোড করা (ফ্রি সিপইউ এর জন্য অপ্টিমাইজড)
7
+ model_id = "timbrooks/instruct-pix2pix"
8
+ pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(
9
+ model_id, torch_dtype=torch.float32, safety_checker=None
10
+ )
11
+ pipe.to("cpu") # আপনার ফ্রি স্পেসের জন্য সিপইউ ব্যবহার করা হয়েছে
12
+
13
+ def edit_image(input_image, instruction):
14
+ if input_image is None or instruction == "":
15
+ return None
16
+
17
+ # এআই প্রসেসিং
18
+ edited_image = pipe(
19
+ prompt=instruction,
20
+ image=input_image,
21
+ num_inference_steps=5, # সিপইউ তে দ্রুত করার জন্য স্টেপ কমানো হয়েছে
22
+ image_guidance_scale=1.5,
23
+ guidance_scale=7.5
24
+ ).images[0]
25
+
26
+ return edited_image
27
+
28
+ # ইন্টারফেস ডিজাইন
29
+ with gr.Blocks() as demo:
30
+ gr.Markdown("## 🎨 AI Photo Editor (Prompt Based)")
31
+ with gr.Row():
32
+ with gr.Column():
33
+ img_in = gr.Image(type="pil", label="আপনার ছবি দিন")
34
+ prompt_in = gr.Textbox(label="কি এডিট করতে চান?", placeholder="যেমন: Make the dress red or change background to moon")
35
+ btn = gr.Button("এডিট করুন")
36
+ with gr.Column():
37
+ img_out = gr.Image(type="pil", label="এডিট করা ছবি")
38
+
39
+ btn.click(edit_image, inputs=[img_in, prompt_in], outputs=img_out)
40
+
41
+ demo.launch()