Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,18 @@
|
|
1 |
-
import os
|
2 |
-
import sys
|
3 |
-
import time
|
4 |
-
import gradio as gr
|
5 |
import torch
|
6 |
-
import
|
7 |
-
|
8 |
-
# Cloner le repo si non présent
|
9 |
-
if not os.path.exists('TCVC-Temporally-Consistent-Video-Colorization'):
|
10 |
-
os.system('git clone https://github.com/lyh-18/TCVC-Temporally-Consistent-Video-Colorization.git')
|
11 |
-
|
12 |
-
# Vérifier si le dépôt est bien cloné
|
13 |
-
while not os.path.exists('TCVC-Temporally-Consistent-Video-Colorization'):
|
14 |
-
time.sleep(1) # Attendre que le clonage soit terminé
|
15 |
-
|
16 |
-
# Ajouter le dépôt cloné au chemin Python
|
17 |
-
sys.path.append('TCVC-Temporally-Consistent-Video-Colorization')
|
18 |
|
19 |
-
#
|
20 |
-
|
|
|
|
|
21 |
|
22 |
-
# Charger le modèle pré-entraîné
|
23 |
-
|
24 |
-
model = TCVC_Model()
|
25 |
-
model.load_state_dict(torch.load("path_to_pretrained_model.pth")) # Charge le modèle pré-entraîné
|
26 |
-
model.eval() # Mode évaluation
|
27 |
-
return model
|
28 |
|
29 |
-
# Fonction
|
30 |
def colorize_video(video_path):
|
31 |
-
|
32 |
-
|
33 |
-
# Lire la vidéo
|
34 |
-
cap = cv2.VideoCapture(video_path)
|
35 |
-
frame_width = int(cap.get(3))
|
36 |
-
frame_height = int(cap.get(4))
|
37 |
-
fps = cap.get(cv2.CAP_PROP_FPS)
|
38 |
-
|
39 |
-
output_path = "colorized_output.mp4"
|
40 |
-
out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (frame_width, frame_height))
|
41 |
-
|
42 |
-
while(cap.isOpened()):
|
43 |
-
ret, frame = cap.read()
|
44 |
-
if not ret:
|
45 |
-
break
|
46 |
-
# Convertir l'image en noir et blanc en couleur
|
47 |
-
color_frame = model.colorize_frame(frame)
|
48 |
-
out.write(color_frame)
|
49 |
-
|
50 |
-
cap.release()
|
51 |
-
out.release()
|
52 |
return output_path
|
53 |
|
54 |
# Interface Gradio
|
@@ -56,12 +20,12 @@ def process_video(video):
|
|
56 |
colorized_video = colorize_video(video.name)
|
57 |
return colorized_video
|
58 |
|
59 |
-
#
|
60 |
interface = gr.Interface(fn=process_video,
|
61 |
-
inputs=gr.Video(label="Télécharger une vidéo en noir et blanc"),
|
62 |
outputs=gr.Video(label="Vidéo colorisée"),
|
63 |
-
title="Colorisation
|
64 |
-
description="Téléchargez une vidéo en noir et blanc
|
65 |
|
66 |
if __name__ == "__main__":
|
67 |
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
1 |
import torch
|
2 |
+
from deoldify.visualize import get_image_colorizer, get_video_colorizer
|
3 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
# Clone le repo et télécharge les dépendances
|
6 |
+
if not os.path.exists('DeOldify'):
|
7 |
+
os.system('git clone https://github.com/jantic/DeOldify.git')
|
8 |
+
os.system('pip install -r DeOldify/requirements-colab.txt')
|
9 |
|
10 |
+
# Charger le modèle DeOldify pré-entraîné
|
11 |
+
video_colorizer = get_video_colorizer()
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
# Fonction pour coloriser une vidéo
|
14 |
def colorize_video(video_path):
|
15 |
+
output_path = video_colorizer.colorize_from_file_name(video_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
return output_path
|
17 |
|
18 |
# Interface Gradio
|
|
|
20 |
colorized_video = colorize_video(video.name)
|
21 |
return colorized_video
|
22 |
|
23 |
+
# Interface Gradio pour uploader la vidéo
|
24 |
interface = gr.Interface(fn=process_video,
|
25 |
+
inputs=gr.Video(label="Télécharger une vidéo en noir et blanc"),
|
26 |
outputs=gr.Video(label="Vidéo colorisée"),
|
27 |
+
title="Colorisation de Vidéo avec DeOldify",
|
28 |
+
description="Téléchargez une vidéo en noir et blanc pour la coloriser.")
|
29 |
|
30 |
if __name__ == "__main__":
|
31 |
interface.launch()
|