Spaces:
Running
Running
File size: 2,454 Bytes
2f72c5e b120055 2f72c5e eebd998 |
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
import os
import subprocess
from pathlib import Path
from PIL import Image
import streamlit as st
import urllib.request
from PIL import Image,ImageFile
import streamlit as st
import numpy as np
import requests
from io import BytesIO
# ---- CONFIG ----
st.set_page_config(
page_title="Streamlit iCodeIdoia",
page_icon="images/ilpicon1.png",
layout="wide",
initial_sidebar_state="expanded"
)
st.image("images/banner.jpg")
# ---- PATHS ----
FRAME1 = Path("demo/frame1.png")
FRAME2 = Path("demo/frame2.png")
TARGET_DIR = Path("/home/user/app/output/")
PALETTE_PNG = TARGET_DIR / "palette.png"
OUTPUT_GIF = TARGET_DIR / "output.gif"
os.makedirs(TARGET_DIR, exist_ok=True)
# ---- FUNCTION ----
def interpolate_image(img_a_path: str, img_b_path: str) -> str:
subprocess.run([
"python3", "inference_img.py",
"--img", str(img_a_path), str(img_b_path),
"--exp", "4"
], check=True)
subprocess.run([
"ffmpeg", "-y", "-r", "14", "-f", "image2",
"-i", f"{TARGET_DIR}/img%d.png",
"-vf", "palettegen=stats_mode=single",
"-frames:v", "1",
str(PALETTE_PNG)
], check=True)
subprocess.run([
"ffmpeg", "-y", "-r", "14", "-f", "image2",
"-i", f"{TARGET_DIR}/img%d.png",
"-i", str(PALETTE_PNG),
"-lavfi", "paletteuse",
str(OUTPUT_GIF)
], check=True)
return str(OUTPUT_GIF)
# ---- TABS ----
tab1, tab2 = st.tabs(["Demo", "Upload your images"])
with tab1:
st.subheader("Demo: Preloaded images")
st.image(str(FRAME1), caption="Image A")
st.image(str(FRAME2), caption="Image B")
if st.button("Run Interpolation Demo"):
gif_path = interpolate_image(FRAME1, FRAME2)
st.image(gif_path, caption="Interpolated GIF")
st.text(f"Output path: {gif_path}")
with tab2:
st.subheader("Upload any two images")
uploaded_a = st.file_uploader("Upload Image A", type=["png", "jpg", "jpeg"])
uploaded_b = st.file_uploader("Upload Image B", type=["png", "jpg", "jpeg"])
if uploaded_a and uploaded_b:
temp_a = TARGET_DIR / "user_a.png"
temp_b = TARGET_DIR / "user_b.png"
Image.open(uploaded_a).save(temp_a)
Image.open(uploaded_b).save(temp_b)
if st.button("Run Interpolation"):
gif_path = interpolate_image(temp_a, temp_b)
st.image(gif_path, caption="Interpolated GIF")
#st.text(f"Output path: {gif_path}")
|