hieu-nguyen2208 commited on
Commit
6273f21
·
1 Parent(s): 7a96ad1
app.py CHANGED
@@ -21,8 +21,8 @@ genai.configure(api_key=GOOGLE_API_KEY)
21
  client = InferenceClient(provider="hf-inference", api_key=HF_TOKEN)
22
 
23
  # Định nghĩa đường dẫn video đầu ra
24
- OUTPUT_VIDEO_PATH = "./final_output.mp4"
25
- OUTPUT_VIDEO_FIXED_PATH = "./final_output_fixed.mp4"
26
 
27
  # Tiêu đề ứng dụng
28
  st.set_page_config(page_title="KnowFlow", page_icon="📖")
@@ -41,7 +41,7 @@ uploaded_file = st.file_uploader("📂 Upload your document (PDF)", type=["pdf",
41
  # Nếu có file, lưu vào thư mục tạm và lấy đường dẫn
42
  file_path = None
43
  if uploaded_file:
44
- file_path = f"./{uploaded_file.name}"
45
  with open(file_path, "wb") as f:
46
  f.write(uploaded_file.getbuffer()) # Lưu file thực tế
47
  number_of_images = st.slider("🖼️ Nhập số ảnh",1,10,3)
 
21
  client = InferenceClient(provider="hf-inference", api_key=HF_TOKEN)
22
 
23
  # Định nghĩa đường dẫn video đầu ra
24
+ OUTPUT_VIDEO_PATH = "final_output.mp4"
25
+ OUTPUT_VIDEO_FIXED_PATH = "final_output_fixed.mp4"
26
 
27
  # Tiêu đề ứng dụng
28
  st.set_page_config(page_title="KnowFlow", page_icon="📖")
 
41
  # Nếu có file, lưu vào thư mục tạm và lấy đường dẫn
42
  file_path = None
43
  if uploaded_file:
44
+ file_path = f"{uploaded_file.name}"
45
  with open(file_path, "wb") as f:
46
  f.write(uploaded_file.getbuffer()) # Lưu file thực tế
47
  number_of_images = st.slider("🖼️ Nhập số ảnh",1,10,3)
data/BeVietnamPro-Light.ttf DELETED
Binary file (135 kB)
 
main.py CHANGED
@@ -3,11 +3,8 @@ from src.text_to_speech import text_to_speech
3
  from src.image_gen import image_gen
4
  from src.text_to_video import text_to_video
5
  import os
6
- def main(file_path = "./data/input/sample.pdf", 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"):
7
  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 )
8
  text_to_speech(gender = gender, speed = speed)
9
  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)
10
- text_to_video()
11
-
12
- if __name__ == "__main__":
13
- main(file_path="./data/input/sample_2.pdf")
 
3
  from src.image_gen import image_gen
4
  from src.text_to_video import text_to_video
5
  import os
6
+ 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"):
7
  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 )
8
  text_to_speech(gender = gender, speed = speed)
9
  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)
10
+ text_to_video()
 
 
 
src/image_gen.py CHANGED
@@ -16,7 +16,7 @@ genai.configure(api_key=GOOGLE_API_KEY)
16
  client = InferenceClient(provider="hf-inference", api_key=HF_TOKEN)
17
 
18
  def split_text_for_images(number_of_images):
19
- with open("./text.txt", "r", encoding="utf-8") as file:
20
  text = file.read().strip()
21
 
22
  total_length = len(text)
