File size: 3,464 Bytes
6e73cd3 793ea24 6e73cd3 793ea24 6e73cd3 793ea24 6e73cd3 793ea24 6e73cd3 793ea24 6e73cd3 793ea24 6e73cd3 793ea24 dd96d5f 793ea24 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
from Perceptrix.engine import perceptrix, robotix, identify_objects_from_text, search_keyword
from CircumSpect import answer_question, find_object_description, locate_object
from flask import Flask, request, jsonify
import numpy as np
import threading
import whisper
import cv2
import os
model = whisper.load_model("base")
def transcribe(audio):
result = model.transcribe(audio)
transcription = result['text']
print(transcription)
return transcription
app = Flask(__name__)
@app.route('/locate_object', methods=['POST'])
def display_image():
try:
image_data = request.json['image_data']
prompt = request.json['prompt']
image_data = np.array(image_data, dtype=np.uint8)
image = cv2.imdecode(image_data, cv2.IMREAD_COLOR)
cv2.imwrite('API.jpg', image)
answer, annotated_image = locate_object(prompt, "API.jpg")
return jsonify({'message': answer, 'annotated_image': annotated_image})
except Exception as e:
return jsonify({'error': str(e)})
@app.route('/vqa', methods=['POST'])
def display_image():
try:
image_data = request.json['image_data']
prompt = request.json['prompt']
image_data = np.array(image_data, dtype=np.uint8)
image = cv2.imdecode(image_data, cv2.IMREAD_COLOR)
cv2.imwrite('API.jpg', image)
answer = answer_question(prompt, "API.jpg")
return jsonify({'message': answer})
except Exception as e:
return jsonify({'error': str(e)})
@app.route('/object_description', methods=['POST'])
def display_image():
try:
image_data = request.json['image_data']
image_data = np.array(image_data, dtype=np.uint8)
image = cv2.imdecode(image_data, cv2.IMREAD_COLOR)
cv2.imwrite('API.jpg', image)
answer = find_object_description("API.jpg")
return jsonify({'message': answer})
except Exception as e:
return jsonify({'error': str(e)})
@app.route('/perceptrix', methods=['POST'])
def display_image():
try:
prompt = request.json['prompt']
answer = perceptrix(prompt)
return jsonify({'message': answer})
except Exception as e:
return jsonify({'error': str(e)})
@app.route('/robotix', methods=['POST'])
def display_image():
try:
prompt = request.json['prompt']
answer = robotix(prompt)
return jsonify({'message': answer})
except Exception as e:
return jsonify({'error': str(e)})
@app.route('/search_keyword', methods=['POST'])
def display_image():
try:
prompt = request.json['prompt']
answer = search_keyword(prompt)
return jsonify({'message': answer})
except Exception as e:
return jsonify({'error': str(e)})
@app.route('/identify_objects_from_text', methods=['POST'])
def display_image():
try:
prompt = request.json['prompt']
answer = identify_objects_from_text(prompt)
return jsonify({'message': answer})
except Exception as e:
return jsonify({'error': str(e)})
@app.route('/transcribe', methods=['POST'])
def upload_audio():
audio_file = request.files['audio']
filename = os.path.join("database", audio_file.filename)
audio_file.save(filename)
return jsonify({'message': transcribe(filename)})
def run_app():
app.run(port=7777)
if __name__ == "__main__":
runner = threading.Thread(target=run_app)
runner.start() |