Add FastAPI for handling POST requests
Browse files- app.py +17 -6
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,7 +1,14 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
@st.cache(allow_output_mutation=True)
|
@@ -11,8 +18,12 @@ def load_model():
|
|
11 |
|
12 |
model = load_model()
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
from fastapi import FastAPI
|
4 |
+
from pydantic import BaseModel
|
5 |
+
import uvicorn
|
6 |
|
7 |
+
app = FastAPI()
|
8 |
+
|
9 |
+
|
10 |
+
class Input(BaseModel):
|
11 |
+
input: str
|
12 |
|
13 |
|
14 |
@st.cache(allow_output_mutation=True)
|
|
|
18 |
|
19 |
model = load_model()
|
20 |
|
21 |
+
|
22 |
+
@app.post("/")
|
23 |
+
def generate_text(input: Input):
|
24 |
+
result = model(input.input)
|
25 |
+
return {"generated_text": result[0]["generated_text"]}
|
26 |
+
|
27 |
+
|
28 |
+
if __name__ == "__main__":
|
29 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
requirements.txt
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
streamlit
|
2 |
-
transformers
|
|
|
|
|
|
1 |
streamlit
|
2 |
+
transformers
|
3 |
+
fastapi
|
4 |
+
uvicorn
|