Update app.py
Browse files
app.py
CHANGED
|
@@ -57,44 +57,94 @@ def home():
|
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
-
@app.route("/generate", methods=["POST"])
|
| 61 |
@app.route("/generate", methods=["POST"])
|
| 62 |
def generate_video():
|
| 63 |
try:
|
| 64 |
data = request.get_json()
|
| 65 |
userprompt = data.get("duration", '').strip()
|
| 66 |
-
prompt
|
| 67 |
-
lang
|
| 68 |
-
prompts
|
| 69 |
print(prompts)
|
| 70 |
-
|
| 71 |
if prompts == '':
|
| 72 |
return jsonify({"error": "prompts be must"}), 400
|
| 73 |
-
|
| 74 |
-
#
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
try:
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
except Exception as
|
| 91 |
-
print(
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
return send_file(video_link, mimetype='video/mp4')
|
| 94 |
|
| 95 |
else:
|
| 96 |
-
|
| 97 |
-
|
| 98 |
except Exception as e:
|
| 99 |
traceback.print_exc()
|
| 100 |
return jsonify({"error": str(e)}), 500
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
|
|
|
|
| 60 |
@app.route("/generate", methods=["POST"])
|
| 61 |
def generate_video():
|
| 62 |
try:
|
| 63 |
data = request.get_json()
|
| 64 |
userprompt = data.get("duration", '').strip()
|
| 65 |
+
prompt=extract_english_paragraphs(userprompt)
|
| 66 |
+
lang=extract_native_text(userprompt)
|
| 67 |
+
prompts=prompt.replace("**","")
|
| 68 |
print(prompts)
|
|
|
|
| 69 |
if prompts == '':
|
| 70 |
return jsonify({"error": "prompts be must"}), 400
|
| 71 |
+
image_folder = "/tmp/images"
|
| 72 |
+
#line=prompts.splitlines()
|
| 73 |
+
#asyncio.run(main(line))
|
| 74 |
+
raw_lines = prompts.splitlines(keepends=False)
|
| 75 |
+
lines = []
|
| 76 |
|
| 77 |
+
i = 0
|
| 78 |
+
while i < len(raw_lines):
|
| 79 |
+
line = raw_lines[i].strip()
|
| 80 |
+
|
| 81 |
+
# Check if current line is a heading
|
| 82 |
+
if line.strip().startswith("#") and (line.endswith('?') or line.endswith(':')):
|
| 83 |
+
block = line # Start block with heading
|
| 84 |
+
i += 1
|
| 85 |
+
|
| 86 |
+
# Accumulate body lines until next heading or 5+ lines
|
| 87 |
+
paragraph_lines = []
|
| 88 |
+
while i < len(raw_lines):
|
| 89 |
+
next_line = raw_lines[i].strip()
|
| 90 |
+
|
| 91 |
+
# Stop if next line is a heading
|
| 92 |
+
if next_line.strip().startswith("#") and (next_line.endswith('?') or next_line.endswith(':')):
|
| 93 |
+
break
|
| 94 |
+
|
| 95 |
+
paragraph_lines.append(next_line)
|
| 96 |
+
i += 1
|
| 97 |
+
|
| 98 |
+
# If we've gathered enough lines for a slide, break to next
|
| 99 |
+
if len(paragraph_lines) >= 5:
|
| 100 |
+
break
|
| 101 |
+
|
| 102 |
+
# Combine heading + paragraph
|
| 103 |
+
if paragraph_lines:
|
| 104 |
+
block += '\n' + '\n'.join(paragraph_lines)
|
| 105 |
+
|
| 106 |
+
lines.append(block)
|
| 107 |
+
|
| 108 |
+
else:
|
| 109 |
+
# Group normal lines (not part of any heading)
|
| 110 |
+
block_lines = []
|
| 111 |
+
count = 0
|
| 112 |
+
|
| 113 |
+
while i < len(raw_lines) and count < 5:
|
| 114 |
+
next_line = raw_lines[i].strip()
|
| 115 |
+
|
| 116 |
+
# If this is a heading, break to handle it separately
|
| 117 |
+
if next_line.strip().startswith("#") and (next_line.endswith('?') or next_line.endswith(':')):
|
| 118 |
+
break
|
| 119 |
+
|
| 120 |
+
block_lines.append(next_line)
|
| 121 |
+
i += 1
|
| 122 |
+
count += 1
|
| 123 |
+
|
| 124 |
+
if block_lines:
|
| 125 |
+
lines.append('\n'.join(block_lines))
|
| 126 |
+
|
| 127 |
+
# Print or use lines as slides
|
| 128 |
+
if len(lines)==1:
|
| 129 |
try:
|
| 130 |
+
os.remove("/app/data/video/clip0.mp4")
|
| 131 |
+
os.remove("/app/data/sound/audio0.mp3")
|
| 132 |
+
except Exception as e:
|
| 133 |
+
print(e)
|
| 134 |
+
#image_folder="/tmp/images"
|
| 135 |
+
#image_olst=[]
|
| 136 |
+
#create_text_image(lines[0],0,image_olst)
|
| 137 |
+
#image_files = sorted(glob.glob(os.path.join(image_folder, "*.png")))
|
| 138 |
+
#if not image_files:
|
| 139 |
+
#raise ValueError("No images found in folder!")
|
| 140 |
+
video_link1 = "/app/data/video/clip0.mp4"
|
| 141 |
+
video_link=video_func(0,lines,lang)
|
| 142 |
+
#for img in image_files:
|
| 143 |
+
#os.remove(img)
|
| 144 |
return send_file(video_link, mimetype='video/mp4')
|
| 145 |
|
| 146 |
else:
|
| 147 |
+
print("learn deeper")
|
|
|
|
| 148 |
except Exception as e:
|
| 149 |
traceback.print_exc()
|
| 150 |
return jsonify({"error": str(e)}), 500
|