jm0x commited on
Commit
3189aec
·
1 Parent(s): 799628c

Terminado para probar inferencia

Browse files
Files changed (2) hide show
  1. Dockerfile +9 -0
  2. app.py +31 -0
Dockerfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+ RUN pip install --no-cache-dir fastapi uvicorn huggingface_hub
5
+
6
+ COPY app.py /app/app.py
7
+
8
+ EXPOSE 7860
9
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from fastapi import FastAPI, HTTPException
3
+ from pydantic import BaseModel
4
+ from huggingface_hub import InferenceClient
5
+
6
+ MODEL_ID = os.getenv(
7
+ "MODEL_ID",
8
+ "distilbert/distilbert-base-uncased-finetuned-sst-2-english",
9
+ )
10
+
11
+ client = InferenceClient(
12
+ provider="hf-inference",
13
+ api_key=os.getenv["HF_TOKEN"],
14
+ )
15
+
16
+ app = FastAPI()
17
+
18
+ class Payload(BaseModel):
19
+ text: str
20
+
21
+ @app.post("/analyze")
22
+ def analyze(p: Payload):
23
+ if not p.text.strip():
24
+ raise HTTPException(status_code=400, detail="Empty text")
25
+
26
+ result = client.text_classification(
27
+ p.text,
28
+ model=MODEL_ID,
29
+ )
30
+
31
+ return {"model": MODEL_ID, "result": result}