代码拉取完成,页面将自动刷新
# -*- coding:utf-8 -*-
from voice import voice_fix
from voice import voice_get
from pic import pic_fix
from data import data_fix
import os
import requests
import warnings
from flask import Flask, request, jsonify
import json
warnings.filterwarnings("ignore")
app = Flask(__name__)
app.config.from_object(__name__)
app.config["JSON_AS_ASCII"] = False
@app.route('/welcome', methods=['GET'])
def welcome():
return 0
@app.route('/voice', methods=['POST'])
def voice():
if request.method == 'POST':
body = request.json
flag = body['flag']
user = body['user']
if flag == '1':
print('开始录音,小声时结束')
voice_get.listen()
text = voice_fix.fix()
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer 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"
}
url = 'https://open.aiproxy.xyz/v1/chat/completions'
data = {
"model": "gpt-3.5-turbo",
"messages": [{"role": user, "content": text}]
}
response = requests.post(url, json=data, headers=headers)
response = response.text
response = response.encode('utf-8')
response = json.loads(response)
print(response)
return response
else:
return {'error': 'log has something wrong'}
else:
return {'error': 'web connect wrong'}
# @app.route('/pic')
# def pic():
# return 0
# @app.route('/login', methods=['POST'])
# def test():
# if request.method == 'POST':
# text = request.json
# print(text)
# headers = {
# "Content-Type": "application/json",
# "Authorization": "Bearer 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"
# }
# url = 'https://open.aiproxy.xyz/v1/chat/completions'
# data = {
# "model": "gpt-3.5-turbo",
# "messages": [{"role": "user", "content": text['content']}]
# }
# response = requests.post(url, json=data, headers=headers)
# print(response.text)
# return response.json()
if __name__ == '__main__':
app.run()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。