Spaces:
Runtime error
Runtime error
Commit
·
3e26431
0
Parent(s):
Duplicate from templates/fastapi_with_streamlit
Browse filesCo-authored-by: Omar Sanseviero <osanseviero@users.noreply.huggingface.co>
- .gitattributes +27 -0
- README.md +14 -0
- app.py +34 -0
- inference_server.py +10 -0
- requirements.txt +2 -0
.gitattributes
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Fastapi_with_streamlit
|
3 |
+
emoji: 🌍
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: green
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.2.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: templates/fastapi_with_streamlit
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
import requests
|
6 |
+
import socket
|
7 |
+
|
8 |
+
def start_server():
|
9 |
+
os.system("uvicorn inference_server:app --port 8080 --host 0.0.0.0 --workers 2")
|
10 |
+
st.session_state['server_started'] = True
|
11 |
+
|
12 |
+
def is_port_in_use(port):
|
13 |
+
import socket
|
14 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
15 |
+
return s.connect_ex(('0.0.0.0', port)) == 0
|
16 |
+
|
17 |
+
def inference(input_text):
|
18 |
+
req = "http://0.0.0.0:8080?input_text=" + input_text
|
19 |
+
res = requests.get(req)
|
20 |
+
st.markdown(f'## Output')
|
21 |
+
st.write(json.loads(res.text))
|
22 |
+
|
23 |
+
if 'server_started' not in st.session_state:
|
24 |
+
st.session_state['server_started'] = False
|
25 |
+
|
26 |
+
if not st.session_state['server_started']:
|
27 |
+
start_server()
|
28 |
+
|
29 |
+
st.title('FastAPI Demo')
|
30 |
+
input_text = st.text_input(
|
31 |
+
label="Write something",
|
32 |
+
value="text"
|
33 |
+
)
|
34 |
+
inference(input_text)
|
inference_server.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import uvicorn
|
2 |
+
from fastapi import FastAPI
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
|
6 |
+
# Here you can do things such as load your models
|
7 |
+
|
8 |
+
@app.get("/")
|
9 |
+
def read_root(input_text):
|
10 |
+
return {f"Hello {input_text}!"}
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|