Signed-off-by: sairate <sairate@sina.cn>
This commit is contained in:
parent
a20d8bfbb5
commit
e238c918c5
|
@ -7,4 +7,12 @@
|
|||
<orderEntry type="jdk" jdkName="Python 3.12 (AIchat)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
|
||||
<option name="TEMPLATE_FOLDERS">
|
||||
<list>
|
||||
<option value="$MODULE_DIR$/templates" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
34
app.py
34
app.py
|
@ -1,24 +1,32 @@
|
|||
from flask import Flask, render_template
|
||||
from flask import Flask, render_template, request, redirect, url_for
|
||||
import sqlite3
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def get_match_logs(db_name="conversation.db"):
|
||||
conn = sqlite3.connect(db_name)
|
||||
c = conn.cursor()
|
||||
c.execute("SELECT id, question, answer, audio_path FROM conversation")
|
||||
logs = c.fetchall()
|
||||
conn.close()
|
||||
return logs
|
||||
|
||||
def delete_log(log_id, db_name="conversation.db"):
|
||||
conn = sqlite3.connect(db_name)
|
||||
c = conn.cursor()
|
||||
c.execute("DELETE FROM conversation WHERE id = ?", (log_id,))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
# 连接数据库
|
||||
conn = sqlite3.connect('conversation.db')
|
||||
c = conn.cursor()
|
||||
|
||||
# 从数据库中获取数据
|
||||
c.execute("SELECT * FROM conversation")
|
||||
conversations = c.fetchall()
|
||||
|
||||
# 关闭数据库连接
|
||||
conn.close()
|
||||
|
||||
return render_template("./index.html", conversations=conversations)
|
||||
logs = get_match_logs()
|
||||
return render_template('index.html', logs=logs)
|
||||
|
||||
@app.route('/delete/<int:log_id>', methods=['POST'])
|
||||
def delete(log_id):
|
||||
delete_log(log_id)
|
||||
return redirect(url_for('index'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
|
Binary file not shown.
BIN
conversation.db
BIN
conversation.db
Binary file not shown.
26
index.html
26
index.html
|
@ -1,26 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Conversation Table</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Conversation Table</h1>
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Message</th>
|
||||
<!-- 添加其他列标题 -->
|
||||
</tr>
|
||||
{% for conversation in conversations %}
|
||||
<tr>
|
||||
<td>{{ conversation[0] }}</td>
|
||||
<td>{{ conversation[1] }}</td>
|
||||
<!-- 添加其他列数据 -->
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
5
main.py
5
main.py
|
@ -203,10 +203,11 @@ def main():
|
|||
print('Model response:', model_response)
|
||||
|
||||
# 6. 将文本转换为语音,保存到唯一的文件名
|
||||
unique_audio_filename = "./audio/"+str(uuid.uuid4()) + '.mp3' # 保存为不同的文件名以避免访问冲突
|
||||
audio_filename="audio/"+str(uuid.uuid4()) + '.mp3'
|
||||
unique_audio_filename = "static/"+audio_filename# 保存为不同的文件名以避免访问冲突
|
||||
asyncio.run(generate_audio_from_text(model_response, unique_audio_filename))
|
||||
|
||||
insert_data(baidu_result, model_response,unique_audio_filename)# 插入数据库
|
||||
insert_data(baidu_result, model_response,audio_filename)# 插入数据库
|
||||
# 7. 播放生成的语音
|
||||
play_mp3(unique_audio_filename)
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,71 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Match Logs</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #333;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
th, td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
th {
|
||||
background-color: #5e7abf;
|
||||
color: white;
|
||||
}
|
||||
tr:nth-child(even) {
|
||||
background-color: #8568d7;
|
||||
}
|
||||
tr:hover {
|
||||
background-color: #75d1c8;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>交流记录</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Question</th>
|
||||
<th>Answer</th>
|
||||
<th>Audio Path</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
{% for log in logs %}
|
||||
<tr>
|
||||
<td>{{ log[1] }}</td>
|
||||
<td>{{ log[2] }}</td>
|
||||
<td>
|
||||
<audio controls>
|
||||
<source src="{{ url_for('static', filename=log[3]) }}" type="audio/mpeg">
|
||||
Your browser does not support the audio element.
|
||||
</audio>
|
||||
</td>
|
||||
<td>
|
||||
<form action="{{ url_for('delete', log_id=log[0]) }}" method="post" style="display:inline;">
|
||||
<button type="submit" style="background-color: #e74c3c; color: white; border: none; padding: 5px 10px; cursor: pointer;">
|
||||
删除
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
BIN
user_audio.wav
BIN
user_audio.wav
Binary file not shown.
Loading…
Reference in New Issue