-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
55 lines (43 loc) · 1.52 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from flask import Flask, request, jsonify, send_from_directory
from pathlib import Path
import sys, json, logging
import os
# os.environ["IMAGEIO_FFMPEG_EXE"] = "/opt/homebrew/bin/ffmpeg"
os.environ["IMAGEIO_FFMPEG_EXE"] = "/usr/bin/ffmpeg"
path_root = Path(__file__).parents[2]
sys.path.append(str(path_root))
import generate_story
from moviepy.config import change_settings
from logging.config import dictConfig
# change_settings({"FFMPEG_BINARY": "/opt/homebrew/bin/ffmpeg"})
change_settings({"FFMPEG_BINARY": "/usr/bin/ffmpeg"})
dictConfig({
'version': 1,
'formatters': {'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
}},
'handlers': {'wsgi': {
'class': 'logging.StreamHandler',
'formatter': 'default'
}},
'root': {
'level': 'DEBUG',
'handlers': ['wsgi']
}
})
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = "/storage/"
@app.route('/health')
def say_hello():
return 'OK'
@app.route('/api/v1/generate', methods=['POST'])
def generate():
print(request.json)
logging.info('got generate story request: {}'.format(request.json))
output_file = generate_story.generate_story_video_from_config(request.json)
if output_file is None:
return jsonify({'error': {'id': '1', 'message': 'cannot generate video'}}), 500
return jsonify({'video': {'type': 'file', 'file_name': output_file}})
@app.route('/videos/<path:path>')
def send_report(path):
return send_from_directory('storage/video/generated/8c3de4dd', path)