Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,61 +3,48 @@ import subprocess
|
|
| 3 |
import os
|
| 4 |
import shutil
|
| 5 |
|
| 6 |
-
|
| 7 |
def setup_avif_decode():
|
| 8 |
# Install Rust and Cargo
|
| 9 |
if not os.path.exists(os.path.expanduser("~/.cargo/bin/cargo")):
|
|
|
|
| 10 |
subprocess.run("curl https://sh.rustup.rs -sSf | sh -s -- -y", shell=True, check=True)
|
| 11 |
os.environ['PATH'] += os.pathsep + os.path.expanduser("~/.cargo/bin")
|
| 12 |
-
|
| 13 |
-
# Clone avif-decode if it doesn't exist
|
| 14 |
if not os.path.exists("avif-decode"):
|
| 15 |
subprocess.run("git clone https://github.com/kornelski/avif-decode.git", shell=True, check=True)
|
| 16 |
-
|
| 17 |
-
# Build avif-decode
|
| 18 |
subprocess.run("cd avif-decode && cargo build --release", shell=True, check=True)
|
| 19 |
-
|
| 20 |
-
# Call setup function to ensure everything is installed and built
|
| 21 |
setup_avif_decode()
|
| 22 |
|
| 23 |
-
|
| 24 |
def convert_avif_to_png(avif_file):
|
| 25 |
avif_path = avif_file.name
|
| 26 |
png_path = avif_path.rsplit('.', 1)[0] + '.png'
|
| 27 |
-
|
| 28 |
-
# Run the avif-decode command
|
| 29 |
result = subprocess.run(["avif-decode/target/release/avif_decode", "-f", avif_path, png_path], capture_output=True, text=True)
|
| 30 |
-
|
| 31 |
if result.returncode == 0:
|
| 32 |
return png_path
|
| 33 |
else:
|
| 34 |
return f"Error converting {avif_file.name}: {result.stderr}"
|
| 35 |
|
|
|
|
| 36 |
css = """
|
| 37 |
#col-container {
|
| 38 |
margin: 0 auto;
|
| 39 |
max-width: 520px;
|
| 40 |
}
|
| 41 |
"""
|
| 42 |
-
|
| 43 |
-
with gr.Blocks(css=css) as demo:
|
| 44 |
-
|
| 45 |
with gr.Column(elem_id="col-container"):
|
| 46 |
gr.Markdown("""
|
| 47 |
# AVIF to PNG Converter
|
| 48 |
Upload your AVIF files and get them converted to PNG.
|
| 49 |
-
""")
|
| 50 |
-
|
| 51 |
-
with gr.Row():
|
| 52 |
-
|
| 53 |
avif_file = gr.File(
|
| 54 |
label="Upload AVIF File",
|
| 55 |
file_types=[".avif"],
|
| 56 |
file_count="multiple"
|
| 57 |
-
)
|
| 58 |
-
|
| 59 |
-
run_button = gr.Button("Convert", scale=0)
|
| 60 |
-
|
| 61 |
result = gr.Gallery(label="Result")
|
| 62 |
|
| 63 |
run_button.click(
|
|
@@ -65,5 +52,4 @@ with gr.Blocks(css=css) as demo:
|
|
| 65 |
inputs=[avif_file],
|
| 66 |
outputs=[result]
|
| 67 |
)
|
| 68 |
-
|
| 69 |
-
demo.queue().launch()
|
|
|
|
| 3 |
import os
|
| 4 |
import shutil
|
| 5 |
|
| 6 |
+
|
| 7 |
def setup_avif_decode():
|
| 8 |
# Install Rust and Cargo
|
| 9 |
if not os.path.exists(os.path.expanduser("~/.cargo/bin/cargo")):
|
| 10 |
+
subprocess.run("apt-get update && apt-get install -y yasm", shell=True, check=True)
|
| 11 |
subprocess.run("curl https://sh.rustup.rs -sSf | sh -s -- -y", shell=True, check=True)
|
| 12 |
os.environ['PATH'] += os.pathsep + os.path.expanduser("~/.cargo/bin")
|
|
|
|
|
|
|
| 13 |
if not os.path.exists("avif-decode"):
|
| 14 |
subprocess.run("git clone https://github.com/kornelski/avif-decode.git", shell=True, check=True)
|
|
|
|
|
|
|
| 15 |
subprocess.run("cd avif-decode && cargo build --release", shell=True, check=True)
|
|
|
|
|
|
|
| 16 |
setup_avif_decode()
|
| 17 |
|
| 18 |
+
|
| 19 |
def convert_avif_to_png(avif_file):
|
| 20 |
avif_path = avif_file.name
|
| 21 |
png_path = avif_path.rsplit('.', 1)[0] + '.png'
|
|
|
|
|
|
|
| 22 |
result = subprocess.run(["avif-decode/target/release/avif_decode", "-f", avif_path, png_path], capture_output=True, text=True)
|
|
|
|
| 23 |
if result.returncode == 0:
|
| 24 |
return png_path
|
| 25 |
else:
|
| 26 |
return f"Error converting {avif_file.name}: {result.stderr}"
|
| 27 |
|
| 28 |
+
|
| 29 |
css = """
|
| 30 |
#col-container {
|
| 31 |
margin: 0 auto;
|
| 32 |
max-width: 520px;
|
| 33 |
}
|
| 34 |
"""
|
| 35 |
+
with gr.Blocks(css=css) as demo:
|
|
|
|
|
|
|
| 36 |
with gr.Column(elem_id="col-container"):
|
| 37 |
gr.Markdown("""
|
| 38 |
# AVIF to PNG Converter
|
| 39 |
Upload your AVIF files and get them converted to PNG.
|
| 40 |
+
""")
|
| 41 |
+
with gr.Row():
|
|
|
|
|
|
|
| 42 |
avif_file = gr.File(
|
| 43 |
label="Upload AVIF File",
|
| 44 |
file_types=[".avif"],
|
| 45 |
file_count="multiple"
|
| 46 |
+
)
|
| 47 |
+
run_button = gr.Button("Convert", scale=0)
|
|
|
|
|
|
|
| 48 |
result = gr.Gallery(label="Result")
|
| 49 |
|
| 50 |
run_button.click(
|
|
|
|
| 52 |
inputs=[avif_file],
|
| 53 |
outputs=[result]
|
| 54 |
)
|
| 55 |
+
demo.queue().launch()
|
|
|