Spaces:
Running
Running
File size: 1,468 Bytes
112aa35 e86d900 112aa35 e86d900 112aa35 b17d754 112aa35 1245c6a b17d754 1245c6a 112aa35 b17d754 112aa35 1245c6a 112aa35 b17d754 112aa35 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import gradio as gr
from pathlib import Path
import subprocess
from inference_img import *
OUTPUT_GIF = Path("demo/output.gif")
def generate_demo_gif(img1, img2):
# Save uploaded images
frame1_path = Path("demo/frame1.jpg")
frame2_path = Path("demo/frame2.jpg")
img1.save(frame1_path)
img2.save(frame2_path)
try:
result = subprocess.run([
"python", "inference_img.py",
"--img", str(frame1_path), str(frame2_path),
"--exp=4",
"--model='train_log/",
], capture_output=True, text=True)
print("STDOUT:", result.stdout)
print("STDERR:", result.stderr)
if result.returncode == 0 and OUTPUT_GIF.exists():
return OUTPUT_GIF
else:
return "GIF generation failed."
except Exception as e:
print(f"Error: {e}")
return "No subprocss. Error during GIF generation."
with gr.Blocks() as demo_ui:
with gr.Tab("Demo"):
gr.Markdown("### Upload two frames to generate a GIF")
with gr.Row():
img1_input = gr.Image(type="pil", label="Frame 1")
img2_input = gr.Image(type="pil", label="Frame 2")
generate_btn = gr.Button("Generate GIF")
output_gif = gr.Image(label="Generated GIF")
generate_btn.click(
fn=generate_demo_gif,
inputs=[img1_input, img2_input],
outputs=output_gif
)
demo_ui.launch()
|