huaqianshu_z commited on
Commit
5cc58b0
·
1 Parent(s): 4f6419e

Add application file

Browse files
Files changed (3) hide show
  1. app.py +19 -2
  2. app.py.1 +5 -0
  3. requirements.txt +3 -0
app.py CHANGED
@@ -1,5 +1,22 @@
1
  import streamlit as st
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
 
1
  import streamlit as st
2
+ from fastapi import FastAPI
3
+ from fastapi.middleware.wsgi import WSGIMiddleware
4
 
5
+ app = FastAPI()
6
+
7
+ # Streamlit app as a function
8
+ def streamlit_app():
9
+ x = st.slider('Select a value')
10
+ st.write(x, 'squared is', x * x)
11
+
12
+ @app.get("/api/square/{value}")
13
+ def read_square(value: int):
14
+ return {"value": value, "squared": value * value}
15
+
16
+ # Mount the Streamlit app
17
+ app.mount("/", WSGIMiddleware(lambda environ, start_response: streamlit_app()))
18
+
19
+ if __name__ == "__main__":
20
+ import uvicorn
21
+ uvicorn.run(app, host="0.0.0.0", port=8000)
22
 
app.py.1 ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ x = st.slider('Select a value')
4
+ st.write(x, 'squared is', x * x)
5
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ fastapi
3
+ uvicorn