rairo commited on
Commit
d04b508
·
verified ·
1 Parent(s): 8dd936e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +53 -0
main.py CHANGED
@@ -560,6 +560,59 @@ def update_narration_audio(project_id):
560
  except Exception as e:
561
  logger.error(f"CRITICAL ERROR updating narration for {project_id}: {traceback.format_exc()}")
562
  return jsonify({'error': str(e)}), 500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
563
  # -----------------------------------------------------------------------------
564
  # 5. UNIVERSAL ENDPOINTS (Waitlist, Feedback, Credits)
565
  # -----------------------------------------------------------------------------
 
560
  except Exception as e:
561
  logger.error(f"CRITICAL ERROR updating narration for {project_id}: {traceback.format_exc()}")
562
  return jsonify({'error': str(e)}), 500
563
+
564
+ # In main.py, add this new endpoint
565
+
566
+ @app.route('/api/sozo/projects/<string:project_id>/generate-slides', methods=['POST'])
567
+ def generate_sozo_slides(project_id):
568
+ logger.info(f"POST /api/sozo/projects/{project_id}/generate-slides - Generating slides")
569
+ try:
570
+ token = request.headers.get('Authorization', '').split(' ')
571
+ uid = verify_token(token)
572
+ if not uid:
573
+ return jsonify({'error': 'Unauthorized'}), 401
574
+
575
+ project_ref = db.reference(f'sozo_projects/{project_id}')
576
+ project_data = project_ref.get()
577
+
578
+ if not project_data or project_data.get('uid') != uid:
579
+ return jsonify({'error': 'Project not found or unauthorized'}), 404
580
+
581
+ raw_md = project_data.get('rawMarkdown')
582
+ chart_urls = project_data.get('chartUrls', {})
583
+
584
+ if not raw_md:
585
+ return jsonify({'error': 'Report must be generated before slides can be created.'}), 400
586
+
587
+ # The planner AI needs an LLM instance
588
+ llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash", google_api_key=os.getenv("GOOGLE_API_KEY"), temperature=0.2)
589
+
590
+ slides_data = generate_slides_from_report(
591
+ raw_md,
592
+ chart_urls,
593
+ uid,
594
+ project_id,
595
+ bucket,
596
+ llm
597
+ )
598
+
599
+ if not slides_data:
600
+ raise Exception("Slide generation failed in core function.")
601
+
602
+ # Save the slides data to the project in Firebase
603
+ project_ref.update({'slides': slides_data})
604
+
605
+ logger.info(f"Project {project_id} successfully updated with {len(slides_data)} slides.")
606
+
607
+ return jsonify({
608
+ 'success': True,
609
+ 'slides': slides_data
610
+ }), 200
611
+
612
+ except Exception as e:
613
+ logger.error(f"CRITICAL error generating slides for project {project_id}: {traceback.format_exc()}")
614
+ db.reference(f'sozo_projects/{project_id}').update({'status': 'failed_slides', 'error': str(e)})
615
+ return jsonify({'error': str(e)}), 500
616
  # -----------------------------------------------------------------------------
617
  # 5. UNIVERSAL ENDPOINTS (Waitlist, Feedback, Credits)
618
  # -----------------------------------------------------------------------------