Resolved merge conflicts
Browse files
app.py
CHANGED
@@ -16,17 +16,27 @@ language_map = {
|
|
16 |
"Japanese": "Helsinki-NLP/opus-mt-en-jap"
|
17 |
}
|
18 |
|
|
|
19 |
# Custom CSS for dark mode and animations
|
20 |
css = """
|
21 |
body {
|
22 |
background-color: #1a1a1a;
|
23 |
color: #e0e0e0;
|
24 |
font-family: 'Arial', sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
26 |
.gradio-container {
|
27 |
max-width: 1200px;
|
28 |
margin: 0 auto;
|
29 |
padding: 20px;
|
|
|
30 |
border-radius: 10px;
|
31 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
32 |
}
|
@@ -42,6 +52,21 @@ body {
|
|
42 |
}
|
43 |
@keyframes blink {
|
44 |
50% { opacity: 0.5; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
}
|
46 |
"""
|
47 |
|
@@ -64,9 +89,15 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css=css) as demo:
|
|
64 |
value="English"
|
65 |
)
|
66 |
|
|
|
67 |
generate_button = gr.Button("Generate Subtitles π")
|
68 |
progress_text = gr.Textbox(
|
69 |
label="Progress",
|
|
|
|
|
|
|
|
|
|
|
70 |
interactive=False,
|
71 |
elem_classes=["progress-text"]
|
72 |
)
|
@@ -78,6 +109,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css=css) as demo:
|
|
78 |
if not video_file.name.lower().endswith(('.mp4', '.mkv', '.avi')):
|
79 |
return None, "β Invalid file type. Please upload an MP4, MKV, or AVI file."
|
80 |
|
|
|
81 |
# Update progress
|
82 |
progress = "π Processing video..."
|
83 |
yield None, progress # Initial progress update
|
@@ -90,6 +122,24 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css=css) as demo:
|
|
90 |
yield None, "β Error during processing. Check logs."
|
91 |
except Exception as e:
|
92 |
yield None, f"β Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
generate_button.click(
|
95 |
generate_subtitles,
|
|
|
16 |
"Japanese": "Helsinki-NLP/opus-mt-en-jap"
|
17 |
}
|
18 |
|
19 |
+
<<<<<<< HEAD
|
20 |
# Custom CSS for dark mode and animations
|
21 |
css = """
|
22 |
body {
|
23 |
background-color: #1a1a1a;
|
24 |
color: #e0e0e0;
|
25 |
font-family: 'Arial', sans-serif;
|
26 |
+
=======
|
27 |
+
# Custom CSS for a Windows-like professional look
|
28 |
+
css = """
|
29 |
+
body {
|
30 |
+
background-color: #1a1a1a;
|
31 |
+
color: #e0e0e0;
|
32 |
+
font-family: 'Segoe UI', sans-serif;
|
33 |
+
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
|
34 |
}
|
35 |
.gradio-container {
|
36 |
max-width: 1200px;
|
37 |
margin: 0 auto;
|
38 |
padding: 20px;
|
39 |
+
<<<<<<< HEAD
|
40 |
border-radius: 10px;
|
41 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
42 |
}
|
|
|
52 |
}
|
53 |
@keyframes blink {
|
54 |
50% { opacity: 0.5; }
|
55 |
+
=======
|
56 |
+
border-radius: 8px;
|
57 |
+
background: #2d2d2d;
|
58 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
59 |
+
}
|
60 |
+
.file-preview {
|
61 |
+
border: 2px dashed #007acc;
|
62 |
+
padding: 20px;
|
63 |
+
border-radius: 8px;
|
64 |
+
}
|
65 |
+
.progress-text {
|
66 |
+
color: #00ff00;
|
67 |
+
font-weight: bold;
|
68 |
+
margin-top: 10px;
|
69 |
+
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
|
70 |
}
|
71 |
"""
|
72 |
|
|
|
89 |
value="English"
|
90 |
)
|
91 |
|
92 |
+
<<<<<<< HEAD
|
93 |
generate_button = gr.Button("Generate Subtitles π")
|
94 |
progress_text = gr.Textbox(
|
95 |
label="Progress",
|
96 |
+
=======
|
97 |
+
generate_button = gr.Button("Generate Subtitles π", elem_classes=["btn-primary"])
|
98 |
+
progress_text = gr.Textbox(
|
99 |
+
label="Status",
|
100 |
+
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
|
101 |
interactive=False,
|
102 |
elem_classes=["progress-text"]
|
103 |
)
|
|
|
109 |
if not video_file.name.lower().endswith(('.mp4', '.mkv', '.avi')):
|
110 |
return None, "β Invalid file type. Please upload an MP4, MKV, or AVI file."
|
111 |
|
112 |
+
<<<<<<< HEAD
|
113 |
# Update progress
|
114 |
progress = "π Processing video..."
|
115 |
yield None, progress # Initial progress update
|
|
|
122 |
yield None, "β Error during processing. Check logs."
|
123 |
except Exception as e:
|
124 |
yield None, f"β Error: {str(e)}"
|
125 |
+
=======
|
126 |
+
# Initialize progress tracking
|
127 |
+
progress = gr.Progress(track_tqdm=True)
|
128 |
+
|
129 |
+
# Process video
|
130 |
+
progress(0, desc="Initializing...")
|
131 |
+
srt_path = process_video(video_file.name, language, progress=progress)
|
132 |
+
if srt_path:
|
133 |
+
progress(1, desc="β
Subtitles generated successfully!")
|
134 |
+
return gr.File(srt_path), "β
Subtitles ready for download!"
|
135 |
+
else:
|
136 |
+
progress(0, desc="β Error during processing.")
|
137 |
+
return None, "β Failed to generate subtitles. Check logs."
|
138 |
+
|
139 |
+
except Exception as e:
|
140 |
+
progress(0, desc="β Error encountered.")
|
141 |
+
return None, f"β Error: {str(e)}"
|
142 |
+
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
|
143 |
|
144 |
generate_button.click(
|
145 |
generate_subtitles,
|
utils.py
CHANGED
@@ -7,6 +7,7 @@ import subprocess
|
|
7 |
# Load Whisper model
|
8 |
model = whisper.load_model("base")
|
9 |
|
|
|
10 |
def process_video(video_path, language):
|
11 |
# Create a temporary directory
|
12 |
temp_dir = tempfile.gettempdir()
|
@@ -16,18 +17,38 @@ def process_video(video_path, language):
|
|
16 |
try:
|
17 |
# Convert video to MP4 using ffmpeg
|
18 |
print(f"Converting video: {video_path} to MP4...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
subprocess.run(
|
20 |
["ffmpeg", "-i", video_path, "-c:v", "libx264", "-preset", "fast", output_video_path],
|
21 |
check=True,
|
22 |
stdout=subprocess.PIPE,
|
23 |
stderr=subprocess.PIPE
|
24 |
)
|
|
|
25 |
print("Video converted successfully!")
|
26 |
|
27 |
# Transcribe video
|
28 |
print("Transcribing video...")
|
29 |
result = model.transcribe(output_video_path, language="en")
|
30 |
print("Transcription completed!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# Translation logic
|
33 |
segments = []
|
@@ -48,10 +69,13 @@ def process_video(video_path, language):
|
|
48 |
}
|
49 |
model_name = model_map.get(language)
|
50 |
if not model_name:
|
51 |
-
return
|
52 |
|
53 |
# Load translation model
|
|
|
54 |
print(f"Loading translation model: {model_name}")
|
|
|
|
|
55 |
if language == "Telugu":
|
56 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
57 |
translation_model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
@@ -73,13 +97,23 @@ def process_video(video_path, language):
|
|
73 |
segments.append({"text": translated_text, "start": segment["start"], "end": segment["end"]})
|
74 |
|
75 |
# Create SRT file
|
|
|
|
|
|
|
|
|
|
|
76 |
with open(srt_path, "w", encoding="utf-8") as f:
|
77 |
for i, segment in enumerate(segments, 1):
|
78 |
start = f"{segment['start']:.3f}".replace(".", ",")
|
79 |
end = f"{segment['end']:.3f}".replace(".", ",")
|
80 |
text = segment["text"].strip()
|
81 |
f.write(f"{i}\n00:00:{start} --> 00:00:{end}\n{text}\n\n")
|
|
|
82 |
print(f"SRT file saved to {srt_path}")
|
|
|
|
|
|
|
|
|
83 |
return srt_path
|
84 |
|
85 |
except subprocess.CalledProcessError as e:
|
|
|
7 |
# Load Whisper model
|
8 |
model = whisper.load_model("base")
|
9 |
|
10 |
+
<<<<<<< HEAD
|
11 |
def process_video(video_path, language):
|
12 |
# Create a temporary directory
|
13 |
temp_dir = tempfile.gettempdir()
|
|
|
17 |
try:
|
18 |
# Convert video to MP4 using ffmpeg
|
19 |
print(f"Converting video: {video_path} to MP4...")
|
20 |
+
=======
|
21 |
+
def process_video(video_path, language, progress=None):
|
22 |
+
output_video_path = os.path.join(tempfile.gettempdir(), "converted_video.mp4")
|
23 |
+
srt_path = os.path.join(tempfile.gettempdir(), "subtitles.srt")
|
24 |
+
|
25 |
+
try:
|
26 |
+
# Convert video to MP4 using ffmpeg
|
27 |
+
if progress:
|
28 |
+
progress(0.2, desc="π Converting video to MP4...")
|
29 |
+
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
|
30 |
subprocess.run(
|
31 |
["ffmpeg", "-i", video_path, "-c:v", "libx264", "-preset", "fast", output_video_path],
|
32 |
check=True,
|
33 |
stdout=subprocess.PIPE,
|
34 |
stderr=subprocess.PIPE
|
35 |
)
|
36 |
+
<<<<<<< HEAD
|
37 |
print("Video converted successfully!")
|
38 |
|
39 |
# Transcribe video
|
40 |
print("Transcribing video...")
|
41 |
result = model.transcribe(output_video_path, language="en")
|
42 |
print("Transcription completed!")
|
43 |
+
=======
|
44 |
+
|
45 |
+
# Transcribe video
|
46 |
+
if progress:
|
47 |
+
progress(0.4, desc="π Transcribing audio...")
|
48 |
+
result = model.transcribe(output_video_path, language="en")
|
49 |
+
if progress:
|
50 |
+
progress(0.6, desc="π Translating subtitles...")
|
51 |
+
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
|
52 |
|
53 |
# Translation logic
|
54 |
segments = []
|
|
|
69 |
}
|
70 |
model_name = model_map.get(language)
|
71 |
if not model_name:
|
72 |
+
return None
|
73 |
|
74 |
# Load translation model
|
75 |
+
<<<<<<< HEAD
|
76 |
print(f"Loading translation model: {model_name}")
|
77 |
+
=======
|
78 |
+
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
|
79 |
if language == "Telugu":
|
80 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
81 |
translation_model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
|
|
97 |
segments.append({"text": translated_text, "start": segment["start"], "end": segment["end"]})
|
98 |
|
99 |
# Create SRT file
|
100 |
+
<<<<<<< HEAD
|
101 |
+
=======
|
102 |
+
if progress:
|
103 |
+
progress(0.8, desc="π Generating SRT file...")
|
104 |
+
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
|
105 |
with open(srt_path, "w", encoding="utf-8") as f:
|
106 |
for i, segment in enumerate(segments, 1):
|
107 |
start = f"{segment['start']:.3f}".replace(".", ",")
|
108 |
end = f"{segment['end']:.3f}".replace(".", ",")
|
109 |
text = segment["text"].strip()
|
110 |
f.write(f"{i}\n00:00:{start} --> 00:00:{end}\n{text}\n\n")
|
111 |
+
<<<<<<< HEAD
|
112 |
print(f"SRT file saved to {srt_path}")
|
113 |
+
=======
|
114 |
+
if progress:
|
115 |
+
progress(1.0, desc="β
Done!")
|
116 |
+
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
|
117 |
return srt_path
|
118 |
|
119 |
except subprocess.CalledProcessError as e:
|