Spaces:
Sleeping
Sleeping
Tony Shepherd
commited on
Commit
•
abb1f73
1
Parent(s):
0817f3d
attempt at a helloworld FastApi endpoint
Browse files- app.py +32 -11
- payload.py +15 -0
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,16 +1,37 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
|
3 |
# x = st.slider('Select a value')
|
4 |
# st.write(x, 'squared is', x * x)
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
st.write("cuda available: " + str(torch.cuda.is_available()))
|
13 |
-
st.write(" ")
|
14 |
-
st.write("No of GPUs: " + str(torch.cuda.device_count()))
|
15 |
-
st.write(" ")
|
16 |
-
st.write("device name: " + torch.cuda.get_device_name())
|
|
|
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 |
+
from fastapi import FastAPI, Request, HTTPException
|
16 |
+
from payload import SomeText
|
17 |
+
|
18 |
+
app=FastAPI(title="Hello Huggingworld",
|
19 |
+
version="1.0",
|
20 |
+
debug=True,
|
21 |
+
swagger_ui_bundle_js= "//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js",
|
22 |
+
swagger_ui_standalone_preset_js= "//unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js",
|
23 |
+
summary="API to return the text belonging to a payload."
|
24 |
+
)
|
25 |
+
|
26 |
+
@app.post("/api/test-io-capability")
|
27 |
+
async def test_io(request: Request, input: SomeText): #
|
28 |
+
"""
|
29 |
+
Takes in some raw text and returns the same
|
30 |
+
"""
|
31 |
+
|
32 |
+
if len(input.text) > 0:
|
33 |
|
34 |
+
return input.text
|
35 |
|
36 |
+
else:
|
37 |
+
raise HTTPException(status_code=400, detail = "payload contains no text")
|
|
|
|
|
|
|
|
|
|
payload.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
|
3 |
+
class SomeText(BaseModel):
|
4 |
+
""" This Data Class defines ...
|
5 |
+
"""
|
6 |
+
text: str
|
7 |
+
model_config = {
|
8 |
+
"json_schema_extra": {
|
9 |
+
"examples": [
|
10 |
+
{
|
11 |
+
"text": "twoday is gonna be the day that they're gonna throw it back to you."
|
12 |
+
}
|
13 |
+
]
|
14 |
+
}
|
15 |
+
}
|
requirements.txt
CHANGED
@@ -1 +1,3 @@
|
|
1 |
-
torch
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
pydantic
|
3 |
+
fastapi
|