ffxbot commited on
Commit
4d0800d
·
verified ·
1 Parent(s): bc7b112

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import spaces
3
+ import torch
4
+ from diffusers import StableDiffusionUpscalePipeline
5
+ from PIL import Image
6
+
7
+ # মডেল লোড করা হচ্ছে
8
+ model_id = "stabilityai/stable-diffusion-x4-upscaler"
9
+ pipeline = StableDiffusionUpscalePipeline.from_pretrained(
10
+ model_id, torch_dtype=torch.float16
11
+ )
12
+ pipeline = pipeline.to("cuda")
13
+
14
+ @spaces.GPU
15
+ def upscale_image(image):
16
+ if image is None:
17
+ return None
18
+
19
+ # ছবির সাইজ বড় হলে OOM এরর এড়াতে ছোট করে নেওয়া হচ্ছে
20
+ max_size = 512
21
+ width, height = image.size
22
+ if width > max_size or height > max_size:
23
+ ratio = min(max_size/width, max_size/height)
24
+ new_size = (int(width*ratio), int(height*ratio))
25
+ image = image.resize(new_size, Image.LANCZOS)
26
+
27
+ if image.mode != "RGB":
28
+ image = image.convert("RGB")
29
+
30
+ prompt = "masterpiece, best quality, high resolution, 8k, highly detailed, photorealistic"
31
+ with torch.no_grad():
32
+ upscaled = pipeline(prompt=prompt, image=image).images[0]
33
+
34
+ return upscaled
35
+
36
+ # Gradio ইন্টারফেস তৈরি
37
+ demo = gr.Interface(
38
+ fn=upscale_image,
39
+ inputs=gr.Image(type="pil", label="এখানে আপনার ছবি দিন"),
40
+ outputs=gr.Image(type="pil", label="8K কোয়ালিটির ছবি"),
41
+ title="🔥 ZeroGPU 8K Image Upscaler 🔥",
42
+ description="আপনার যেকোনো ছবি আপলোড করুন এবং এটি ZeroGPU ব্যবহার করে 8K কোয়ালিটিতে কনভার্ট হয়ে যাবে। (100% Free)",
43
+ theme=gr.themes.Soft(),
44
+ allow_flagging="never"
45
+ )
46
+
47
+ if __name__ == "__main__":
48
+ demo.launch()