Raahul07 commited on
Commit
92ddabd
·
verified ·
1 Parent(s): 55161e4

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +13 -0
  2. app.py +18 -0
  3. requirements.txt +4 -0
  4. start.sh +2 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt /app/
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY app.py /app/
9
+ COPY start.sh /app/
10
+ RUN chmod +x /app/start.sh
11
+
12
+ EXPOSE 7860
13
+ CMD ["/app/start.sh"]
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from transformers import pipeline
4
+
5
+ app = FastAPI()
6
+ generator = pipeline("text-generation", model="sshleifer/tiny-gpt2")
7
+
8
+ class InputText(BaseModel):
9
+ prompt: str
10
+
11
+ @app.get("/")
12
+ def home():
13
+ return {"message": "Welcome to my Hugging Face Docker App!"}
14
+
15
+ @app.post("/predict")
16
+ def predict(data: InputText):
17
+ result = generator(data.prompt, max_length=40)
18
+ return {"result": result[0]["generated_text"]}
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ transformers
4
+ torch
start.sh ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env bash
2
+ uvicorn app:app --host 0.0.0.0 --port 7860