Spaces:
Running
Running
Commit
·
091b090
1
Parent(s):
c9a39eb
"LOL"
Browse files- app.py +2 -1
- main.py +2 -2
- src/text_processing.py +5 -5
app.py
CHANGED
@@ -47,6 +47,7 @@ if uploaded_file:
|
|
47 |
with open(file_path, "wb") as f:
|
48 |
f.write(uploaded_file.getbuffer()) # Lưu file thực tế
|
49 |
number_of_images = st.slider("🖼️ Nhập số ảnh",1,10,3)
|
|
|
50 |
# Cấu hình đầu vào
|
51 |
gender = st.radio("🗣️ Select Voice Gender", options=["female", "male"])
|
52 |
|
@@ -98,7 +99,7 @@ def convert_audio_format(video_input, video_output):
|
|
98 |
if st.button("🚀 Generate Video"):
|
99 |
if file_path and os.path.exists(file_path):
|
100 |
st.success("⏳ Processing started...")
|
101 |
-
main(file_path, analysis_level, writting_style, word_lower_limit, word_upper_limit, gender, speed, number_of_images, detail_level, perspective, emotion, time_setting, art_style, style, color_palette)
|
102 |
|
103 |
# Kiểm tra xem video đã được tạo chưa
|
104 |
if os.path.exists(OUTPUT_VIDEO_PATH):
|
|
|
47 |
with open(file_path, "wb") as f:
|
48 |
f.write(uploaded_file.getbuffer()) # Lưu file thực tế
|
49 |
number_of_images = st.slider("🖼️ Nhập số ảnh",1,10,3)
|
50 |
+
chunks = st.slider("📄 Number of chunks", min_value=1, max_value=10, value=3)
|
51 |
# Cấu hình đầu vào
|
52 |
gender = st.radio("🗣️ Select Voice Gender", options=["female", "male"])
|
53 |
|
|
|
99 |
if st.button("🚀 Generate Video"):
|
100 |
if file_path and os.path.exists(file_path):
|
101 |
st.success("⏳ Processing started...")
|
102 |
+
main(file_path, chunks, analysis_level, writting_style, word_lower_limit, word_upper_limit, gender, speed, number_of_images, detail_level, perspective, emotion, time_setting, art_style, style, color_palette)
|
103 |
|
104 |
# Kiểm tra xem video đã được tạo chưa
|
105 |
if os.path.exists(OUTPUT_VIDEO_PATH):
|
main.py
CHANGED
@@ -5,7 +5,7 @@ from src.text_to_video import text_to_video
|
|
5 |
import os
|
6 |
import glob
|
7 |
|
8 |
-
def main(file_path, analysis_level='basic', writting_style='academic', word_lower_limit=100, word_upper_limit = 150, gender = "female", speed = "fast", number_of_images = 3, detail_level="short", perspective="neutral", emotion="sad", time_setting="classic", art_style="realistic", style="anime", color_palette="monochrome"):
|
9 |
# Lấy danh sách tất cả các tệp .txt và .mp3 trong thư mục hiện tại
|
10 |
files_to_delete = glob.glob("*.txt") + glob.glob("*.mp3") + glob.glob("*.png")
|
11 |
|
@@ -14,7 +14,7 @@ def main(file_path, analysis_level='basic', writting_style='academic', word_lowe
|
|
14 |
if file != "requirements.txt":
|
15 |
os.remove(file)
|
16 |
print(f"Deleted: {file}")
|
17 |
-
text_processing(file_path = file_path, analysis_level=analysis_level, writting_style=writting_style, word_lower_limit = word_lower_limit, word_upper_limit=word_upper_limit )
|
18 |
text_to_speech(gender = gender, speed = speed)
|
19 |
image_gen(number_of_images = number_of_images, detail_level=detail_level, perspective=perspective, emotion=emotion, time_setting=time_setting, art_style=art_style, style=style, color_palette=color_palette)
|
20 |
text_to_video()
|
|
|
5 |
import os
|
6 |
import glob
|
7 |
|
8 |
+
def main(file_path, chunks = 3, analysis_level='basic', writting_style='academic', word_lower_limit=100, word_upper_limit = 150, gender = "female", speed = "fast", number_of_images = 3, detail_level="short", perspective="neutral", emotion="sad", time_setting="classic", art_style="realistic", style="anime", color_palette="monochrome"):
|
9 |
# Lấy danh sách tất cả các tệp .txt và .mp3 trong thư mục hiện tại
|
10 |
files_to_delete = glob.glob("*.txt") + glob.glob("*.mp3") + glob.glob("*.png")
|
11 |
|
|
|
14 |
if file != "requirements.txt":
|
15 |
os.remove(file)
|
16 |
print(f"Deleted: {file}")
|
17 |
+
text_processing(file_path = file_path, chunks = chunks, analysis_level=analysis_level, writting_style=writting_style, word_lower_limit = word_lower_limit, word_upper_limit=word_upper_limit )
|
18 |
text_to_speech(gender = gender, speed = speed)
|
19 |
image_gen(number_of_images = number_of_images, detail_level=detail_level, perspective=perspective, emotion=emotion, time_setting=time_setting, art_style=art_style, style=style, color_palette=color_palette)
|
20 |
text_to_video()
|
src/text_processing.py
CHANGED
@@ -40,9 +40,9 @@ def extract_text_from_file(file_path):
|
|
40 |
else:
|
41 |
raise ValueError("Unsupported file format. Only PDF and DOCX are supported.")
|
42 |
####################### - SEMANTIC CHUNKING - #######################
|
43 |
-
def split_text_by_semantics(text, client):
|
44 |
prompt = f"""
|
45 |
-
Bạn là một chuyên gia xử lý văn bản. Hãy chia văn bản sau thành
|
46 |
|
47 |
Văn bản:
|
48 |
{text}
|
@@ -68,7 +68,7 @@ def split_text_by_semantics(text, client):
|
|
68 |
return []
|
69 |
|
70 |
####################### - CONTENT GENERATION - #######################
|
71 |
-
def generate_explaination_for_chunks(chunks, client, analysis_level='basic', writting_style='academic', word_lower_limit=
|
72 |
"""
|
73 |
Phân tích nội dung của văn bản theo mức độ và phong cách mong muốn.
|
74 |
|
@@ -127,14 +127,14 @@ def generate_explaination_for_chunks(chunks, client, analysis_level='basic', wri
|
|
127 |
except Exception as e:
|
128 |
print(f"Lỗi khi gọi API Gemini: {e}")
|
129 |
return []
|
130 |
-
def text_processing(file_path, analysis_level='basic', writting_style='academic', word_lower_limit = 100, word_upper_limit = 150):
|
131 |
client = set_up_api()
|
132 |
# Trích xuất văn bản từ file PDF
|
133 |
text = extract_text_from_file(file_path=file_path)
|
134 |
with open("./text.txt", "w", encoding="utf-8") as f:
|
135 |
f.write(text)
|
136 |
# Tách văn bản theo ngữ nghĩa
|
137 |
-
semantic_chunks = split_text_by_semantics(text, client)
|
138 |
|
139 |
# Tạo thuyết minh cho từng phần semantic chunk
|
140 |
explanations = generate_explaination_for_chunks(semantic_chunks, client, analysis_level=analysis_level, writting_style = writting_style, word_lower_limit = word_lower_limit, word_upper_limit=word_upper_limit)
|
|
|
40 |
else:
|
41 |
raise ValueError("Unsupported file format. Only PDF and DOCX are supported.")
|
42 |
####################### - SEMANTIC CHUNKING - #######################
|
43 |
+
def split_text_by_semantics(text, chunks, client):
|
44 |
prompt = f"""
|
45 |
+
Bạn là một chuyên gia xử lý văn bản. Hãy chia văn bản sau thành {chunks} số đoạn có ý nghĩa sao cho mỗi đoạn vừa đủ để giải thích trong khoảng 3 đến 5 câu.
|
46 |
|
47 |
Văn bản:
|
48 |
{text}
|
|
|
68 |
return []
|
69 |
|
70 |
####################### - CONTENT GENERATION - #######################
|
71 |
+
def generate_explaination_for_chunks(chunks, client, analysis_level='basic', writting_style='academic', word_lower_limit=50, word_upper_limit=100):
|
72 |
"""
|
73 |
Phân tích nội dung của văn bản theo mức độ và phong cách mong muốn.
|
74 |
|
|
|
127 |
except Exception as e:
|
128 |
print(f"Lỗi khi gọi API Gemini: {e}")
|
129 |
return []
|
130 |
+
def text_processing(file_path, chunks = 3, analysis_level='basic', writting_style='academic', word_lower_limit = 100, word_upper_limit = 150):
|
131 |
client = set_up_api()
|
132 |
# Trích xuất văn bản từ file PDF
|
133 |
text = extract_text_from_file(file_path=file_path)
|
134 |
with open("./text.txt", "w", encoding="utf-8") as f:
|
135 |
f.write(text)
|
136 |
# Tách văn bản theo ngữ nghĩa
|
137 |
+
semantic_chunks = split_text_by_semantics(text, chunks, client)
|
138 |
|
139 |
# Tạo thuyết minh cho từng phần semantic chunk
|
140 |
explanations = generate_explaination_for_chunks(semantic_chunks, client, analysis_level=analysis_level, writting_style = writting_style, word_lower_limit = word_lower_limit, word_upper_limit=word_upper_limit)
|