Spaces:
Paused
Paused
Update backend/main.py
Browse files- backend/main.py +5 -9
backend/main.py
CHANGED
@@ -8,7 +8,6 @@ from uuid import uuid4
|
|
8 |
import logging
|
9 |
from fastapi.logger import logger as fastapi_logger
|
10 |
import sys
|
11 |
-
# sys.path.append('/Users/benolojo/DCU/CA4/ca400_FinalYearProject/2024-ca400-olojob2-majdap2/src/backend/')
|
12 |
|
13 |
from fastapi import FastAPI
|
14 |
from fastapi.middleware.cors import CORSMiddleware
|
@@ -72,9 +71,6 @@ config = dotenv_values(".env")
|
|
72 |
# Read connection string from .env file
|
73 |
uri = config['MONGODB_URI']
|
74 |
|
75 |
-
# Set transformers cache
|
76 |
-
# os.environ['HF_HOME'] = './.cache/'
|
77 |
-
# os.environ['SENTENCE_TRANSFORMERS_HOME'] = './.cache'
|
78 |
|
79 |
# MongoDB Connection Lifespan Events
|
80 |
@asynccontextmanager
|
@@ -187,8 +183,8 @@ def test_put():
|
|
187 |
|
188 |
async def send_translated_text(client_id, original_text, translated_text, room_id):
|
189 |
print('SEND_TRANSLATED_TEXT IS WOKRING IN FASTAPI BACKEND...')
|
190 |
-
print(rooms)
|
191 |
-
print(clients)
|
192 |
|
193 |
data = {
|
194 |
"author": str(client_id),
|
@@ -238,7 +234,7 @@ async def call_user(sid, call_id):
|
|
238 |
client_id = clients[sid].client_id
|
239 |
|
240 |
gunicorn_logger.warning(f"NOW TRYING TO CREATE DB RECORD FOR Caller with ID: {client_id} for call: {call_id}")
|
241 |
-
#
|
242 |
request_data = {
|
243 |
"call_id": str(call_id),
|
244 |
"caller_id": str(client_id),
|
@@ -272,7 +268,7 @@ async def answer_call(sid, call_id):
|
|
272 |
|
273 |
# BO -> Update Call Record with Callee field based on call_id
|
274 |
gunicorn_logger.warning(f"NOW UPDATING MongoDB RECORD FOR Caller with ID: {client_id} for call: {call_id}")
|
275 |
-
#
|
276 |
request_data = {
|
277 |
"callee_id": client_id
|
278 |
}
|
@@ -316,7 +312,7 @@ async def incoming_audio(sid, data, call_id):
|
|
316 |
# PM - text_output is a list with 1 string
|
317 |
await send_translated_text(clients[sid].client_id, asr_text, translated_text, call_id)
|
318 |
|
319 |
-
#
|
320 |
# send_captions(clients[sid].client_id, asr_text, translated_text, call_id)
|
321 |
|
322 |
except Exception as e:
|
|
|
8 |
import logging
|
9 |
from fastapi.logger import logger as fastapi_logger
|
10 |
import sys
|
|
|
11 |
|
12 |
from fastapi import FastAPI
|
13 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
71 |
# Read connection string from .env file
|
72 |
uri = config['MONGODB_URI']
|
73 |
|
|
|
|
|
|
|
74 |
|
75 |
# MongoDB Connection Lifespan Events
|
76 |
@asynccontextmanager
|
|
|
183 |
|
184 |
async def send_translated_text(client_id, original_text, translated_text, room_id):
|
185 |
print('SEND_TRANSLATED_TEXT IS WOKRING IN FASTAPI BACKEND...')
|
186 |
+
print(rooms) # Debugging
|
187 |
+
print(clients) # Debugging
|
188 |
|
189 |
data = {
|
190 |
"author": str(client_id),
|
|
|
234 |
client_id = clients[sid].client_id
|
235 |
|
236 |
gunicorn_logger.warning(f"NOW TRYING TO CREATE DB RECORD FOR Caller with ID: {client_id} for call: {call_id}")
|
237 |
+
# BO -> Create Call Record with Caller and call_id field (None for callee, duration, terms..)
|
238 |
request_data = {
|
239 |
"call_id": str(call_id),
|
240 |
"caller_id": str(client_id),
|
|
|
268 |
|
269 |
# BO -> Update Call Record with Callee field based on call_id
|
270 |
gunicorn_logger.warning(f"NOW UPDATING MongoDB RECORD FOR Caller with ID: {client_id} for call: {call_id}")
|
271 |
+
# BO -> Create Call Record with callee_id field (None for callee, duration, terms..)
|
272 |
request_data = {
|
273 |
"callee_id": client_id
|
274 |
}
|
|
|
312 |
# PM - text_output is a list with 1 string
|
313 |
await send_translated_text(clients[sid].client_id, asr_text, translated_text, call_id)
|
314 |
|
315 |
+
# BO -> send translated_text to mongodb as caption record update based on call_id
|
316 |
# send_captions(clients[sid].client_id, asr_text, translated_text, call_id)
|
317 |
|
318 |
except Exception as e:
|