Skip to content

Commit 2d0f2c9

Browse files
author
李茂益
committed
提交html界面
1 parent 66c420d commit 2d0f2c9

30 files changed

+509
-211
lines changed

application.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import datetime
2+
import logging
23
import uuid
34

4-
from flask import Flask, request, make_response, render_template, Response
5+
from flask import Flask, request, make_response, render_template, Response, send_from_directory
6+
from flask_cors import CORS
57

68
from generation.gen_ppt_outline import GenBody, GenTitle, GenOutline
79
from mdtree.tree2ppt import Tree2PPT
8-
import logging
9-
from flask_cors import CORS
10-
1110

1211
app = Flask(__name__)
1312
# 设置日志级别
@@ -30,12 +29,26 @@
3029
CORS(app)
3130

3231

33-
3432
@app.route('/')
3533
def index():
3634
return render_template('index.html')
3735

3836

37+
@app.route('/static/js/<filename>')
38+
def serve_js(filename):
39+
return send_from_directory('./templates/static/js', filename)
40+
41+
42+
@app.route('/static/css/<filename>')
43+
def serve_css(filename):
44+
return send_from_directory('./templates/static/css', filename)
45+
46+
47+
@app.route('/static/media/<filename>')
48+
def serve_media(filename):
49+
return send_from_directory('./templates/static/media', filename)
50+
51+
3952
@app.route('/auto-ppt/gen-uuid', methods=['GET'])
4053
def get_uuid():
4154
random_uuid = str(uuid.uuid4())
@@ -54,7 +67,8 @@ def stream1():
5467
form = request.json["form"]
5568
topic_num = request.json["topic_num"]
5669
gen_title_v2 = GenTitle(uuid)
57-
return Response(gen_title_v2.predict_title_v2(form, role, title, topic_num), mimetype='application/octet-stream')
70+
return Response(gen_title_v2.predict_title_v2(form, role, title, topic_num),
71+
mimetype='application/octet-stream')
5872

5973

6074
@app.route('/generate_outline', methods=['POST'])
@@ -124,4 +138,4 @@ def stream():
124138

125139

126140
if __name__ == '__main__':
127-
app.run(host='0.0.0.0', port=5000, debug=True)
141+
app.run(host='0.0.0.0', port=5000, debug=True)

mdtree/readmd.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Information about a single table. (A slide might have more than one - or none.)
2+
class TableInfo:
3+
def __init__(self, tableRows, tableCaption):
4+
self.tableRows = []
5+
self.tableCaption = ""

mdtree/tree2ppt.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from enum import Enum
44
from io import BytesIO
55

6+
import markdown
67
from PIL.ImageQt import rgb
78
from pptx import Presentation
89
from pptx.enum.text import MSO_AUTO_SIZE, MSO_VERTICAL_ANCHOR
@@ -27,9 +28,9 @@ def __init__(self, md_str1):
2728
self.init_markdown(md_str1)
2829
self.traverse_tree(self.tree)
2930
now = datetime.datetime.now().timestamp()
30-
path = './../myppt/test' + str(now) + '.pptx'
31-
if not os.path.exists('./../myppt'):
32-
os.makedirs('./../myppt')
31+
path = './myppt/test' + str(now) + '.pptx'
32+
if not os.path.exists('./myppt'):
33+
os.makedirs('./myppt')
3334
self.prs.save(path)
3435
pass
3536

@@ -154,13 +155,14 @@ def init_content(self):
154155
tf.word_wrap = True
155156
# 添加正文
156157
paragraph = tf.paragraphs[0]
157-
paragraph.text = self.content.replace("<p>", "\t").replace("</p>", "\n")
158+
paragraph.text = self.content.replace("<p>", "").replace("</p>", "\n")
159+
self.processing_md_str(self.content.replace("<p>", "").replace("</p>", "\n"))
158160
# TODO 处理正文
159161
self.get_font(paragraph.font, MarkdownCategory.CONTENT)
160162
paragraph.vertical_anchor = MSO_VERTICAL_ANCHOR.TOP
161163

162-
163-
if __name__ == "__main__":
164-
md_content = read_md_file("./txt.md")
165-
out = parse_string(md_content)
166-
Tree2PPT(md_content)
164+
def processing_md_str(self, md_str):
165+
print(md_str)
166+
md = markdown.Markdown()
167+
html1 = md.convert(md_str)
168+
print(html1)

