Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 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()
|