Spaces:
Running
on
Zero
Running
on
Zero
malvin noel
commited on
Commit
Β·
454765e
1
Parent(s):
046681b
changes spaces
Browse files- app.py +0 -1
- scripts/generate_scripts.py +7 -6
- scripts/generate_subtitles.py +4 -0
- scripts/generate_voice.py +3 -1
app.py
CHANGED
@@ -30,7 +30,6 @@ def safe_copy(src: str, dst: str) -> str:
|
|
30 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
31 |
# Core processing pipeline
|
32 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
33 |
-
@spaces.GPU()
|
34 |
def process_video(
|
35 |
context: str,
|
36 |
instruction: str,
|
|
|
30 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
31 |
# Core processing pipeline
|
32 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
33 |
def process_video(
|
34 |
context: str,
|
35 |
instruction: str,
|
scripts/generate_scripts.py
CHANGED
@@ -5,6 +5,7 @@ import torch
|
|
5 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
6 |
import gradio as gr
|
7 |
from dotenv import load_dotenv
|
|
|
8 |
|
9 |
|
10 |
# Chargement du modèle et du tokenizer
|
@@ -17,7 +18,7 @@ model_id = "Qwen/Qwen2.5-0.5B"
|
|
17 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
18 |
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float32, trust_remote_code=True).to(device)
|
19 |
|
20 |
-
|
21 |
def generate_local(prompt: str, max_new_tokens: int = 350, temperature: float = 0.7) -> str:
|
22 |
device = model.device # get the device the model is on
|
23 |
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
@@ -32,7 +33,7 @@ def generate_local(prompt: str, max_new_tokens: int = 350, temperature: float =
|
|
32 |
return tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
33 |
|
34 |
|
35 |
-
|
36 |
def generate_script(prompt: str, word_count: int = 60) -> str:
|
37 |
system_prompt = (
|
38 |
"You are a professional video scriptwriter. "
|
@@ -41,7 +42,7 @@ def generate_script(prompt: str, word_count: int = 60) -> str:
|
|
41 |
)
|
42 |
return generate_local(system_prompt)
|
43 |
|
44 |
-
|
45 |
def one_word(query: str) -> str:
|
46 |
prompt_final = (
|
47 |
"Extract only the unique central theme of the following text in English in JSON format like this: "
|
@@ -56,7 +57,7 @@ def one_word(query: str) -> str:
|
|
56 |
keyword = matches[0] if matches else ""
|
57 |
return keyword.lower()
|
58 |
|
59 |
-
|
60 |
def generate_title(text: str) -> str:
|
61 |
prompt_final = (
|
62 |
"Generate a unique title for a YouTube Short video that is engaging and informative, "
|
@@ -64,7 +65,7 @@ def generate_title(text: str) -> str:
|
|
64 |
)
|
65 |
return generate_local(prompt_final, max_new_tokens=50, temperature=0.9).strip()
|
66 |
|
67 |
-
|
68 |
def generate_description(text: str) -> str:
|
69 |
prompt_final = (
|
70 |
"Write only the YouTube video description in English:\n"
|
@@ -75,7 +76,7 @@ def generate_description(text: str) -> str:
|
|
75 |
)
|
76 |
return generate_local(prompt_final, max_new_tokens=300, temperature=0.7).strip()
|
77 |
|
78 |
-
|
79 |
def generate_tags(text: str) -> list:
|
80 |
prompt_final = (
|
81 |
"List only the important keywords for this YouTube video, separated by commas, "
|
|
|
5 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
6 |
import gradio as gr
|
7 |
from dotenv import load_dotenv
|
8 |
+
import spaces
|
9 |
|
10 |
|
11 |
# Chargement du modèle et du tokenizer
|
|
|
18 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
19 |
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float32, trust_remote_code=True).to(device)
|
20 |
|
21 |
+
@spaces.GPU()
|
22 |
def generate_local(prompt: str, max_new_tokens: int = 350, temperature: float = 0.7) -> str:
|
23 |
device = model.device # get the device the model is on
|
24 |
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
|
|
33 |
return tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
34 |
|
35 |
|
36 |
+
@spaces.GPU()
|
37 |
def generate_script(prompt: str, word_count: int = 60) -> str:
|
38 |
system_prompt = (
|
39 |
"You are a professional video scriptwriter. "
|
|
|
42 |
)
|
43 |
return generate_local(system_prompt)
|
44 |
|
45 |
+
@spaces.GPU()
|
46 |
def one_word(query: str) -> str:
|
47 |
prompt_final = (
|
48 |
"Extract only the unique central theme of the following text in English in JSON format like this: "
|
|
|
57 |
keyword = matches[0] if matches else ""
|
58 |
return keyword.lower()
|
59 |
|
60 |
+
@spaces.GPU()
|
61 |
def generate_title(text: str) -> str:
|
62 |
prompt_final = (
|
63 |
"Generate a unique title for a YouTube Short video that is engaging and informative, "
|
|
|
65 |
)
|
66 |
return generate_local(prompt_final, max_new_tokens=50, temperature=0.9).strip()
|
67 |
|
68 |
+
@spaces.GPU()
|
69 |
def generate_description(text: str) -> str:
|
70 |
prompt_final = (
|
71 |
"Write only the YouTube video description in English:\n"
|
|
|
76 |
)
|
77 |
return generate_local(prompt_final, max_new_tokens=300, temperature=0.7).strip()
|
78 |
|
79 |
+
@spaces.GPU()
|
80 |
def generate_tags(text: str) -> list:
|
81 |
prompt_final = (
|
82 |
"List only the important keywords for this YouTube video, separated by commas, "
|
scripts/generate_subtitles.py
CHANGED
@@ -12,6 +12,8 @@ from moviepy import (
|
|
12 |
vfx
|
13 |
)
|
14 |
from moviepy.video.fx import FadeIn, Resize
|
|
|
|
|
15 |
|
16 |
|
17 |
FONT_PATH = "Arial-Bold"
|
@@ -81,6 +83,8 @@ def save_subtitles_to_srt(subtitles, output_path):
|
|
81 |
f.write(f"{format_timestamp(sub['start'])} --> {format_timestamp(sub['end'])}\n")
|
82 |
f.write(f"{sub['text'].strip()}\n\n")
|
83 |
|
|
|
|
|
84 |
def transcribe_audio_to_subs(audio_path):
|
85 |
"""
|
86 |
Transcrit le fichier audio en texte (via Whisper), retourne la liste
|
|
|
12 |
vfx
|
13 |
)
|
14 |
from moviepy.video.fx import FadeIn, Resize
|
15 |
+
import spaces
|
16 |
+
|
17 |
|
18 |
|
19 |
FONT_PATH = "Arial-Bold"
|
|
|
83 |
f.write(f"{format_timestamp(sub['start'])} --> {format_timestamp(sub['end'])}\n")
|
84 |
f.write(f"{sub['text'].strip()}\n\n")
|
85 |
|
86 |
+
|
87 |
+
@spaces.GPU()
|
88 |
def transcribe_audio_to_subs(audio_path):
|
89 |
"""
|
90 |
Transcrit le fichier audio en texte (via Whisper), retourne la liste
|
scripts/generate_voice.py
CHANGED
@@ -2,6 +2,8 @@ import os
|
|
2 |
import soundfile as sf
|
3 |
from kokoro import KPipeline
|
4 |
import random
|
|
|
|
|
5 |
|
6 |
pipeline = KPipeline(lang_code='a') # 'a' for English
|
7 |
|
@@ -12,7 +14,7 @@ ENGLISH_VOICES = [
|
|
12 |
"am_fenrir"
|
13 |
]
|
14 |
|
15 |
-
|
16 |
def generate_voice(text: str, path: str):
|
17 |
for voice in random.sample(ENGLISH_VOICES, len(ENGLISH_VOICES)):
|
18 |
try:
|
|
|
2 |
import soundfile as sf
|
3 |
from kokoro import KPipeline
|
4 |
import random
|
5 |
+
import spaces
|
6 |
+
|
7 |
|
8 |
pipeline = KPipeline(lang_code='a') # 'a' for English
|
9 |
|
|
|
14 |
"am_fenrir"
|
15 |
]
|
16 |
|
17 |
+
@spaces.GPU()
|
18 |
def generate_voice(text: str, path: str):
|
19 |
for voice in random.sample(ENGLISH_VOICES, len(ENGLISH_VOICES)):
|
20 |
try:
|