templates/asset-manifest.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"files": {
3+
"main.css": "./static/css/main.05987304.css",
4+
"main.js": "./static/js/main.aee5e3a4.js",
5+
"runtime.js": "./static/js/runtime.1b8d8764.js",
6+
"base.js": "./static/js/base.0ec2920c.js",
7+
"antd.js": "./static/js/antd.56ea7e9d.js",
8+
"lodash.js": "./static/js/lodash.4814a24f.js",
9+
"vendors.js": "./static/js/vendors.3862e664.js",
10+
"static/media/bg.png": "./static/media/bg.604e6fa22cf577d70726.png",
11+
"static/media/icon_ai.svg": "./static/media/icon_ai.be8adbf8c3ed72278120e99796c47095.svg",
12+
"static/media/icon_fy.svg": "./static/media/icon_fy.342e439a8976a606aeed62874b278890.svg",
13+
"static/media/icon_cxd.svg": "./static/media/icon_cxd.04ebe92419162580d43aecf8a3214e69.svg",
14+
"static/media/icon_rs.svg": "./static/media/icon_rs.168efc1c3b1b33c0f7a2b6aba90abedf.svg",
15+
"static/media/icon_zjd.svg": "./static/media/icon_zjd.099eabb77e46b48ab586eb8c81830998.svg",
16+
"static/media/icon_fuz.svg": "./static/media/icon_fuz.db0be2abae623e6f62fb1cdcdb013dd3.svg",
17+
"index.html": "./index.html",
18+
"static/media/index.cjs": "./static/media/index.433019db0fc741f26829.cjs"
19+
},
20+
"entrypoints": [
21+
"static/js/runtime.1b8d8764.js",
22+
"static/js/base.0ec2920c.js",
23+
"static/js/antd.56ea7e9d.js",
24+
"static/js/lodash.4814a24f.js",
25+
"static/js/vendors.3862e664.js",
26+
"static/css/main.05987304.css",
27+
"static/js/main.aee5e3a4.js"
28+
]
29+
}

templates/favicon.ico

3.78 KB
Binary file not shown.

templates/index.html

