fix: update

Desc  : update project
parent 504beb2c
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 core.logger import setup_logger
# Replace with your MongoDB Atlas credentials # Replace with your MongoDB Atlas credentials
username = "admin" username = "admin"
password = "JppbU6MZeHfOj7sp" password = "JppbU6MZeHfOj7sp"
...@@ -118,6 +118,7 @@ def translate_text(text, target_language): ...@@ -118,6 +118,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 +138,6 @@ def send_to_mongodb(translated_integer_si): ...@@ -137,4 +138,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()
...@@ -18,6 +17,7 @@ client = MongoClient(uri) ...@@ -18,6 +17,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,30 +33,30 @@ async def shutdown_db_client(): ...@@ -33,30 +33,30 @@ 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"
] ]
app.add_middleware( app.add_middleware(CORSMiddleware,
CORSMiddleware,
allow_origins=origins, allow_origins=origins,
allow_credentials=True, allow_credentials=True,
allow_methods=["*"], allow_methods=["*"],
allow_headers=["*"], allow_headers=["*"])
)
@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)
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