@@ -101,7 +101,7 @@ def image_gen(number_of_images = 3,detail_level = "short", perspective="neutral"
101
  texts = split_text_for_images(number_of_images)
102
  index = 0
103
  for text in tqdm(texts, desc="Processing", unit="image"):
104
- output_path = f"./{index}.png"
105
  prompt = describe_image(text, detail_level, perspective, emotion, time_setting, art_style)
106
  print(prompt)
107
 
@@ -120,6 +120,4 @@ def image_gen(number_of_images = 3,detail_level = "short", perspective="neutral"
120
  wait_time = 2 ** retry_count + random.uniform(0, 1) # Exponential backoff
121
  print(f"Thử lại sau {wait_time:.2f} giây...")
122
  time.sleep(wait_time)
123
- index += 1
124
- if __name__ == "__main__":
125
- image_gen(number_of_images = 3, detail_level="short", perspective="neutral", emotion="sad", time_setting="classic", art_style="realistic", style="anime", color_palette="monochrome")
 
16
  client = InferenceClient(provider="hf-inference", api_key=HF_TOKEN)
17
 
18
  def split_text_for_images(number_of_images):
19
+ with open("text.txt", "r", encoding="utf-8") as file:
20
  text = file.read().strip()
21
 
22
  total_length = len(text)
 
101
  texts = split_text_for_images(number_of_images)
102
  index = 0
103
  for text in tqdm(texts, desc="Processing", unit="image"):
104
+ output_path = f"{index}.png"
105
  prompt = describe_image(text, detail_level, perspective, emotion, time_setting, art_style)
106
  print(prompt)
107
 
 
120
  wait_time = 2 ** retry_count + random.uniform(0, 1) # Exponential backoff
121
  print(f"Thử lại sau {wait_time:.2f} giây...")
122
  time.sleep(wait_time)
123
+ index += 1
 
 
src/text_processing.py CHANGED
@@ -15,7 +15,7 @@ def extract_text_from_pdf(pdf_path):
15
  text = ""
16
  for page_num in range(doc.page_count):
17
  page = doc.load_page(page_num)
18
- text += page.get_text()
19
  return text
20
 
21
  def extract_text_from_docx(docx_path):
@@ -145,7 +145,4 @@ def text_processing(file_path, analysis_level='basic', writting_style='academic'
145
  output_file = os.path.join(output_dir, f"{chunk_idx}_{sentence_idx}.txt") # Tên file dạng "chunkID_sentenceID.txt"
146
  with open(output_file, "w", encoding="utf-8") as f:
147
  f.write(sentence.replace("*","") + ".") # Giữ dấu chấm cuối câu
148
- print(f"Đã lưu: {output_file}")
149
- ####################### - MAIN CODE - #######################
150
- if __name__ == "__main__":
151
- text_processing(file_path = "./input/sample_3.pdf")
 
15
  text = ""
16
  for page_num in range(doc.page_count):
17
  page = doc.load_page(page_num)
18
+ text += page.get_text()
19
  return text
20
 
21
  def extract_text_from_docx(docx_path):
 
145
  output_file = os.path.join(output_dir, f"{chunk_idx}_{sentence_idx}.txt") # Tên file dạng "chunkID_sentenceID.txt"
146
  with open(output_file, "w", encoding="utf-8") as f:
147
  f.write(sentence.replace("*","") + ".") # Giữ dấu chấm cuối câu
148
+ print(f"Đã lưu: {output_file}")
 
 
 
src/text_to_speech.py CHANGED
@@ -42,11 +42,9 @@ def generate_audio(text, filename="output.mp3", gender="female", speed="normal")
42
  print("⚠️ Giọng không hợp lệ! Chỉ hỗ trợ 'male' hoặc 'female'.")
43
  def text_to_speech(gender, speed):
44
  text_folder = "./"
45
- text_files = sorted([f for f in os.listdir(text_folder) if f.endswith('.txt') and f != "text.txt"])
46
  for text_file in text_files:
47
- with open(f"./text/{text_file}", "r", encoding="utf-8") as file:
48
  content = file.read()
49
  audio_file = text_file.replace("txt","mp3")
50
- generate_audio(content, f"./audio/{audio_file}", gender=gender, speed=speed)
51
- if __name__ == "__main__":
52
- text_to_speech(gender = "female", speed = "fast")
 
42
  print("⚠️ Giọng không hợp lệ! Chỉ hỗ trợ 'male' hoặc 'female'.")
43
  def text_to_speech(gender, speed):
44
  text_folder = "./"
45
+ text_files = sorted([f for f in os.listdir(text_folder) if f.endswith('.txt') and f != "text.txt" and f != "requirements.txt"])
46
  for text_file in text_files:
47
+ with open(f"{text_file}", "r", encoding="utf-8") as file:
48
  content = file.read()
49
  audio_file = text_file.replace("txt","mp3")
50
+ generate_audio(content, f"{audio_file}", gender=gender, speed=speed)