-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathmain.py
88 lines (65 loc) · 2.19 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import uvicorn
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from starlette.requests import Request
from starlette.staticfiles import StaticFiles
from starlette.responses import HTMLResponse, JSONResponse
from admin.databases import engine
from admin import models, views
"""
第一步、将用户输入的文本进行切割,按照逗号或者句号切割
需要的数据,text, bookname
bookname: 书名
text: 书内容文本
输出的数据,[text,text,...]
第二步、使用chatGPT生成提示词
需要的的数据 [text,text,...]
输出的数据,[{text,index,prompt,negative},...]
text:原文本
index:原文本坐标
prompt:英文提示词
negative:英文反向提示词
第三步、调用百度语音合成包进行语音合成
需要的的数据 [{text,index}, {text,index},...]
输出的数据,[index.wav, index.wav, ...]
第四步、使用stable diffusion生成图片
需要的的数据 [{prompt, negative, index},...]
输出的数据,[index.png, index.png, ...]
第五步、使用moviepy将图片和语音结合起来生成视频
需要的的数据 [{index.png, index.wav},...]
输出的数据,[index.mp4, ...]
"""
models.Base.metadata.create_all(bind=engine)
app = FastAPI()
origins = [
"*",
]
async def catch_exceptions_middleware(request: Request, call_next):
try:
return await call_next(request)
except Exception as e:
return JSONResponse({"code": 0, "message": str(e)}, status_code=200)
app.middleware('http')(catch_exceptions_middleware)
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/", response_class=HTMLResponse)
async def root():
return open("dist/index.html", 'r').read()
@app.get("/hello/{name}")
async def say_hello(name: str):
return {"message": f"Hello {name}"}
app.include_router(
views.router,
prefix="",
tags=["后台"],
responses={404: {"description": "Not found"}},
)
app.mount('/media', StaticFiles(directory="media"), 'media')
app.mount('', StaticFiles(directory="dist"), 'dist')
if __name__ == '__main__':
uvicorn.run("main:app", host="localhost", port=8001, reload=True)