Spaces:
Running
Running
File size: 1,760 Bytes
112aa35 4d43fca 112aa35 9dafb56 4d43fca 7ab7a6b 112aa35 9dafb56 4d43fca 112aa35 1245c6a 9dafb56 1245c6a 5279551 112aa35 9dafb56 112aa35 9dafb56 112aa35 9dafb56 112aa35 9dafb56 112aa35 c8a2177 b17d754 4d43fca b17d754 4d43fca 9dafb56 b17d754 4d43fca 9dafb56 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 * # Assuming necessary functions are exposed here
# Constants
OUTPUT_GIF = Path("demo/output.gif")
FRAME1_PATH = Path("demo/frame1.png")
FRAME2_PATH = Path("demo/frame2.png")
# Function to generate GIF
def generate_demo_gif(_1, _2):
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 str(OUTPUT_GIF), "β
GIF generated successfully!"
else:
return None, "β GIF generation failed. Check logs or file paths."
except Exception as e:
print(f"Error: {e}")
return None, f"β Subprocess error: {e}"
# Gradio UI
with gr.Blocks() as demo_ui:
with gr.Tab("Demo"):
gr.Markdown("### Preview frames and generate animation. #FREE CPU cut off, 5.5 seconds and done. No AI democracy.")
with gr.Row():
img1_preview = gr.Image(value=str(FRAME1_PATH), label="Frame 1", interactive=False)
img2_preview = gr.Image(value=str(FRAME2_PATH), label="Frame 2", interactive=False)
generate_btn = gr.Button("Generate GIF")
output_gif = gr.Image(label="Animated GIF")
status_msg = gr.Markdown()
generate_btn.click(
fn=generate_demo_gif,
inputs=[img1_preview, img2_preview], # Non-interactive but passed to match fn signature
outputs=[output_gif, status_msg]
)
demo_ui.launch()
|