Update app.py
Browse files
app.py
CHANGED
@@ -22,6 +22,8 @@ def inference(image, size):
|
|
22 |
if image is None:
|
23 |
raise gr.Error("Image not uploaded")
|
24 |
|
|
|
|
|
25 |
|
26 |
if torch.cuda.is_available():
|
27 |
torch.cuda.empty_cache()
|
@@ -55,22 +57,36 @@ def inference(image, size):
|
|
55 |
result = model2.predict(image.convert('RGB'))
|
56 |
|
57 |
print(f"Image size ({device}): {size} ... OK")
|
58 |
-
|
|
|
59 |
|
60 |
|
61 |
-
title = "ProFaker"
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
[gr.Image(type="pil"),
|
66 |
-
gr.Radio(["2x", "4x", "8x"],
|
67 |
-
type="value",
|
68 |
-
value="2x",
|
69 |
-
label="Resolution model")],
|
70 |
-
ImageSlider(interactive = False, type="pil", label="Output"),
|
71 |
-
title=title,
|
72 |
-
flagging_mode="never",
|
73 |
-
cache_mode="lazy",
|
74 |
-
delete_cache=(44000, 44000),
|
75 |
-
).queue(api_open=True).launch(show_error=True, show_api=True)
|
76 |
-
|
|
|
22 |
if image is None:
|
23 |
raise gr.Error("Image not uploaded")
|
24 |
|
25 |
+
# Store original image for comparison
|
26 |
+
original_image = image.copy()
|
27 |
|
28 |
if torch.cuda.is_available():
|
29 |
torch.cuda.empty_cache()
|
|
|
57 |
result = model2.predict(image.convert('RGB'))
|
58 |
|
59 |
print(f"Image size ({device}): {size} ... OK")
|
60 |
+
# Return tuple of original and processed images for the slider
|
61 |
+
return (original_image, result)
|
62 |
|
63 |
|
64 |
+
title = """<h1 align="center">ProFaker</h1>"""
|
65 |
|
66 |
+
with gr.Blocks() as demo:
|
67 |
+
gr.HTML(title)
|
68 |
+
|
69 |
+
with gr.Row():
|
70 |
+
with gr.Column():
|
71 |
+
input_image = gr.Image(type="pil", label="Input Image")
|
72 |
+
size_select = gr.Radio(
|
73 |
+
["2x", "4x", "8x"],
|
74 |
+
type="value",
|
75 |
+
value="2x",
|
76 |
+
label="Resolution model"
|
77 |
+
)
|
78 |
+
process_btn = gr.Button("Upscale Image")
|
79 |
+
|
80 |
+
with gr.Column():
|
81 |
+
result_slider = ImageSlider(
|
82 |
+
interactive=False,
|
83 |
+
label="Before and After Comparison"
|
84 |
+
)
|
85 |
+
|
86 |
+
process_btn.click(
|
87 |
+
fn=inference,
|
88 |
+
inputs=[input_image, size_select],
|
89 |
+
outputs=result_slider
|
90 |
+
)
|
91 |
|
92 |
+
demo.queue(api_open=True).launch(show_error=True, show_api=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|