auto convert uploaded webp to png
Browse files
app.py
CHANGED
@@ -96,7 +96,17 @@ def check_and_convert_webp_to_png(input_path, output_path):
|
|
96 |
return input_path
|
97 |
except IOError:
|
98 |
print(f"Cannot open {input_path}. The file might not exist or is not an image.")
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
def clear_audio_elms():
|
101 |
return gr.update(value=None, visible=False)
|
102 |
|
@@ -443,6 +453,14 @@ with gr.Blocks(css=css) as demo:
|
|
443 |
|
444 |
""")
|
445 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
voice.upload(
|
447 |
fn = check_mp3,
|
448 |
inputs = [voice],
|
|
|
96 |
return input_path
|
97 |
except IOError:
|
98 |
print(f"Cannot open {input_path}. The file might not exist or is not an image.")
|
99 |
+
|
100 |
+
def convert_user_uploded_webp(input_path):
|
101 |
+
|
102 |
+
# convert to png if necessary
|
103 |
+
input_file = input_path
|
104 |
+
unique_id = uuid.uuid4()
|
105 |
+
output_file = f"converted_to_png_portrait-{unique_id}.png"
|
106 |
+
ready_png = check_and_convert_webp_to_png(input_file, output_file)
|
107 |
+
print(f"PORTRAIT PNG FILE: {ready_png}")
|
108 |
+
return ready_png
|
109 |
+
|
110 |
def clear_audio_elms():
|
111 |
return gr.update(value=None, visible=False)
|
112 |
|
|
|
453 |
|
454 |
""")
|
455 |
|
456 |
+
portrait.upload(
|
457 |
+
fn = convert_user_uploded_webp,
|
458 |
+
inputs = [portrait],
|
459 |
+
outputs = [portrait],
|
460 |
+
queue = False,
|
461 |
+
show_api = False
|
462 |
+
)
|
463 |
+
|
464 |
voice.upload(
|
465 |
fn = check_mp3,
|
466 |
inputs = [voice],
|