Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,8 @@ import shutil
|
|
| 7 |
from datetime import datetime
|
| 8 |
import traceback
|
| 9 |
import json
|
|
|
|
|
|
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
CORS(app) # Enable CORS for all routes
|
|
@@ -241,87 +243,32 @@ def generate_video():
|
|
| 241 |
data = None
|
| 242 |
print(raw_body)
|
| 243 |
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
if raw_body.startswith("{") or raw_body.startswith("["):
|
| 249 |
-
# Likely JSON, try parsing
|
| 250 |
-
try:
|
| 251 |
-
data = json.loads(raw_body)
|
| 252 |
-
print("✅ Detected valid JSON input.")
|
| 253 |
-
except json.JSONDecodeError:
|
| 254 |
-
# Not valid JSON, fallback to manual parse
|
| 255 |
-
data = None
|
| 256 |
-
|
| 257 |
-
if data is None:
|
| 258 |
-
print("⚙️ Detected raw string input (non-JSON). Parsing manually...")
|
| 259 |
-
|
| 260 |
-
# Handle format like: [ [...], [...]] &&& Tamil explanation
|
| 261 |
-
parts = raw_body.split("&&&&&")
|
| 262 |
-
slides_part = parts[0].strip()
|
| 263 |
-
extra_info = parts[1].strip() if len(parts) > 1 else ""
|
| 264 |
|
| 265 |
-
|
| 266 |
-
slides = json.loads(slides_part)
|
| 267 |
-
except json.JSONDecodeError as e:
|
| 268 |
-
return jsonify({
|
| 269 |
-
"error": "Failed to parse slides JSON from string input",
|
| 270 |
-
"details": str(e),
|
| 271 |
-
"raw_snippet": slides_part[:200]
|
| 272 |
-
}), 400
|
| 273 |
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
"animation": animation,
|
| 283 |
-
"duration": duration
|
| 284 |
-
})'''
|
| 285 |
|
| 286 |
-
data
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
"slides": [
|
| 297 |
-
{
|
| 298 |
-
"type": "title",
|
| 299 |
-
"content": "Projectile Motion Problem : A ball is thrown horizontally from a 20m high cliff with an initial speed of 15 m/s. How far from the base of the cliff does it land?",
|
| 300 |
-
"animation": "fade_in",
|
| 301 |
-
"duration": 1.2
|
| 302 |
-
},
|
| 303 |
-
{
|
| 304 |
-
"type": "text",
|
| 305 |
-
"content": "A ball is thrown horizontally from a 20m high cliff with an initial speed of 15 m/s. How far from the base of the cliff does it land?",
|
| 306 |
-
"animation": "write_left",
|
| 307 |
-
"duration": 1.5
|
| 308 |
-
},
|
| 309 |
-
{
|
| 310 |
-
"type": "text",
|
| 311 |
-
"content": "This is a projectile motion problem with horizontal launch.",
|
| 312 |
-
"animation": "write_left",
|
| 313 |
-
"duration": 0.8
|
| 314 |
-
},
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
{
|
| 318 |
-
"type": "text",
|
| 319 |
-
"content": "The ball lands 30.3 meters from the base of the cliff.",
|
| 320 |
-
"animation": "highlight_left",
|
| 321 |
-
"duration": 1.2
|
| 322 |
-
}
|
| 323 |
-
]
|
| 324 |
-
}
|
| 325 |
# ✅ Final validation
|
| 326 |
if "slides" not in data or not data["slides"]:
|
| 327 |
return jsonify({"error": "No slides provided in request"}), 400
|
|
|
|
| 7 |
from datetime import datetime
|
| 8 |
import traceback
|
| 9 |
import json
|
| 10 |
+
import ast
|
| 11 |
+
import re
|
| 12 |
|
| 13 |
app = Flask(__name__)
|
| 14 |
CORS(app) # Enable CORS for all routes
|
|
|
|
| 243 |
data = None
|
| 244 |
print(raw_body)
|
| 245 |
|
| 246 |
+
lst = raw_body.split("&&&&")
|
| 247 |
+
|
| 248 |
+
# Fix the spacing issue in numbers like "1 . 2" → "1.2"
|
| 249 |
+
cleaned = re.sub(r'(\d)\s*\.\s*(\d)', r'\1.\2', lst[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
+
nlist = ast.literal_eval(cleaned)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
+
datalst=[]
|
| 254 |
+
for line in range(len(nlist)):
|
| 255 |
+
datalst.append({
|
| 256 |
+
"type": nlist[line][0],
|
| 257 |
+
"content": nlist[line][1],
|
| 258 |
+
"animation": nlist[line][2],
|
| 259 |
+
"duration": nlist[line][3]
|
| 260 |
+
})
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
+
data={"video_settings": {
|
| 263 |
+
"background_color": "#0f0f23",
|
| 264 |
+
"text_color": "WHITE",
|
| 265 |
+
"highlight_color": "YELLOW",
|
| 266 |
+
"font": "CMU Serif",
|
| 267 |
+
"text_size": 36,
|
| 268 |
+
"equation_size": 42,
|
| 269 |
+
"title_size": 48
|
| 270 |
+
},
|
| 271 |
+
"slides":datalst}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
# ✅ Final validation
|
| 273 |
if "slides" not in data or not data["slides"]:
|
| 274 |
return jsonify({"error": "No slides provided in request"}), 400
|