animena3264 commited on
Commit
d5fc3b9
·
verified ·
1 Parent(s): ee17b44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -15
app.py CHANGED
@@ -1,20 +1,42 @@
1
  import gradio as gr
2
- from PIL import Image
3
 
4
- def upscale_image(image):
5
- # ตัวอย่างการขยายภาพ 2x ด้วย PIL
6
- original_size = image.size
7
- upscaled_image = image.resize((original_size[0] * 2, original_size[1] * 2), Image.Resampling.LANCZOS)
8
- return upscaled_image
 
 
 
 
 
9
 
10
- # สร้าง Gradio Interface
11
- demo = gr.Interface(
12
- fn=upscale_image, # ฟังก์ชันสำหรับการอัปสเกล
13
- inputs=gr.Image(type="pil"), # อินพุตเป็นภาพ
14
- outputs=gr.Image(type="pil"), # เอาต์พุตเป็นภาพ
15
- title="Upscale Image 2x", # ชื่ออินเทอร์เฟซ
16
- description="อัปสเกลภาพ 2x ด้วย Gradio"
17
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- # เปิดใช้งานอินเทอร์เฟซ
20
  demo.launch()
 
1
  import gradio as gr
2
+ from gradio_client import Client, handle_file
3
 
4
+ # ฟังก์ชันสำหรับอัปสเกลภาพ
5
+ def upscale(image):
6
+ # ใช้โมเดล 4xNomosWebPhoto_RealPLKSR สำหรับการอัปสเกล
7
+ client = Client("Phips/Upscaler")
8
+ result = client.predict(
9
+ image=handle_file(image), # ส่งไฟล์ภาพ
10
+ model_selection="4xNomosWebPhoto_esrgan", # กำหนดโมเดล
11
+ api_name="/upscale_image"
12
+ )
13
+ return result # คืนค่าผลลัพธ์ที่ได้จาก API
14
 
15
+ # UI ด้วย Gradio Blocks
16
+ with gr.Blocks() as demo:
17
+ gr.Markdown("## Image Upscaling using 4xNomosWebPhoto_RealPLKSR")
18
+
19
+ with gr.Row():
20
+ with gr.Column():
21
+ gr.Markdown("### Original Image")
22
+ original_image = gr.Image(type="pil", label="Upload your image")
23
+
24
+ with gr.Column():
25
+ gr.Markdown("### Upscaled Image (Hover to compare)")
26
+ upscaled_image = gr.Image(type="pil", interactive=True, label="Upscaled Image")
27
+
28
+ with gr.Row():
29
+ upscale_button = gr.Button("Upscale")
30
+
31
+ def process_and_compare(input_image):
32
+ # ส่งคืนภาพเริ่มต้นและภาพที่อัปสเกล
33
+ upscaled_img = upscale(input_image)
34
+ return input_image, upscaled_img
35
+
36
+ upscale_button.click(
37
+ process_and_compare,
38
+ inputs=original_image,
39
+ outputs=[original_image, upscaled_image]
40
+ )
41
 
 
42
  demo.launch()