sreepathi-ravikumar commited on
Commit
2fde59e
·
verified ·
1 Parent(s): 1cd611d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -1,15 +1,14 @@
1
  from flask import Flask, request, jsonify, send_file
2
- from moviepy.editor import ColorClip,ImageClip, concatenate_videoclips,VideoFileClip
3
  import traceback
4
  import uuid
5
  import glob
6
  import os
7
- import asyncio
8
  from image_fetcher import main
9
  from video import create_text_image
10
  from video2 import video_func
11
 
12
- app = Flask(__name__)
13
 
14
  @app.route("/")
15
  def home():
@@ -21,31 +20,33 @@ def generate_video():
21
  data = request.get_json()
22
  id = data["id"]
23
  lines = data["lines"]
 
24
  image_folder = "/tmp/images"
25
- #line=prompts.splitlines()
26
- #asyncio.run(main(line))
 
 
 
 
 
 
 
 
 
27
 
28
-
29
- image_olst=[]
30
- create_text_image(lines[id],id,image_olst)
31
  image_files = sorted(glob.glob(os.path.join(image_folder, "*.png")))
32
- video_path = video_func(id,lines)
33
  for img in image_files:
34
  os.remove(img)
35
 
36
- # Your existing processing logic
37
- # create_text_image, video_func, etc.
38
-
39
- video_path = video_func(id, lines)
40
- print(video_path,"--------------------------------video_path-------------------------------")
41
-
42
- return send_file(video_path, mimetype='video/mp4')
43
 
44
  except Exception as e:
 
45
  return jsonify({"error": str(e)}), 500
46
-
47
-
48
- if __name__ == "__main__":
49
- app.run(host="0.0.0.0", port=7860)
50
 
51
- # Example call (remove or change in your actual app)
 
 
1
  from flask import Flask, request, jsonify, send_file
2
+ from moviepy.editor import ColorClip, ImageClip, concatenate_videoclips, VideoFileClip
3
  import traceback
4
  import uuid
5
  import glob
6
  import os
 
7
  from image_fetcher import main
8
  from video import create_text_image
9
  from video2 import video_func
10
 
11
+ app = Flask(_name_)
12
 
13
  @app.route("/")
14
  def home():
 
20
  data = request.get_json()
21
  id = data["id"]
22
  lines = data["lines"]
23
+
24
  image_folder = "/tmp/images"
25
+ image_olst = []
26
+
27
+ # 1. Create Image
28
+ create_text_image(lines[id], id, image_olst)
29
+
30
+ # 2. Generate Video (Only once!)
31
+ video_path = video_func(id, lines)
32
+
33
+ # 3. Check video exists
34
+ if not os.path.exists(video_path):
35
+ raise Exception("Video not found: " + video_path)
36
 
37
+ print("Generated video at:", video_path)
38
+
39
+ # 4. Cleanup images
40
  image_files = sorted(glob.glob(os.path.join(image_folder, "*.png")))
 
41
  for img in image_files:
42
  os.remove(img)
43
 
44
+ # 5. Return video
45
+ return send_file(video_path, mimetype='video/mp4', as_attachment=True)
 
 
 
 
 
46
 
47
  except Exception as e:
48
+ traceback.print_exc()
49
  return jsonify({"error": str(e)}), 500
 
 
 
 
50
 
51
+ if _name_ == "_main_":
52
+ app.run(host="0.0.0.0", port=7860)