Lines changed: 1 addition & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -1,195 +1 @@
1-
<!DOCTYPE html>
2-
<html>
3-
<head>
4-
<title>Auto PPT</title>
5-
<meta charset="UTF-8">
6-
<link rel="icon" href="https://img1.imgtp.com/2023/06/26/2uA6lVi8.png" type="image/png">
7-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>
8-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes"/>
9-
<meta property="image" content="https://img1.imgtp.com/2023/06/26/2uA6lVi8.png"/>
10-
<meta property="title" content="Auto PPTX: chatgpt自动生成pptx"/>
11-
<meta
12-
name="description"
13-
content="Auto generate pptx using gpt-3.5, Free to use online | 通过gpt-3.5生成PPT,免费在线使用"
14-
/>
15-
<style>
16-
/**背景图变色动画**/
17-
@keyframes background-overlay-animation {
18-
0% {
19-
background-image: linear-gradient(4deg, rgba(255, 78, 36, 0.3) 50%, rgba(255, 78, 36, 0.3) 100%),
20-
url("https://img1.imgtp.com/2023/07/04/sOFsVAlW.jpg");
21-
}
22-
25% {
23-
background-image: linear-gradient(4deg, rgba(213, 49, 127, 0.3) 50%, rgba(213, 49, 127, 0.3) 100%),
24-
url("https://img1.imgtp.com/2023/07/04/sOFsVAlW.jpg");
25-
}
26-
50% {
27-
background-image: linear-gradient(4deg, rgba(36, 182, 255, 0.3) 50%, rgba(36, 182, 255, 1) 100%),
28-
url("https://img1.imgtp.com/2023/07/04/sOFsVAlW.jpg");
29-
}
30-
31-
100% {
32-
background-image: linear-gradient(4deg, rgba(0, 255, 254, 0.3) 50%, rgba(0, 255, 254, 0.3) 100%),
33-
url("https://img1.imgtp.com/2023/07/04/sOFsVAlW.jpg");
34-
}
35-
}
36-
canvas{
37-
width: 100%;
38-
position: absolute;
39-
top: 0;
40-
}
41-
/*** 动画 end****/
42-
43-
44-
body {
45-
margin: 0;
46-
}
47-
48-
/* 页面容器 */
49-
.container {
50-
background-image: url("https://img1.imgtp.com/2023/07/04/sOFsVAlW.jpg");
51-
background-size: 100% 100%;
52-
background-position: center;
53-
background-repeat: no-repeat;
54-
height: 100vh;
55-
display: flex;
56-
flex-direction: column;
57-
align-items: center;
58-
justify-content: center;
59-
60-
animation: background-overlay-animation 10s linear infinite;
61-
}
62-
63-
/* 内容样式 */
64-
.content {
65-
text-align: center;
66-
color: #fff;
67-
font-size: 24px;
68-
}
69-
70-
/* 大标题样式 */
71-
.page-title {
72-
color: rgba(58, 209, 73, 0.6);
73-
text-align: center;
74-
font-size: 48px; /* 调整标题字体大小 */
75-
font-weight: 500;
76-
margin-top: -20px; /* 调整标题与上方元素的间距 */
77-
font-family: "Microsoft YaHei UI";
78-
}
79-
80-
/* 输入行样式 */
81-
.input-row {
82-
display: flex;
83-
align-items: center;
84-
margin-bottom: 10px;
85-
}
86-
87-
.page-input {
88-
width: 100%;
89-
appearance: none;
90-
outline: none;
91-
padding: 12px 20px;
92-
box-sizing: border-box;
93-
border-radius: 10px;
94-
border: 1px solid rgba(58, 209, 73, 0.2);
95-
box-shadow: 0 0 2px rgba(58, 209, 73, 0.2);
96-
}
97-
98-
/* 按钮样式 */
99-
.page-btn {
100-
min-width: 70px;
101-
margin-left: 10px;
102-
padding: 12px 20px;
103-
box-sizing: border-box;
104-
border-radius: 10px;
105-
outline: none;
106-
border: 0;
107-
background: rgba(58, 209, 73, 0.6);
108-
color: white;
109-
cursor: pointer;
110-
}
111-
112-
/* GitHub 图标样式 */
113-
.github-icon {
114-
position: absolute;
115-
top: 10px;
116-
right: 10px;
117-
}
118-
119-
.github-icon svg {
120-
fill: white;
121-
height: 30px;
122-
}
123-
</style>
124-
125-
</head>
126-
<body>
127-
<script src="./../../pptx_static/particle.min.js"></script>
128-
<div class="container">
129-
<canvas id="my_canvas"></canvas>
130-
<a class="github-icon" href="https://github.com/limaoyi1/Auto_PPT">
131-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="30" height="30">
132-
<path fill="#000"
133-
d="M23.999 2C12.177 2 2 12.179 2 24.001c0 9.086 5.891 16.767 14.06 19.438 1.03.189 1.407-.447 1.407-1.002v-3.91c-5.715 1.23-6.915-2.749-6.915-2.749-.935-2.353-2.283-2.979-2.283-2.979-1.874-1.278.146-1.252.146-1.252 2.071.148 3.154 2.124 3.154 2.124 1.839 3.18 4.828 2.261 5.998 1.728.186-1.327.715-2.26 1.301-2.779-4.552-.514-9.365-2.276-9.365-10.126 0-2.242.8-4.077 2.12-5.502-.212-.515-.918-2.61.201-5.439 0 0 1.72-.553 5.639 2.107a19.293 19.293 0 0 1 5.007-.67c1.7.005 3.41.228 5.006.67 3.916-2.66 5.634-2.107 5.634-2.107 1.12 2.83.416 4.924.204 5.439 1.322 1.425 2.116 3.26 2.116 5.502 0 7.865-4.82 9.604-9.39 10.11.736.63 1.397 1.876 1.397 3.777v5.583c0 .557.373 1.198 1.417.994C40.106 40.767 46 33.086 46 24.001 46 12.179 35.823 2 23.999 2"/>
134-
</svg>
135-
</a>
136-
<div class="content">
137-
<h1 class="page-title animate__animated animate__zoomInDown">自动生成你的PPT</h1>
138-
139-
<div class="input-row">
140-
<input type="text" id="titleInput" class="page-input animate__animated animate__backInLeft" placeholder="请输入PPT的主题"/>
141-
<button onclick="callAPI()" class="page-btn animate__animated animate__backInRight">生成</button>
142-
</div>
143-
<div class="input-row">
144-
<p id="loadingText" style="display: none;">正在生成 PPT,这大概需要3~5分钟,请稍候...</p>
145-
</div>
146-
</div>
147-
</div>
148-
149-
<script>
150-
// 初始化粒子(画布id)
151-
particle.init('my_canvas');
152-
// 调用api
153-
function callAPI() {
154-
let title = document.getElementById("titleInput").value;
155-
let url = "http://www.limaoyi.top:5000/ppt?title=" + encodeURIComponent(title);
156-
157-
// 显示加载文本
158-
let loadingText = document.getElementById("loadingText");
159-
loadingText.style.display = "block";
160-
161-
// 发送 HTTP GET 请求获取流数据
162-
fetch(url)
163-
.then(response => {
164-
if (!response.ok) {
165-
throw new Error('网络请求错误');
166-
}
167-
return response.blob(); // 获取响应数据的二进制流
168-
})
169-
.then(blob => {
170-
// 创建 URL 对象
171-
let url = URL.createObjectURL(blob);
172-
173-
// 创建一个链接并模拟点击下载
174-
let link = document.createElement("a");
175-
link.href = url;
176-
link.download = "presentation.pptx"; // 下载的文件名
177-
link.click();
178-
179-
// 清除 URL 对象
180-
URL.revokeObjectURL(url);
181-
182-
// 隐藏加载文本
183-
loadingText.style.display = "none";
184-
})
185-
.catch(error => {
186-
// 处理错误
187-
console.error(error);
188-
189-
// 隐藏加载文本
190-
loadingText.style.display = "none";
191-
});
192-
}
193-
</script>
194-
</body>
195-
</html>
1+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site|AIGC"/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><title>AIGC App</title><script defer="defer" src="./static/js/runtime.1b8d8764.js"></script><script defer="defer" src="./static/js/base.0ec2920c.js"></script><script defer="defer" src="./static/js/antd.56ea7e9d.js"></script><script defer="defer" src="./static/js/lodash.4814a24f.js"></script><script defer="defer" src="./static/js/vendors.3862e664.js"></script><script defer="defer" src="./static/js/main.aee5e3a4.js"></script><link href="./static/css/main.05987304.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

0 commit comments

Comments
 (0)