diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.idea/AIchat.iml b/.idea/AIchat.iml index b60f9e2..202d1b6 100644 --- a/.idea/AIchat.iml +++ b/.idea/AIchat.iml @@ -7,4 +7,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app.py b/app.py index 0ac17df..29ea3e1 100644 --- a/app.py +++ b/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/', methods=['POST']) +def delete(log_id): + delete_log(log_id) + return redirect(url_for('index')) if __name__ == '__main__': app.run(debug=True) diff --git a/audio/55d4badc-8a6c-4415-a5f3-ecff6b5b3022.mp3 b/audio/55d4badc-8a6c-4415-a5f3-ecff6b5b3022.mp3 deleted file mode 100644 index ab05330..0000000 Binary files a/audio/55d4badc-8a6c-4415-a5f3-ecff6b5b3022.mp3 and /dev/null differ diff --git a/conversation.db b/conversation.db index 11ae193..22f8c23 100644 Binary files a/conversation.db and b/conversation.db differ diff --git a/index.html b/index.html deleted file mode 100644 index 7101365..0000000 --- a/index.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - Conversation Table - - - Conversation Table - - - ID - Message - - - {% for conversation in conversations %} - - {{ conversation[0] }} - {{ conversation[1] }} - - - {% endfor %} - - - diff --git a/main.py b/main.py index 196121d..f1602df 100644 --- a/main.py +++ b/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) diff --git a/static/audio/65d4335a-d6e0-47b5-ac04-71196d4cf14e.mp3 b/static/audio/65d4335a-d6e0-47b5-ac04-71196d4cf14e.mp3 new file mode 100644 index 0000000..f346e63 Binary files /dev/null and b/static/audio/65d4335a-d6e0-47b5-ac04-71196d4cf14e.mp3 differ diff --git a/static/audio/c785168c-ed70-4c5e-9bab-d660e6b99388.mp3 b/static/audio/c785168c-ed70-4c5e-9bab-d660e6b99388.mp3 new file mode 100644 index 0000000..d5a748b Binary files /dev/null and b/static/audio/c785168c-ed70-4c5e-9bab-d660e6b99388.mp3 differ diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..8374430 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,71 @@ + + + + + + + Match Logs + + + + 交流记录 + + + Question + Answer + Audio Path + Action + + {% for log in logs %} + + {{ log[1] }} + {{ log[2] }} + + + + Your browser does not support the audio element. + + + + + + 删除 + + + + + {% endfor %} + + + diff --git a/user_audio.wav b/user_audio.wav index f45dec7..a37d6db 100644 Binary files a/user_audio.wav and b/user_audio.wav differ