liturriago commited on
Commit
55b6f51
·
1 Parent(s): 2467e4b

ClassificationVCAPI\nAPI en HuggingFace Space con TensorFlow Serving-like pipeline.

Browse files
Files changed (7) hide show
  1. .gitattributes +1 -0
  2. Dockerfile +17 -0
  3. README.md +5 -6
  4. app.py +25 -0
  5. model.keras +3 -0
  6. requirements.txt +4 -0
  7. runtime.txt +1 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.keras filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ # Crear usuario no-root
4
+ RUN useradd -m -u 1000 user
5
+ USER user
6
+ ENV PATH="/home/user/.local/bin:$PATH"
7
+
8
+ WORKDIR /app
9
+
10
+ COPY --chown=user ./requirements.txt /app/requirements.txt
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ COPY --chown=user . /app
14
+
15
+ EXPOSE 7860
16
+
17
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,12 +1,11 @@
1
  ---
2
  title: ClassificationVCAPI
3
- emoji: 🔥
4
- colorFrom: yellow
5
- colorTo: blue
6
  sdk: docker
7
  pinned: false
8
- license: cc-by-nc-4.0
9
- short_description: Deployment space for a computer vision model
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
  title: ClassificationVCAPI
3
+ emoji: 🚀
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: docker
7
  pinned: false
 
 
8
  ---
9
 
10
+ # ClassificationVCAPI
11
+ API en HuggingFace Space con TensorFlow Serving-like pipeline.
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ import tensorflow as tf
4
+ import base64
5
+ import numpy as np
6
+
7
+ app = FastAPI(title="TF Serving Base64 API")
8
+
9
+ class ImagePayload(BaseModel):
10
+ image_base64: str
11
+
12
+ @app.post("/predict")
13
+ def predict(payload: ImagePayload):
14
+ # Decodificar base64
15
+ img_bytes = base64.b64decode(payload.image_base64)
16
+ img = tf.image.decode_image(img_bytes, channels=3)
17
+ img = tf.image.resize(img, (224, 224))
18
+ img = img / 255.0
19
+ img = tf.expand_dims(img, 0)
20
+
21
+ # Cargar modelo local
22
+ model = tf.keras.models.load_model("model.keras")
23
+
24
+ pred = model.predict(img).tolist()
25
+ return {"prediction": pred}
model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbd4b43027e4688614da415846066cf89e071c1a5ca8d93b09de211363c59374
3
+ size 14732001
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ tensorflow-cpu==2.17.0
4
+ numpy
runtime.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ python-3.10