Created
April 15, 2023 11:39
-
-
Save 2blackbar/55c5125ee6a95337d311f5820e199980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
import subprocess | |
from tkinter import filedialog | |
import datetime | |
import os | |
def run_script(): | |
# Check if there is a file called "interpolated.mp4" in the chosen folder | |
if os.path.isfile(os.path.join(photos_path.get(), "interpolated.mp4")): | |
# Get the current time as a string | |
now = datetime.datetime.now().strftime("%H%M%S") | |
# Rename the file to "interp" with the current time added | |
os.rename(os.path.join(photos_path.get(), "interpolated.mp4"), os.path.join(photos_path.get(), f"interp{now}.mp4")) | |
# Change the button color to red | |
run_button.config(bg="#FF0000") | |
# Run the activate script to activate the environment | |
activate = subprocess.Popen([r"venv\scripts\activate.bat"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
# Wait for the activate script to finish and check for errors | |
activate_out, activate_err = activate.communicate(timeout=10) | |
if activate.returncode != 0: | |
print("Error activating the environment:", activate_err.decode()) | |
return | |
# Run the Python script with the virtual environment's Python interpreter | |
run = subprocess.Popen([r"venv\scripts\python.exe", "-m", "eval.interpolator_cli", "--pattern", photos_path.get(), "--model_path", "pretrained_models/film_net/Style/saved_model", "--times_to_interpolate", str(times.get()), "--output_video"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
# Wait for the Python script to finish and check for errors | |
run_out, run_err = run.communicate(timeout=1600) | |
if run.returncode != 0: | |
print("_:", run_err.decode()) | |
return | |
# Print the output of the Python script | |
print(run_out.decode()) | |
# Change the button color back to green | |
run_button.config(bg="#00FF00") | |
# Create a label to display the message | |
message_label = tk.Label(root, text="DONE !", font=FONT, fg="#FF0000") | |
message_label.pack(side=tk.TOP, before=run_button) | |
# Define a callback function that will hide the label | |
def hide_message(): | |
message_label.pack_forget() | |
# Schedule the callback function to run after 5000 milliseconds (5 seconds) | |
root.after(5000, hide_message) | |
def increase_times(): | |
# Increase the times_to_interpolate value by 1 | |
times.set(times.get() + 1) | |
def decrease_times(): | |
# Decrease the times_to_interpolate value by 1 | |
times.set(times.get() - 1) | |
def choose_photos(): | |
# Open a file chooser dialog and get the selected path | |
path = filedialog.askdirectory() | |
# Set the photos_path variable to the selected path | |
photos_path.set(path) | |
root = tk.Tk() | |
root.title("FILM INTERPOLATION") | |
# Set the GUI size to 800x800 pixels | |
root.geometry("600x600") | |
# Create constants for colors and fonts | |
LIGHT_BLUE = "#ADD8E6" | |
FONT = ("Arial", 12, "bold") | |
# Create a variable to store the times_to_interpolate value | |
times = tk.IntVar() | |
times.set(1) | |
# Create a variable to store the photos path | |
photos_path = tk.StringVar() | |
photos_path.set("photos") | |
# Create a label to display the string "INPUT FOLDER" | |
input_label = tk.Label(root, text="INPUT FOLDER", font=FONT) | |
input_label.pack(side=tk.TOP) | |
# Create an entry to display the photos path | |
photos_entry = tk.Entry(root, textvariable=photos_path, font=FONT) | |
photos_entry.pack(side=tk.TOP) | |
# Create a button to choose the photos path | |
choose_button = tk.Button(root, text="Choose Folder", command=choose_photos, height=10, width=10, bg=LIGHT_BLUE) | |
choose_button.pack(side=tk.TOP) | |
# Create a label to display the string "times to interpolate" | |
string_label = tk.Label(root, text="TIMES TO INTERPOLATE", font=FONT) | |
string_label.place(anchor="center", relx=0.3, rely=0.62) # use place method to center the label | |
# Create a label to display the value | |
times_label = tk.Label(root, textvariable=times, font=FONT) | |
times_label.pack(side=tk.LEFT) | |
# Create a scale to adjust the times_to_interpolate value | |
times_scale = tk.Scale(root, from_=1, to=20, resolution=1, orient=tk.HORIZONTAL, variable=times, length=300) | |
times_scale.pack(side=tk.LEFT) | |
# Create a button to run the script | |
# Set the background color to green and increase the size | |
run_button = tk.Button(root, text="Run", command=run_script, height=10, width=10, bg="#00FF00") | |
run_button.pack(padx=10, pady=10) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment