Hieucyber2208 commited on
Commit
f24d831
·
verified ·
1 Parent(s): f87ca8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -30
app.py CHANGED
@@ -8,11 +8,9 @@ except RuntimeError:
8
  import streamlit as st
9
  from main import main
10
  import os
11
- import subprocess
12
 
13
  # Định nghĩa đường dẫn video đầu ra
14
  OUTPUT_VIDEO_PATH = "final_output.mp4"
15
- OUTPUT_VIDEO_FIXED_PATH = "final_output_fixed.mp4"
16
 
17
  # Tiêu đề ứng dụng
18
  st.set_page_config(page_title="KnowFlow", page_icon="📖")
@@ -38,7 +36,7 @@ KnowFlow automates the process of converting lecture documents (PDF, DOCX) into
38
  If you find it's slow, then another person must be using the GPU. Please wait!!
39
  """)
40
  # Upload file PDF
41
- uploaded_file = st.file_uploader("📂 Upload your document (PDF)", type=["pdf","docx"])
42
 
43
  # Nếu có file, lưu vào thư mục tạm và lấy đường dẫn
44
  file_path = None
@@ -46,7 +44,9 @@ if uploaded_file:
46
  file_path = f"{uploaded_file.name}"
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
 
@@ -55,8 +55,9 @@ if gender == "male":
55
  speed = st.radio("⚡ Speech Speed (Male voice supports only normal)", options=["normal"], disabled=True)
56
  else:
57
  speed = st.radio("⚡ Speech Speed", options=["fast", "normal", "slow"])
 
58
  analysis_level = st.radio("Analysis Level", options=["basic", "detailed"])
59
- writting_style = st.radio("Writting Style", options = ["academic","popular","creative","humorous"])
60
 
61
  # Tạo thanh trượt với giá trị từ 50 đến 250, bước nhảy 50
62
  word_lower_limit, word_upper_limit = st.slider(
@@ -68,6 +69,7 @@ word_lower_limit, word_upper_limit = st.slider(
68
  )
69
 
70
  st.write(f"Giới hạn độ dài văn bản từ **{word_lower_limit}** đến **{word_upper_limit}** ký tự.")
 
71
  detail_level = st.radio("📖 Detail Level of Image Description", options=["short", "detailed"])
72
  perspective = st.radio("🔎 Perspective", options=["subjective", "neutral"])
73
  emotion = st.text_input("🎭 Emotion", placeholder="Example: mysterious, romantic,...")
@@ -76,41 +78,20 @@ art_style = st.text_input("🖌️ Image Description Style", placeholder="Exampl
76
  style = st.text_input("🎨 Image Style", placeholder="Example: realistic, anime,...")
77
  color_palette = st.text_input("🌈 Color Palette", placeholder="Example: vibrant, monochrome,...")
78
 
79
- def convert_audio_format(video_input, video_output):
80
- """Chuyển đổi định dạng âm thanh của video sang AAC."""
81
- if not os.path.exists(video_input):
82
- raise FileNotFoundError(f"File '{video_input}' không tồn tại!")
83
-
84
- command = [
85
- "ffmpeg", "-i", video_input,
86
- "-c:v", "copy", "-c:a", "aac", "-b:a", "192k",
87
- "-y", # Ghi đè nếu file output đã tồn tại
88
- video_output
89
- ]
90
-
91
- try:
92
- subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
93
- print(f"✅ Chuyển đổi thành công: {video_output}")
94
- except subprocess.CalledProcessError as e:
95
- print(f"❌ Lỗi khi chuyển đổi video: {e.stderr.decode()}")
96
-
97
  # Nút chạy pipeline
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):
105
  st.success("🎉 Video generated successfully!")
106
-
107
- # Chuyển đổi định dạng âm thanh
108
- convert_audio_format(OUTPUT_VIDEO_PATH, OUTPUT_VIDEO_FIXED_PATH)
109
 
110
  # Tạo link tải về
111
- with open(OUTPUT_VIDEO_FIXED_PATH, "rb") as video_file:
112
- st.download_button(label="📥 Download Video", data=video_file, file_name="final_output_fixed.mp4", mime="video/mp4")
113
  else:
114
  st.error("⚠️ Video generation failed. Please check the logs.")
115
  else:
116
- st.error("⚠️ Please upload a valid PDF file.")
 
8
  import streamlit as st
9
  from main import main
10
  import os
 
11
 
12
  # Định nghĩa đường dẫn video đầu ra
13
  OUTPUT_VIDEO_PATH = "final_output.mp4"
 
14
 
15
  # Tiêu đề ứng dụng
16
  st.set_page_config(page_title="KnowFlow", page_icon="📖")
 
36
  If you find it's slow, then another person must be using the GPU. Please wait!!
37
  """)
38
  # Upload file PDF
39
+ uploaded_file = st.file_uploader("📂 Upload your document (PDF)", type=["pdf", "docx"])
40
 
41
  # Nếu có file, lưu vào thư mục tạm và lấy đường dẫn
42
  file_path = None
 
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
+
48
+ number_of_images = st.slider("🖼️ Nhập số ảnh", 1, 10, 3)
49
+
50
  # Cấu hình đầu vào
51
  gender = st.radio("🗣️ Select Voice Gender", options=["female", "male"])
52
 
 
55
  speed = st.radio("⚡ Speech Speed (Male voice supports only normal)", options=["normal"], disabled=True)
56
  else:
57
  speed = st.radio("⚡ Speech Speed", options=["fast", "normal", "slow"])
58
+
59
  analysis_level = st.radio("Analysis Level", options=["basic", "detailed"])
60
+ writing_style = st.radio("Writing Style", options=["academic", "popular", "creative", "humorous"])
61
 
62
  # Tạo thanh trượt với giá trị từ 50 đến 250, bước nhảy 50
63
  word_lower_limit, word_upper_limit = st.slider(
 
69
  )
70
 
71
  st.write(f"Giới hạn độ dài văn bản từ **{word_lower_limit}** đến **{word_upper_limit}** ký tự.")
72
+
73
  detail_level = st.radio("📖 Detail Level of Image Description", options=["short", "detailed"])
74
  perspective = st.radio("🔎 Perspective", options=["subjective", "neutral"])
75
  emotion = st.text_input("🎭 Emotion", placeholder="Example: mysterious, romantic,...")
 
78
  style = st.text_input("🎨 Image Style", placeholder="Example: realistic, anime,...")
79
  color_palette = st.text_input("🌈 Color Palette", placeholder="Example: vibrant, monochrome,...")
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  # Nút chạy pipeline
82
  if st.button("🚀 Generate Video"):
83
  if file_path and os.path.exists(file_path):
84
  st.success("⏳ Processing started...")
85
+ main(file_path, analysis_level, writing_style, word_lower_limit, word_upper_limit, gender, speed, number_of_images, detail_level, perspective, emotion, time_setting, art_style, style, color_palette)
86
 
87
  # Kiểm tra xem video đã được tạo chưa
88
  if os.path.exists(OUTPUT_VIDEO_PATH):
89
  st.success("🎉 Video generated successfully!")
 
 
 
90
 
91
  # Tạo link tải về
92
+ with open(OUTPUT_VIDEO_PATH, "rb") as video_file:
93
+ st.download_button(label="📥 Download Video", data=video_file, file_name="final_output.mp4", mime="video/mp4")
94
  else:
95
  st.error("⚠️ Video generation failed. Please check the logs.")
96
  else:
97
+ st.error("⚠️ Please upload a valid PDF file.")