Tony Shepherd commited on
Commit
78d106c
1 Parent(s): 8420eeb

created hello world docker app as in HF tutorial

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. app.py +5 -37
  3. requirements.txt +6 -3
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
app.py CHANGED
@@ -1,39 +1,7 @@
1
- # import streamlit as st
2
- # x = st.slider('Select a value')
3
- # st.write(x, 'squared is', x * x)
4
 
5
- # The code below confirms there is no GPU available
6
- # import torch
7
- # st.write("torch version: " + torch.__version__)
8
- # st.write("cuda available: " + str(torch.cuda.is_available()))
9
- # st.write("No of GPUs: " + str(torch.cuda.device_count()))
10
 
11
- # Hypothesis: Huggingface will host a static copy of a model so we can use that in a FastAPI endpoint to be called externally
12
- # Requirement: ability to get anything back from a post request of an API hosted on Huiggingface server
13
- # (separate to the requirement of a GPU, which will cost money)
14
-
15
- # If so, the only thing that's in the huggingface space is opensource anyway, so no risk of losing code IPR that is outside the space (the code calling the model API)
16
-
17
- from fastapi import FastAPI, Request, HTTPException
18
- from payload import SomeText
19
-
20
- app=FastAPI(title="Hello Huggingworld",
21
- version="1.0",
22
- debug=True,
23
- swagger_ui_bundle_js= "//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js",
24
- swagger_ui_standalone_preset_js= "//unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js",
25
- summary="API to return the text belonging to a payload."
26
- )
27
-
28
- @app.post("/api/test-io-capability")
29
- async def test_io(request: Request, input: SomeText): #
30
- """
31
- Takes in some raw text and returns the same
32
- """
33
-
34
- if len(input.text) > 0:
35
-
36
- return input.text
37
-
38
- else:
39
- raise HTTPException(status_code=400, detail = "payload contains no text")
 
1
+ from fastapi import FastAPI
 
 
2
 
3
+ app = FastAPI()
 
 
 
 
4
 
5
+ @app.get("/")
6
+ def read_root():
7
+ return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,3 +1,6 @@
1
- torch
2
- pydantic
3
- fastapi
 
 
 
 
1
+ fastapi==0.74.*
2
+ requests==2.27.*
3
+ sentencepiece==0.1.*
4
+ torch==1.11.*
5
+ transformers==4.*
6
+ uvicorn[standard]==0.17.*