-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (42 loc) · 1.61 KB
/
main.py
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
import io
import os
import json
from fastapi import File,FastAPI, UploadFile
import aiofiles
import whisper
import firebase_admin
from firebase_admin import credentials, db
model_wis = whisper.load_model("base")
absolute_path = os.path.dirname(__file__)
static_dir = os.path.join(os.path.dirname(__file__))
path = static_dir+"/exous.json"
relative_path = "static/"
full_path = os.path.join(absolute_path, relative_path)
cred = credentials.Certificate(path)
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://exous-39536-default-rtdb.firebaseio.com/'
})
app = FastAPI()
@app.get("/")
async def root():
return {"this adham alghreeb, i have spoken"}
@app.post("/uploadfile/")
async def create_upload_file(file: UploadFile):
return {"filename": file.filename}
@app.post("/voicerecog/")
async def create_upload_file(file: UploadFile = File(...)):
destination_file_path = full_path+file.filename # location to store file
async with aiofiles.open(destination_file_path, 'wb') as out_file:
while content := await file.read(1024): # async read file chunk
await out_file.write(content) # async write file chunk
var_name = full_path+file.filename # path to the uploaded file
result = model_wis.transcribe(var_name)
var_item = result['text'].split()
ref = db.reference("order")
if var_item[0].lower().find("move") != -1:
ref.set(int(1))
elif var_item[0].lower().find("bye") != -1:
ref.set(int(2))
elif var_item[0].lower().find("catch") != -1:
ref.set(int(3))
return {'results': result}