| import uvicorn, traceback ,json, time, httpx |
| from fastapi import FastAPI, HTTPException |
| from pydantic import BaseModel |
|
|
| |
| from tools.tools import UniverseToolsClass |
| from modules.ubl.da.da_main import UBLClass |
| from modules.bat.bat_main import BATClass |
| from modules.bangla_ocr.bangla_ocr_main import BanglaOcrClass |
| from modules.face_detection.face_detection_main import FaceDetectionClass |
| from modules.face_recognition.face_recognition_main import facialRecognitionClass |
| from modules.bevarage_indrasty.bevarage_indrasty_main import BevarageIndrastyClass |
| from modules.material_detection.material_main import MaterialDetectionClass |
| from modules.laver_bazar_ocr.laver_bazar_ocr_main import LaverBazarOcrClass |
| from modules.hotspot.hotspot_main import HotspotCalculateClass |
| from modules.ekyc.ekyc_main import EKYCClass |
| from modules.nlp.nlp_main import NlpClass |
| from modules.mt_house_ocr.mt_house_ocr_main import MTHouseOCRClass |
| from modules.nlp_zerocal.nlp_zerocal_main import NlpZeroCalClass |
| from modules.nlp_maya.nlp_maya_main import NlpMayaClass |
| from modules.ubl.category import categoryClass |
| from modules.speechanalyzer.speechanalyzer_main import SpeechAnalyzerClass |
| from modules.nlp_conversational_guidance.nlp_conversational_guidance_main import NlpConversationalGuidanceClass |
| from modules.speakmetric.speakmetric_main import SpeakMetricClass |
| from modules.marge_speak_conver.marge_speak_conver_main import MargeSpeakConverClass |
| from modules.international_image_analysis.category import IntImgAnaCategoryClass |
| from modules.international_image_analysis_ubl.category_iia_ubl import IntImgAnaCategoryClass_UBL |
|
|
| |
| from tools.models_handler import ModelsUBL, ModelsBAT, ModelFace, ModelBATHotspot, ModelBevarageIndrasty, ModelMaterial, ModelMemoOcr, ModelSpeechAnalyzer, ModelIntImgAna, ModelMthouseOcr |
|
|
| |
| face_model = ModelFace() |
| ubl_models = ModelsUBL() |
| bat_models = ModelsBAT() |
| memo_ocr_model = ModelMemoOcr() |
| demo_gp_model = ModelMaterial() |
| bevarage_indrasty_model = ModelBevarageIndrasty() |
| bat_hotspot_model = ModelBATHotspot() |
| speechanalyzer_model = ModelSpeechAnalyzer() |
| int_img_ana_model = ModelIntImgAna() |
| mt_house_ocr_model = ModelMthouseOcr() |
|
|
| |
| universe_tools_object = UniverseToolsClass() |
| ubl_class_object = UBLClass() |
| bat_class_object = BATClass() |
| bevarage_indrasty_class_object = BevarageIndrastyClass() |
| facial_recognition_class_object = facialRecognitionClass() |
| face_detection_class_object = FaceDetectionClass() |
| hotspot_class_object = HotspotCalculateClass() |
| material_detection_class_object = MaterialDetectionClass() |
| bangla_ocr_class_object = BanglaOcrClass() |
| laver_bazar_ocr_class_object = LaverBazarOcrClass() |
| ekyc_class_object = EKYCClass() |
| nlp_class_object = NlpClass() |
| mt_house_ocr_class_object = MTHouseOCRClass() |
| nlp_zerocal_class_object = NlpZeroCalClass() |
| nlp_maya_class_object = NlpMayaClass() |
| category_class_object = categoryClass() |
| speechanalyzer_class_object = SpeechAnalyzerClass() |
| nlp_conversational_guidance_class_object = NlpConversationalGuidanceClass() |
| speakmetric_class_object = SpeakMetricClass() |
| marge_speak_conver_class_object = MargeSpeakConverClass() |
| int_img_ana_category_class_object = IntImgAnaCategoryClass() |
| int_img_ana_category_class_ubl_object = IntImgAnaCategoryClass_UBL() |
|
|
| |
| logger = universe_tools_object.setup_logger() |
|
|
| |
| appId_dic = universe_tools_object.load_data('tools')['appId'] |
|
|
| app = FastAPI() |
|
|
| class ObjectDetection(BaseModel): |
| appId : str |
| appName : str |
| url : list |
| company : str = None |
| area : str = None |
| age : str = None |
| |
| class UnileverModel(BaseModel): |
| outlet: dict |
| job: list |
|
|
| |
| @app.get("/status/bat", tags=["BAT Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/bat/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "BAT Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "BAT Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "BAT returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "BAT AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/bat/", tags=["BAT"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId==appId_dic['bat']: |
| result = await bat_class_object.bat_main_func(images=items.url,models=bat_models) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
|
|
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/faceRecognition", tags=["Facial Recognition Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/faceRecognition/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "Facial Recognition Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "Facial Recognition Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "Facial Recognition returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "Facial Recognition AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/faceRecognition/", tags=["Facial Recognition"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId==appId_dic['facialRecognition']: |
| result = await facial_recognition_class_object.face_recognition_main_func(items.url) |
| universe_tools_object.monitor(result) |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/faceDetection", tags=["Face Detection Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/faceDetection/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "Face Detection Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "Face Detection Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "Face Detection returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "Face Detection AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/faceDetection/", tags=["Face Detection"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId==appId_dic['faceDetection']: |
| result = await face_detection_class_object.face_det_main(items.url[0]['original'], face_model.faceModel) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/hotspot", tags=["Hotspot Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/hotspot/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "Hotspot Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "Hotspot Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "Hotspot returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "Hotspot AI Server unreachable", |
| "error": str(e) |
| } |
|
|
|
|
| @app.post("/hotspot/", tags=["Hotspot"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId==appId_dic['Hotspot']: |
| result = await hotspot_class_object.hotspot_main_func(items.url[0]['original'], bat_hotspot_model.BATHotspotModel) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/banglaOcr", tags=["Bangla OCR Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/banglaOcr/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "Bangla OCR Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "Bangla OCR Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "Bangla OCR returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "Bangla OCR AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/banglaOcr/", tags=["Bangla OCR"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId==appId_dic['banglaOcr']: |
| result = await bangla_ocr_class_object.bng_ocr_main_func(items.url[0]['original']) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/nidOcr", tags=["Nid Ocr Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/nidOcr/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "Nid Ocr Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "Nid Ocr Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "Nid Ocr returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "Nid Ocr AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/nidOcr/", tags=["Nid Ocr"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['ekyc']: |
| result = await ekyc_class_object.ekyc_main_func(items.url[0]['original'],items.url[1]['original']) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/ocr", tags=["Memo OCR Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/ocr/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "Memo OCR Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "Memo OCR Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "Memo OCR returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "Memo OCR AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/ocr/", tags=["Memo OCR"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['memoOcr']: |
| result = await laver_bazar_ocr_class_object.laver_bazar_ocr_main(items.url[0]['original'], memo_ocr_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/nlpBat", tags=["NLP Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/nlpBat/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "NLP Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "NLP Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "NLP returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "NLP AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/nlpBat/", tags=["NLP"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['nlp']: |
| result = await nlp_class_object.nlp_main_func(items.url[0]['original'], models=speechanalyzer_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/fridgeDetection", tags=["Bevarage Indrasty Analysis Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/fridgeDetection/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "Bevarage Indrasty Analysis Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "Bevarage Indrasty Analysis Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "Bevarage Indrasty Analysis returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "Bevarage Indrasty Analysis AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/fridgeDetection/", tags=["Bevarage Indrasty Analysis"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['bevarage_indrasty']: |
| result = await bevarage_indrasty_class_object.bevarage_indrasty_main_func(items.url, bevarage_indrasty_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/materialDetection", tags=["Material Detection Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/materialDetection/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "Material Detection Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "Material Detection Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "Material Detection returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "Material Detection AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/materialDetection/", tags=["Material Detection"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['materialDetection']: |
| result = await material_detection_class_object.material_main_func(items.url[0]['original'], demo_gp_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/mTHouseOCR", tags=["MT House OCR Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/mTHouseOCR/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "MT House OCR Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "MT House OCR Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "MT House OCR returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "MT House OCR AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/mTHouseOCR/", tags=["MT House OCR"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['tableToJson']: |
| result = await mt_house_ocr_class_object.mt_house_ocr_main_func(items.url, model=mt_house_ocr_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY, ensure_ascii=False)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/nlpZeroCal", tags=["NLP Zero Cal Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/nlpZeroCal/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "NLP Zero Cal Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "NLP Zero Cal Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "NLP Zero Cal returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "NLP Zero Cal AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/nlpZeroCal/", tags=["NLP Zero Cal"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['nlpZeroCal']: |
| result = await nlp_zerocal_class_object.nlp_zerocal_main_func(items.url[0]['original'], models=speechanalyzer_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/nlpMaya", tags=["NLP Maya Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/nlpMaya/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "NLP Maya Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "NLP Maya Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "NLP Maya returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "NLP Maya AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/nlpMaya/", tags=["NLP Maya"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['nlpmaya']: |
| result = await nlp_maya_class_object.nlp_maya_main_func(items.url[0]['original'], items.area, items.age, models=speechanalyzer_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/fmcg", tags=["FMCG Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/fmcg/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "FMCG Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "FMCG Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "FMCG returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "FMCG AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/fmcg/", tags=["FMCG"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['fmcg']: |
| result = await category_class_object.process_category(input_data=items.url, models=ubl_models) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/speechflow", tags=["SPEECHFLOW Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/speechflow/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "SPEECHFLOW Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "SPEECHFLOW Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "SPEECHFLOW returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "SPEECHFLOW AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/speechflow/", tags=["SPEECHFLOW"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['speechflow']: |
| result = await speechanalyzer_class_object.speechanalyzer_main_func(items.url[0]['original'], models=speechanalyzer_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/conversationalguidance", tags=["Conversational Guidance Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/conversationalguidance/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "Conversational Guidance Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "Conversational Guidance Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "Conversational Guidance returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "Conversational Guidance AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/conversationalguidance/", tags=["Conversational Guidance"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['nlpconversationalguidance']: |
| result = await nlp_conversational_guidance_class_object.nlp_conversational_guidance_main_func(items.url[0]['original'], items.age, models=speechanalyzer_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/speakmetric", tags=["SpeakMetric Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/speakmetric/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "SpeakMetric Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "SpeakMetric Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "SpeakMetric returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "SpeakMetric AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/speakmetric/", tags=["SpeakMetric"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['speakmetric']: |
| result = await speakmetric_class_object.speakmetric_main_func(items.url[0]['original'], models=speechanalyzer_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/domex", tags=["Domex Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/domex/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "Domex Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "Domex Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "Domex returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "Domex AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/domex/", tags=["Domex"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['domex']: |
| result = await marge_speak_conver_class_object.marge_speak_conver_main_func(items.url[0]['original'], models=speechanalyzer_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/intimgana", tags=["International Image Analysis Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/intimgana/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "International Image Analysis Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "International Image Analysis Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "International Image Analysis returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "International Image Analysis AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/intimgana/", tags=["International Image Analysis"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['intimgana']: |
| result = await int_img_ana_category_class_object.int_img_ana_process_category(input_data=items.url, models=int_img_ana_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/pitchMonitoring", tags=["Pitch Monitoring Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/pitchMonitoring/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "Pitch Monitoring Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "Pitch Monitoring Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "Pitch Monitoring returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "Pitch Monitoring AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/pitchMonitoring/", tags=["Pitch Monitoring"]) |
| async def create_items(items: ObjectDetection): |
| try: |
| BODY = universe_tools_object.Body(items) |
| logger.info(f"Request - {json.dumps(BODY)}") |
| if items.appId== appId_dic['pitchMonitoring']: |
| result = await speakmetric_class_object.speakmetric_main_func(items.url[0]['original'], models=speechanalyzer_model) |
| universe_tools_object.monitor(result) |
| if result: |
| BODY["ai_feedback"] = result |
| BODY['statusAI'] = True |
| logger.info(f"Response - {json.dumps(BODY)}\n") |
| return BODY |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| |
| @app.get("/status/intimgana_ubl", tags=["International Image Analysis UBL Status"]) |
| async def status(): |
| url = "https://batnlp.ngrok.app/intimgana_ubl/" |
|
|
| start = time.perf_counter() |
|
|
| try: |
| async with httpx.AsyncClient(timeout=5) as client: |
| response = await client.post(url) |
|
|
| latency = round(time.perf_counter() - start, 3) |
|
|
| if response.status_code == 422: |
| return { |
| "status": "Server Running...", |
| "message": "International Image Analysis UBL Module is Active...", |
| "status_code": 200, |
| "latency_sec": latency |
| } |
|
|
| elif response.status_code < 500: |
| return { |
| "status": "Server Running...", |
| "message": "International Image Analysis UBL Module is Active...", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
| else: |
| return { |
| "status": "Server Error !!!", |
| "message": "International Image Analysis UBL returned server error", |
| "status_code": response.status_code, |
| "latency_sec": latency |
| } |
|
|
| except httpx.RequestError as e: |
| return { |
| "status": "Server Down ..!!!", |
| "message": "International Image Analysis UBL AI Server unreachable", |
| "error": str(e) |
| } |
|
|
| @app.post("/intimgana_ubl/", tags=["International Image Analysis UBL"]) |
| async def create_items(items: UnileverModel): |
| try: |
| logger.info(f"Request - {json.dumps(items.model_dump())}") |
| if True: |
| result = await int_img_ana_category_class_ubl_object.int_img_ana_process_category_ubl(input_data=items, models=int_img_ana_model) |
| universe_tools_object.monitor(result) |
| logger.info(f"Response - {json.dumps(result)}\n") |
| return result |
| except Exception as e: |
| traceback.print_exc() |
| raise HTTPException(status_code=500, detail="Internal Server Error") |
| finally: |
| universe_tools_object.refresh() |
|
|
| if __name__ == "__main__": |
| uvicorn.run(app, host="127.0.0.1", port=5656) |
|
|