Spaces:
Running on Zero
Running on Zero
Update app.py
#2
by Golf8 - opened
app.py
CHANGED
|
@@ -1,33 +1,53 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
fn=infer_image,
|
| 12 |
-
inputs=[input_image, input_model_image],
|
| 13 |
-
outputs=output_image,
|
| 14 |
-
title="Real-ESRGAN Pytorch",
|
| 15 |
-
description="Gradio UI for Real-ESRGAN Pytorch version. To use it, simply upload your image and choose the model. Read more at the links below. Please click submit only once <br>Credits: [Nick088](https://linktr.ee/Nick088), Xinntao, Tencent, Geeve George, ai-forever, daroche <br><p style='text-align: center'><a href='https://github.com/Nick088/Real-ESRGAN_Pytorch'>Github Repo</a></p>"
|
| 16 |
-
)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
input_model_video = gr.Radio([('x2', 2), ('x4', 4), ('x8', 8)], type="value", value=2, label="Model Upscale/Enhance Type")
|
| 20 |
-
submit_video_button = gr.Button('Submit')
|
| 21 |
-
output_video = gr.Video(label='Output Video')
|
| 22 |
-
|
| 23 |
-
tab_vid = gr.Interface(
|
| 24 |
-
fn=infer_video,
|
| 25 |
-
inputs=[input_video, input_model_video],
|
| 26 |
-
outputs=output_video,
|
| 27 |
-
title="Real-ESRGAN Pytorch",
|
| 28 |
-
description="Gradio UI for Real-ESRGAN Pytorch version. To use it, simply upload your video and choose the model. Read more at the links below. Please click submit only once <br>Credits: [Nick088](https://linktr.ee/Nick088), Xinntao, Tencent, Geeve George, ai-forever, daroche <br><p style='text-align: center'><a href='https://arxiv.org/abs/2107.10833'>Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data</a> | <a href='https://github.com/ai-forever/Real-ESRGAN'>Github Repo</a></p>"
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
-
demo = gr.TabbedInterface([tab_img, tab_vid], ["Image", "Video"])
|
| 32 |
-
|
| 33 |
-
demo.launch(debug=True, show_error=True, share=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image, ImageEnhance, ImageFilter
|
| 3 |
|
| 4 |
+
def advanced_upscale(image, scale, enhance):
|
| 5 |
+
if image is None:
|
| 6 |
+
return None, "画像をアップロードしてください"
|
| 7 |
+
|
| 8 |
+
# 元のサイズ
|
| 9 |
+
width, height = image.size
|
| 10 |
+
new_width = int(width * scale)
|
| 11 |
+
new_height = int(height * scale)
|
| 12 |
+
|
| 13 |
+
# 高品質アップスケール
|
| 14 |
+
upscaled = image.resize((new_width, new_height), Image.LANCZOS)
|
| 15 |
+
|
| 16 |
+
# 追加補正
|
| 17 |
+
if enhance:
|
| 18 |
+
# シャープネス強化
|
| 19 |
+
upscaled = upscaled.filter(ImageFilter.UnsharpMask(radius=2, percent=150, threshold=3))
|
| 20 |
+
# コントラスト・明るさ調整
|
| 21 |
+
enhancer = ImageEnhance.Contrast(upscaled)
|
| 22 |
+
upscaled = enhancer.enhance(1.1)
|
| 23 |
+
enhancer = ImageEnhance.Sharpness(upscaled)
|
| 24 |
+
upscaled = enhancer.enhance(1.3)
|
| 25 |
+
|
| 26 |
+
# ファイルサイズ目安表示
|
| 27 |
+
import io
|
| 28 |
+
buf = io.BytesIO()
|
| 29 |
+
upscaled.save(buf, format="PNG", quality=95)
|
| 30 |
+
size_mb = len(buf.getvalue()) / (1024 * 1024)
|
| 31 |
+
|
| 32 |
+
return upscaled, f"✅ {scale}x 完了! 予想サイズ: {size_mb:.2f} MB"
|
| 33 |
|
| 34 |
+
with gr.Blocks(title="Kazの高画質化アプリ") as demo:
|
| 35 |
+
gr.Markdown("# 🖼️ KazのAI画像高画質化アプリ\n**改善版** - より綺麗に")
|
| 36 |
+
|
| 37 |
+
with gr.Row():
|
| 38 |
+
with gr.Column():
|
| 39 |
+
input_img = gr.Image(label="画像をアップロード", type="pil", height=500)
|
| 40 |
+
scale = gr.Radio([2, 4, 8], value=4, label="拡大倍率(8xでかなり重くなります)")
|
| 41 |
+
enhance = gr.Checkbox(label="さらにシャープ・コントラスト強化", value=True)
|
| 42 |
+
btn = gr.Button("🚀 高画質化開始", variant="primary")
|
| 43 |
+
|
| 44 |
+
with gr.Column():
|
| 45 |
+
output_img = gr.Image(label="処理結果", height=500)
|
| 46 |
+
|
| 47 |
+
status = gr.Textbox(label="結果")
|
| 48 |
+
|
| 49 |
+
btn.click(advanced_upscale, inputs=[input_img, scale, enhance], outputs=[output_img, status])
|
| 50 |
|
| 51 |
+
gr.Markdown("### Tips\n・4xか8xで試してみてください\n・ズームして比較すると違いが分かりやすいです")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|