Spaces:
Sleeping
Sleeping
Create streamlit_app.py
Browse files- streamlit_app.py +36 -0
streamlit_app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import requests
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
# Set the title of the app
|
| 6 |
+
st.title("Medical Prediction Model")
|
| 7 |
+
|
| 8 |
+
# Instruction text
|
| 9 |
+
st.write("Enter 32 features for prediction:")
|
| 10 |
+
|
| 11 |
+
# Create 32 input fields for user input
|
| 12 |
+
inputs = []
|
| 13 |
+
for i in range(32):
|
| 14 |
+
value = st.number_input(f"Feature {i + 1}", min_value=0, step=1)
|
| 15 |
+
inputs.append(value)
|
| 16 |
+
|
| 17 |
+
# Button to make prediction
|
| 18 |
+
if st.button("Predict"):
|
| 19 |
+
# Prepare the data for the request
|
| 20 |
+
input_data = {"features": inputs}
|
| 21 |
+
|
| 22 |
+
# Set the URL for your FastAPI backend
|
| 23 |
+
url = "http://localhost:8501/predict" # Replace with your actual URL if deployed
|
| 24 |
+
|
| 25 |
+
# Make a POST request
|
| 26 |
+
response = requests.post(url, json=input_data) # Send the wrapped input_data
|
| 27 |
+
|
| 28 |
+
# Check the response status code
|
| 29 |
+
if response.status_code == 200:
|
| 30 |
+
# Get the JSON response
|
| 31 |
+
prediction = response.json()
|
| 32 |
+
# Display the prediction results
|
| 33 |
+
st.success("Prediction Results:")
|
| 34 |
+
st.json(prediction)
|
| 35 |
+
else:
|
| 36 |
+
st.error(f"Error: {response.status_code} - {response.text}")
|