Fastapi
Browse files- .gitignore +1 -0
- __pycache__/app.cpython-311.pyc +0 -0
- __pycache__/funciones.cpython-311.pyc +0 -0
- app.py +28 -8
- funciones.py +9 -0
- requirements.txt +2 -1
.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1 |
/venv/
|
|
|
|
1 |
/venv/
|
2 |
+
/__pycache__/
|
__pycache__/app.cpython-311.pyc
ADDED
Binary file (1.94 kB). View file
|
|
__pycache__/funciones.cpython-311.pyc
ADDED
Binary file (511 Bytes). View file
|
|
app.py
CHANGED
@@ -1,9 +1,29 @@
|
|
1 |
-
from
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from io import BytesIO
|
2 |
+
import funciones
|
3 |
+
from fastapi import FastAPI, Form
|
4 |
+
from fastapi import FastAPI, File, UploadFile
|
5 |
+
from fastapi.responses import StreamingResponse, FileResponse, JSONResponse
|
6 |
|
7 |
+
app = FastAPI()
|
8 |
+
|
9 |
+
# Nuevo endpoint para Health Check
|
10 |
+
@app.get("/health",
|
11 |
+
tags=["Health Check"],
|
12 |
+
description="Verifica el estado de salud de la API.",
|
13 |
+
summary="Health Check"
|
14 |
+
)
|
15 |
+
async def health_check():
|
16 |
+
"""
|
17 |
+
Este endpoint devuelve una respuesta 200 OK para indicar que la API está funcionando.
|
18 |
+
"""
|
19 |
+
return JSONResponse(content={"status": "ok"}, status_code=200)
|
20 |
+
|
21 |
+
@app.post("/echo-image/",
|
22 |
+
description="Test endpoint que recibe y regresa la misma imagen, para probar envío, recepción y problemas con api o red.",
|
23 |
+
summary="Summary"
|
24 |
+
)
|
25 |
+
async def echo_image(image: UploadFile = File(...)):
|
26 |
+
if not image.content_type.startswith("image/"):
|
27 |
+
return {"error": "El archivo no es una imagen"}
|
28 |
+
contents = await image.read()
|
29 |
+
return StreamingResponse(BytesIO(contents), media_type=image.content_type)
|
funciones.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio_client import Client, handle_file
|
2 |
+
|
3 |
+
client = Client("Moibe/api_rapicash")
|
4 |
+
result = client.predict(
|
5 |
+
img=handle_file('dnid.png'),
|
6 |
+
lang="en",
|
7 |
+
api_name="/predict"
|
8 |
+
)
|
9 |
+
print(result)
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
gradio_client
|
|
|
|
1 |
+
gradio_client
|
2 |
+
fastapi
|