fix: update

Desc  : update project
parent 504beb2c
from datetime import datetime
import moviepy.editor as mp
import requests
import speech_recognition as sr
from core import setup_logger
from fastapi import APIRouter, File, HTTPException, UploadFile
from fastapi.responses import JSONResponse
from pymongo.mongo_client import MongoClient
from core.logger import setup_logger
# Replace with your MongoDB Atlas credentials
username = "admin"
password = "JppbU6MZeHfOj7sp"
......@@ -118,6 +118,7 @@ def translate_text(text, target_language):
# status_code=500, detail="Failed to update or create translated item"
# )
# v3
def send_to_mongodb(translated_integer_si):
translated_item_data = {
......@@ -137,4 +138,6 @@ def send_to_mongodb(translated_integer_si):
result = items_collection.replace_one({}, translated_item_data, upsert=True)
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 controllers import translate_controler, users_controller, video_to_sign_language_controller
from fastapi.responses import RedirectResponse
from fastapi.middleware.cors import CORSMiddleware
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()
......@@ -18,6 +17,7 @@ client = MongoClient(uri)
db = client["test"]
items_collection = db["translated_items"]
@app.on_event("startup")
async def startup_db_client():
app.mongodb_client = MongoClient(uri)
......@@ -33,30 +33,30 @@ async def shutdown_db_client():
app.mongodb_client.close()
# logger = setup_logger()
logger = setup_logger()
app.include_router(users_controller.router)
app.include_router(translate_controler.router)
app.include_router(video_to_sign_language_controller.router)
# Add cores middleware
origins = [
"http://localhost",
"http://localhost:8080",
"http://127.0.0.1:8000",
"http://localhost:8004",
"http://localhost:3000",
"http://127.0.0.1:8000"
]
app.add_middleware(
CORSMiddleware,
app.add_middleware(CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
allow_headers=["*"])
@app.get("/")
async def read_root():
return {"message": "FastAPI with MongoDB integration"}
\ No newline at end of file
@app.get('/')
async def root():
url = app.docs_url or '/docs'
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