AItool commited on
Commit
84c3d0e
·
verified ·
1 Parent(s): 836da13

Delete _app.py

Browse files
Files changed (1) hide show
  1. _app.py +0 -111
_app.py DELETED
@@ -1,111 +0,0 @@
1
- # app.py
2
- import os
3
- import uuid
4
- import subprocess
5
- from pathlib import Path
6
- from typing import Tuple
7
- from inference_img import *
8
- import gradio as gr
9
-
10
- # Demo images
11
- FRAME1 = Path("demo/frame1.jpg")
12
- FRAME2 = Path("demo/frame2.jpg")
13
- DEMO = Path("demo/demo.gif")
14
- MODEL = Path("train_log/")
15
-
16
- TMP_PREFIX = "demo/"
17
- TARGET_DIR = f"{TMP_PREFIX}output/"
18
- EXTENSION = "png"
19
-
20
- def interpolate_image(img_a_path: str, img_b_path: str) -> Tuple[str, str]:
21
- """
22
- 3-step pipeline:
23
- 1) inference_img.py --img <A> <B> --exp=4 -> writes frames as /tmp/gradio/output/img%d.png
24
- 2) ffmpeg palettegen
25
- 3) ffmpeg paletteuse -> final GIF at a unique path
26
- Returns: (gif_filepath_for_preview, gif_filepath_for_download)
27
- """
28
- # Ensure temp dirs exist
29
- os.makedirs(TARGET_DIR, exist_ok=True)
30
-
31
- # Unique output path per run
32
- interpolated_path = f"{TARGET_DIR}{uuid.uuid4()}.{EXTENSION}"
33
- palette_path = f"{TMP_PREFIX}palette.png"
34
-
35
- try:
36
-
37
- #inference_img(img=[Path(img_a_path), Path(img_b_path)],exp=4)
38
-
39
- print("ok")
40
-
41
- subprocess.run([
42
- "ffmpeg", "-y", "-r", "14", "-f", "image2",
43
- "-i", f"{TARGET_DIR}img%d.png",
44
- "-vf", "palettegen=stats_mode=single",
45
- palette_path
46
- ], check=True)
47
-
48
-
49
-
50
-
51
- # 1) Run interpolation (frames -> TARGET_DIR/img1.png ... imgN.png)
52
- #subprocess.run([
53
- # "python3", "inference_img.py",
54
- # "--img", str(img_a_path), str(img_b_path),
55
- # "--exp", "4"
56
- #], check=True)
57
-
58
- print("ok")
59
- # 2) Generate palette
60
- subprocess.run([
61
- "ffmpeg", "-y", "-r", "14", "-f", "image2",
62
- "-i", f"{TARGET_DIR}img%d.png",
63
- "-vf", "palettegen=stats_mode=single",
64
- palette_path
65
- ], check=True)
66
-
67
- # 3) Use palette to produce final GIF
68
- #!ffmpeg -r 14 -f image2 -i output/img%d.png -vf "palettegen=stats_mode=single" palette.png
69
- subprocess.run([
70
- "ffmpeg", "-y", "-r", "14", "-f",
71
- "-i", f"{TARGET_DIR}img%d.png",
72
- "palettegen=stats_mode=single",
73
- palette_path
74
- ], check=True)
75
-
76
- return interpolated_image, interpolated_path
77
-
78
- except subprocess.CalledProcessError as e:
79
- raise gr.Error(f"Interpolation failed. {e}")
80
-
81
- # Gradio UI
82
- with gr.Blocks(title="RIFE Interpolation") as demo:
83
- with gr.Tab("Demo"):
84
- gr.Markdown("### Demo: Preloaded images")
85
- input_imageA = gr.Image(type="filepath", value=str(FRAME1), label="Image A")
86
- input_imageB = gr.Image(type="filepath", value=str(FRAME2), label="Image B")
87
- output_image = gr.Image(type="filepath", value=str(DEMO), label="Demo")
88
- g_btn = gr.Button("Interpolate")
89
-
90
- output_image = gr.Image(type="filepath", label="Interpolated GIF")
91
- enhance_image_path = gr.Textbox(label="Output path", interactive=False)
92
-
93
- g_btn.click(
94
- fn=interpolate_image,
95
- inputs=[input_imageA, input_imageB]
96
- )
97
-
98
- with gr.Tab("Upload your images"):
99
- gr.Markdown("### Upload any two images")
100
- input_imageA = gr.Image(type="filepath", label="Image A")
101
- input_imageB = gr.Image(type="filepath", label="Image B")
102
- user_btn = gr.Button("Interpolate")
103
- user_out = gr.Image(type="filepath", value=str(TARGET_DIR), label="Interpolated GIF")
104
- user_path = gr.Textbox(label="Output path", value=str(TARGET_DIR), interactive=False)
105
- user_btn.click(
106
- fn=interpolate_image,
107
- inputs=[input_imageA, input_imageB],
108
- outputs=[user_out, user_path],
109
- )
110
-
111
- demo.launch()