Compare commits
No commits in common. "3970c6a4f35091a92e1b520008a0f6637ac4fea5" and "becf4d697db9be170b5fcb16a58921390de205e9" have entirely different histories.
3970c6a4f3
...
becf4d697d
3 changed files with 11 additions and 27 deletions
32
py/api.py
32
py/api.py
|
@ -4,7 +4,6 @@ import secrets
|
||||||
import threading
|
import threading
|
||||||
from ai import AI
|
from ai import AI
|
||||||
from db import DB
|
from db import DB
|
||||||
from voice import VoiceRecognition
|
|
||||||
|
|
||||||
|
|
||||||
class API:
|
class API:
|
||||||
|
@ -14,19 +13,18 @@ class API:
|
||||||
self.ai_response = {}
|
self.ai_response = {}
|
||||||
self.ai = AI()
|
self.ai = AI()
|
||||||
self.db = DB()
|
self.db = DB()
|
||||||
self.voice = VoiceRecognition()
|
|
||||||
self.db.load_database()
|
self.db.load_database()
|
||||||
self.ai_response_lock = threading.Lock()
|
self.ai_response_lock = threading.Lock()
|
||||||
CORS(self.app)
|
CORS(self.app)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@self.app.route('/interstellar_ai/api/ai_create', methods=['GET'])
|
@self.app.route('/interstellar/api/ai_create', methods=['GET'])
|
||||||
def create_ai():
|
def create_ai():
|
||||||
access_token = secrets.token_urlsafe(self.crypt_size)
|
access_token = secrets.token_urlsafe(self.crypt_size)
|
||||||
self.ai_response[access_token] = ""
|
self.ai_response[access_token] = ""
|
||||||
return jsonify({'status': 200, 'access_token': access_token})
|
return jsonify({'status': 200, 'access_token': access_token})
|
||||||
|
|
||||||
@self.app.route('/interstellar_ai/api/ai_send', methods=['POST'])
|
@self.app.route('/interstellar/api/ai_send', methods=['POST'])
|
||||||
def send_ai():
|
def send_ai():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
messages = data.get('messages')
|
messages = data.get('messages')
|
||||||
|
@ -65,39 +63,27 @@ class API:
|
||||||
|
|
||||||
return jsonify({'status': 401, 'error': 'Invalid AI model type'})
|
return jsonify({'status': 401, 'error': 'Invalid AI model type'})
|
||||||
|
|
||||||
@self.app.route('/interstellar_ai/api/ai_get', methods=['GET'])
|
@self.app.route('/interstellar/api/ai_get', methods=['GET'])
|
||||||
def get_ai():
|
def get_ai():
|
||||||
data = request.args.get('access_token')
|
data = request.args.get('access_token')
|
||||||
if data not in self.ai_response:
|
if data not in self.ai_response:
|
||||||
return jsonify({'status': 401, 'error': 'Invalid access token'})
|
return jsonify({'status': 401, 'error': 'Invalid access token'})
|
||||||
return jsonify({'status': 200, 'response': self.ai_response[data]})
|
return jsonify({'status': 200, 'response': self.ai_response[data]})
|
||||||
|
|
||||||
@self.app.route('/interstellar_ai/db', methods=['POST'])
|
@self.app.route('/interstellar/api/db', methods=['POST'])
|
||||||
def db_manipulate():
|
def db_manipulate():
|
||||||
action = request.args.get('action')
|
action = request.args.get('action')
|
||||||
data = request.args.get('data')
|
data = request.args.get('data')
|
||||||
if action == "create_account":
|
if action == "create_account":
|
||||||
return jsonify({'status': 200, 'response': self.db.add_user(data)})
|
self.db.add_user(data)
|
||||||
elif action == "change_password":
|
elif action == "change_password":
|
||||||
return jsonify({'status': 200, 'response': self.db.update_password(data)})
|
self.db.update_password(data)
|
||||||
elif action == "get_data":
|
elif action == "get_data":
|
||||||
return jsonify({'status': 200, 'response': self.db.get_data(data)})
|
self.db.get_data(data)
|
||||||
elif action == "change_data":
|
elif action == "change_data":
|
||||||
return jsonify({'status': 200, 'response': self.db.change_data(data)})
|
self.db.change_data(data)
|
||||||
elif action == "check_credentials":
|
elif action == "check_credentials":
|
||||||
return jsonify({'status': 200, 'response': self.db.check_credentials(data)})
|
self.db.check_credentials(data)
|
||||||
|
|
||||||
return jsonify({'status': 401, 'response': "Invalid action"})
|
|
||||||
|
|
||||||
@self.app.route('/interstellar_ai/api/voice_recognition', methods=['POST'])
|
|
||||||
def db_manipulate():
|
|
||||||
recognition_type = request.args.get('type')
|
|
||||||
audio = request.args.get('audio_data')
|
|
||||||
option = request.args.get('option')
|
|
||||||
if recognition_type == "basic":
|
|
||||||
return jsonify({'status': 200, 'response': self.voice.basic_recognition(audio, option)})
|
|
||||||
|
|
||||||
return jsonify({'status': 401, 'response': "Invalid type"})
|
|
||||||
|
|
||||||
self.app.run(debug=True, host='0.0.0.0', port=5000)
|
self.app.run(debug=True, host='0.0.0.0', port=5000)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,5 @@ class VoiceRecognition:
|
||||||
r = sr.Recognizer()
|
r = sr.Recognizer()
|
||||||
if option == "online":
|
if option == "online":
|
||||||
return r.recognize_google_cloud(audio)
|
return r.recognize_google_cloud(audio)
|
||||||
elif option == "offline":
|
if option == "offline":
|
||||||
return r.recognize_sphinx(audio)
|
return r.recognize_sphinx(audio)
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
Loading…
Reference in a new issue