Download api/main.py from coder160/cpu_machine_learner: direct link, hf CLI and curl.
- Browser
- Download file 3.31 kB
-
https://huggingface.co/spaces/coder160/cpu_machine_learner/resolve/1280b996e645b4839b1944da5879400ec4f36ee7/api/main.py
- Command line
-
hf download hf://spaces/coder160/cpu_machine_learner@1280b996e645b4839b1944da5879400ec4f36ee7/api/main.py
-
curl -L -o main.py https://huggingface.co/spaces/coder160/cpu_machine_learner/resolve/1280b996e645b4839b1944da5879400ec4f36ee7/api/main.py
3.31 kB
| from api.core.app import Demos | |
| __main = Demos() | |
| api = __main.api() | |
| 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 | |
| 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 | |
| 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 | |
| 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 | |
| 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 |