Commit
·
04bd21c
1
Parent(s):
9fadb74
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 InferenceServer: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(correct_request)
|
| 20 |
+
st.markdown(f'## Output')
|
| 21 |
+
st.write(json.loads(res.text))
|
| 22 |
+
|
| 23 |
+
if not st.session_state['server_started']:
|
| 24 |
+
start_server()
|
| 25 |
+
|
| 26 |
+
st.title('FastAPI Demo')
|
| 27 |
+
input_text = st.text_input(
|
| 28 |
+
label="Write something",
|
| 29 |
+
value="text"
|
| 30 |
+
)
|
| 31 |
+
inference(input_text)
|