from api.core.app import Demos __main = Demos() api = __main.api() @api.post("/texto_desde_web/", status_code=201) def get_text_from_url(data:dict) -> dict: __response=dict({"request_data":data}) try: if data and 'url' in data: __response['texto']=__main.obtener_texto(from_url=data.get('url')) else: raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}") except Exception as e: print(e) #To-do ->agregar mas información en el error fecha, usuario, reqs raise __main.exception(status_code = 403, datail=e) finally: return __response @api.post("/texto_desde_pdf/", status_code=201) def get_text_from_pdf(data:dict) -> dict: __response=dict({"request_data":data}) try: if data and 'pdf' in data: __response['texto']=__main.obtener_texto(from_pdf=data.get('pdf')) else: raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}") except Exception as e: print(e) #To-do ->agregar mas información en el error fecha, usuario, reqs raise __main.exception(status_code = 403, datail=e) finally: return __response @api.post("/generar_bloques/", status_code=201) def get_blocks(data:dict) -> dict: __response=dict({"request_data":data}) try: if data and 'texto' in data and 'size' in data: __response['original']=data.get('texto') __response['bloques']=__main.generar_bloques(texto=data.get('texto'), size=data.get('size')) else: raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}") except Exception as e: print(e) #To-do ->agregar mas información en el error fecha, usuario, reqs raise __main.exception(status_code = 403, datail=e) finally: return __response @api.post("/traducir/", status_code=201) def get_traduccion(data:dict) -> dict: __response=dict({"request_data":data}) try: if data and 'texto' in data and 'idioma' in data: __response['original']= data.get('texto') __response['traduccion']= __main.traducir(texto=data.get('texto'), idioma=data.get('idioma')) else: raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}") except Exception as e: print(e) #To-do ->agregar mas información en el error fecha, usuario, reqs raise __main.exception(status_code = 403, datail=e) finally: return __response @api.post("/resumir/", status_code=201) def get_resumen(data:dict) -> dict: __response=dict({"request_data":data}) try: if data and 'texto' in data: __response['original']= data.get('texto') __response['resumen']= __main.resumir(texto=data.get('texto')) else: raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}") except Exception as e: print(e) #To-do ->agregar mas información en el error fecha, usuario, reqs raise __main.exception(status_code = 403, datail=e) finally: return __response @api.post("/texto_a_imagen/", status_code=201, responses = {201: {"content": {"image/png": {}}}} ,response_class=__main.api_response) def get_text2img(data:dict): __response=dict({"request_data":data}) try: if data and 'texto' in data and 'modelo' in data: __response['original']= data.get('texto') __image = __main.text_to_img(texto=data.get('texto'), model=data.get('modelo')) else: raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}") except Exception as e: print(e) #To-do ->agregar mas información en el error fecha, usuario, reqs raise __main.exception(status_code = 403, datail=str(e)) finally: return __main.api_response(content=__image, media_type="image/png") @api.post("/texto_a_video/", status_code=201) def get_text2video(data:dict) -> dict: __response=dict({"request_data":data}) try: if data: __response['original']= data.get('texto') __response['video']= __main.text_to_video(texto=data.get('texto')) else: raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}") except Exception as e: print(e) #To-do ->agregar mas información en el error fecha, usuario, reqs raise __main.exception(status_code = 403, datail=e) finally: return __response @api.post("/texto_a_audio/", status_code=201) def get_text2speach(data:dict) -> dict: __response=dict({"request_data":data}) try: if data: __response['original']= data.get('texto') __response['audio']= __main.text_to_speach(texto=data.get('texto')) else: raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}") except Exception as e: print(e) #To-do ->agregar mas información en el error fecha, usuario, reqs raise __main.exception(status_code = 403, datail=e) finally: return __response