Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| # Load the largest hospitals data | |
| data = [ | |
| {"Hospital": "Texas Health Presbyterian Hospital Dallas", "City": "Dallas", "State": "TX", "Beds": 898}, | |
| {"Hospital": "Cedars-Sinai Medical Center", "City": "Los Angeles", "State": "CA", "Beds": 886}, | |
| {"Hospital": "Jackson Memorial Hospital", "City": "Miami", "State": "FL", "Beds": 1618}, | |
| {"Hospital": "New York-Presbyterian Hospital", "City": "New York", "State": "NY", "Beds": 2528}, | |
| {"Hospital": "Barnes-Jewish Hospital", "City": "St. Louis", "State": "MO", "Beds": 1252}, | |
| ] | |
| # Create a Pandas DataFrame from the data | |
| df = pd.DataFrame(data) | |
| # Define the generative AI function | |
| def generate_data(df, num_rows=1): | |
| # Calculate the mean and standard deviation of the Beds column | |
| bed_mean = df["Beds"].mean() | |
| bed_std = df["Beds"].std() | |
| # Generate new data using a normal distribution | |
| new_data = { | |
| "Hospital": [f"Generated Hospital {i}" for i in range(num_rows)], | |
| "City": np.random.choice(df["City"], num_rows), | |
| "State": np.random.choice(df["State"], num_rows), | |
| "Beds": np.random.normal(bed_mean, bed_std, num_rows).astype(int) | |
| } | |
| # Create a new DataFrame from the generated data and return it | |
| return pd.DataFrame(new_data) | |
| # Define the Streamlit app | |
| def app(): | |
| st.title("Generative AI Demo") | |
| # Display the original data | |
| st.subheader("Original Data") | |
| st.write(df) | |
| # Generate new data and display it | |
| st.subheader("Generated Data") | |
| num_rows = st.slider("Number of rows to generate", min_value=1, max_value=100, value=1) | |
| new_data = generate_data(df, num_rows=num_rows) | |
| st.write(new_data) | |
| # Run the Streamlit app | |
| if __name__ == "__main__": | |
| app() | |