Spaces:
Running
Running
import os | |
import subprocess | |
import gradio as gr | |
from deoldify.visualize import get_image_colorizer, get_video_colorizer | |
# Vérifie si le dépôt DeOldify existe, sinon le clone | |
if not os.path.exists("DeOldify"): | |
subprocess.run(["git", "clone", "https://github.com/jantic/DeOldify.git"]) | |
# Change le répertoire de travail | |
os.chdir("DeOldify") | |
# Crée un fichier requirements.txt | |
with open("requirements.txt", "w") as f: | |
f.write("\ndeoldify\ngradio\ntorch\nopencv-python\n") | |
# Installe les dépendances | |
subprocess.run(["pip", "install", "-r", "requirements.txt"]) | |
# Initialiser les colorisateurs | |
image_colorizer = get_image_colorizer() | |
video_colorizer = get_video_colorizer() | |
def colorize_image(input_image): | |
# Processer l'image d'entrée et retourner la version colorisée | |
colorized_image = image_colorizer.get_transformed_image(input_image) | |
return colorized_image | |
def colorize_video(input_video): | |
# Processer la vidéo d'entrée et retourner la version colorisée | |
colorized_video = video_colorizer.get_transformed_video(input_video) | |
return colorized_video | |
# Créer l'interface Gradio | |
image_interface = gr.Interface(fn=colorize_image, inputs="image", outputs="image", title="Colorisation d'Image") | |
video_interface = gr.Interface(fn=colorize_video, inputs="video", outputs="video", title="Colorisation de Vidéo") | |
# Lancer les interfaces | |
image_interface.launch(share=True) | |
video_interface.launch(share=True) | |