Commit 6675d09b authored by janithgamage1.ed's avatar janithgamage1.ed

Merge branch 'IT20251000' of http://gitlab.sliit.lk/tmp-23-029/2023-029 into IT20251000

parents 03b3e9c4 23439ff8
This diff is collapsed.
from datetime import datetime from datetime import datetime
import moviepy.editor as mp import moviepy.editor as mp
import requests import requests
import speech_recognition as sr import speech_recognition as sr
from core import setup_logger
from fastapi import APIRouter, File, HTTPException, UploadFile from fastapi import APIRouter, File, HTTPException, UploadFile
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from pymongo.mongo_client import MongoClient from pymongo.mongo_client import MongoClient
from bson import ObjectId
from core.logger import setup_logger
# Replace with your MongoDB Atlas credentials # Replace with your MongoDB Atlas credentials
username = "admin" username = "admin"
...@@ -26,6 +27,21 @@ router = APIRouter() ...@@ -26,6 +27,21 @@ router = APIRouter()
logger = setup_logger() logger = setup_logger()
# @router.get("/rest_pyton/items")
# async def read_root():
# return {"message": "Hello, World!"}
@router.get("/rest_pyton/items")
async def read_items():
items = []
for item in items_collection.find():
item_dict = dict(item)
item_dict['_id'] = str(item_dict['_id']) # Convert _id to a string
items.append(item_dict)
return {"items": items}
@router.post("/rest_pyton/uploaded_video") @router.post("/rest_pyton/uploaded_video")
async def uploaded_video(file: UploadFile = File(...)): async def uploaded_video(file: UploadFile = File(...)):
try: try:
...@@ -118,6 +134,7 @@ def translate_text(text, target_language): ...@@ -118,6 +134,7 @@ def translate_text(text, target_language):
# status_code=500, detail="Failed to update or create translated item" # status_code=500, detail="Failed to update or create translated item"
# ) # )
# v3 # v3
def send_to_mongodb(translated_integer_si): def send_to_mongodb(translated_integer_si):
translated_item_data = { translated_item_data = {
...@@ -137,4 +154,6 @@ def send_to_mongodb(translated_integer_si): ...@@ -137,4 +154,6 @@ def send_to_mongodb(translated_integer_si):
result = items_collection.replace_one({}, translated_item_data, upsert=True) result = items_collection.replace_one({}, translated_item_data, upsert=True)
if result.matched_count == 0 and result.modified_count == 0: if result.matched_count == 0 and result.modified_count == 0:
raise HTTPException(status_code=500, detail="Failed to update or create translated item") raise HTTPException(
status_code=500, detail="Failed to update or create translated item"
)
# from core import setup_logger
from fastapi import FastAPI from fastapi import FastAPI
from controllers import (
translate_controler,
users_controller,
video_to_sign_language_controller,
)
from fastapi.responses import RedirectResponse
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from pymongo.mongo_client import MongoClient from pymongo.mongo_client import MongoClient
from controllers import (translate_controler, users_controller, video_to_sign_language_controller)
# from controllers import translate_controler, users_controller
# from core.logger import setup_logger from core.logger import setup_logger
app = FastAPI() app = FastAPI()
# Replace with your MongoDB Atlas credentials # Replace with your MongoDB Atlas credentials
username = "admin" username = "admin"
...@@ -18,6 +21,7 @@ client = MongoClient(uri) ...@@ -18,6 +21,7 @@ client = MongoClient(uri)
db = client["test"] db = client["test"]
items_collection = db["translated_items"] items_collection = db["translated_items"]
@app.on_event("startup") @app.on_event("startup")
async def startup_db_client(): async def startup_db_client():
app.mongodb_client = MongoClient(uri) app.mongodb_client = MongoClient(uri)
...@@ -33,19 +37,27 @@ async def shutdown_db_client(): ...@@ -33,19 +37,27 @@ async def shutdown_db_client():
app.mongodb_client.close() app.mongodb_client.close()
# logger = setup_logger() logger = setup_logger()
app.include_router(users_controller.router) app.include_router(users_controller.router)
app.include_router(translate_controler.router) app.include_router(translate_controler.router)
app.include_router(video_to_sign_language_controller.router) app.include_router(video_to_sign_language_controller.router)
# Add cores middleware # Add cores middleware
origins = [ origins = [
"http://localhost", "http://localhost",
"http://localhost:8080", "http://localhost:8080",
"http://127.0.0.1:8000",
"http://localhost:8004", "http://localhost:8004",
"http://localhost:3000", "http://localhost:3000",
"http://127.0.0.1:8000",
"127.0.0.1:55553",
"http://localhost:52823",
"http://localhost:53826",
"http://localhost:51373",
"http://localhost:51489",
"https://v6p9d9t4.ssl.hwcdn.net",
"https://64f66d39fdef493229b2ddd9--lambent-unicorn-97396a.netlify.app"
] ]
app.add_middleware( app.add_middleware(
...@@ -58,5 +70,6 @@ app.add_middleware( ...@@ -58,5 +70,6 @@ app.add_middleware(
@app.get("/") @app.get("/")
async def read_root(): async def root():
return {"message": "FastAPI with MongoDB integration"} url = app.docs_url or "/docs"
\ No newline at end of file return RedirectResponse(url)
{
"systemParams": "win32-x64-93",
"modulesFolders": [],
"flags": [],
"linkedModules": [],
"topLevelPatterns": [],
"lockfileEntries": {},
"files": [],
"artifacts": {}
}
\ No newline at end of file
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
...@@ -96,6 +96,7 @@ ...@@ -96,6 +96,7 @@
"react-table-sticky": "^1.1.3", "react-table-sticky": "^1.1.3",
"react-timer-hook": "^3.0.5", "react-timer-hook": "^3.0.5",
"react-to-print": "^2.14.12", "react-to-print": "^2.14.12",
"react-unity-webgl": "^9.4.3",
"react-webcam": "^7.1.1", "react-webcam": "^7.1.1",
"react-window": "^1.8.9", "react-window": "^1.8.9",
"react-zoom-pan-pinch": "^3.0.7", "react-zoom-pan-pinch": "^3.0.7",
...@@ -110,11 +111,7 @@ ...@@ -110,11 +111,7 @@
"util": "^0.12.5", "util": "^0.12.5",
"uuid": "^9.0.0", "uuid": "^9.0.0",
"web-vitals": "^3.3.1", "web-vitals": "^3.3.1",
"yup": "^1.1.1", "yup": "^1.1.1"
"@material-ui/core": "^4.12.4",
"@mui/icons-material": "^5.14.6",
"react-material-file-upload": "^0.0.4",
"react-webcam": "^7.1.1"
}, },
"scripts": { "scripts": {
"start": "react-app-rewired start", "start": "react-app-rewired start",
......
...@@ -11116,6 +11116,11 @@ react-transition-group@^4.4.0, react-transition-group@^4.4.5: ...@@ -11116,6 +11116,11 @@ react-transition-group@^4.4.0, react-transition-group@^4.4.5:
loose-envify "^1.4.0" loose-envify "^1.4.0"
prop-types "^15.6.2" prop-types "^15.6.2"
react-unity-webgl@^9.4.3:
version "9.4.3"
resolved "https://registry.yarnpkg.com/react-unity-webgl/-/react-unity-webgl-9.4.3.tgz#c13cadb8fd447d817a128e6e05975c4f4c9b8f74"
integrity sha512-P/NhKil8EZRtT3q87DC0EgxdNd3c5wa34DMWr5128r2bZojgVIJJu+b20RtGaJpW4lxg6SB2PNN4+R2QujKlDw==
react-webcam@^7.1.1: react-webcam@^7.1.1:
version "7.1.1" version "7.1.1"
resolved "https://registry.yarnpkg.com/react-webcam/-/react-webcam-7.1.1.tgz#e6290b192cde0d2a1039051a019a18e998d7fb39" resolved "https://registry.yarnpkg.com/react-webcam/-/react-webcam-7.1.1.tgz#e6290b192cde0d2a1039051a019a18e998d7fb39"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment