Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import random
|
3 |
+
|
4 |
+
def perform_sampling(population_size, sample_size, seed=None):
|
5 |
+
if seed is not None:
|
6 |
+
random.seed(seed)
|
7 |
+
population = list(range(1, population_size + 1))
|
8 |
+
if sample_size > population_size:
|
9 |
+
st.error("Sample size cannot be greater than population size.")
|
10 |
+
return None
|
11 |
+
sample = random.sample(population, sample_size)
|
12 |
+
return sample
|
13 |
+
|
14 |
+
def main():
|
15 |
+
# Sidebar for user inputs
|
16 |
+
st.sidebar.title("Input Parameters")
|
17 |
+
population_size = st.sidebar.number_input('Enter Population Size', min_value=1, value=1000, step=1)
|
18 |
+
sample_size = st.sidebar.number_input('Enter Sample Size', min_value=1, value=50, step=1)
|
19 |
+
seed = st.sidebar.number_input('Enter Random Seed (optional)', min_value=0, value=None, step=1, format='%d', key='seed')
|
20 |
+
|
21 |
+
# Main screen for title, description, and output
|
22 |
+
st.title('Simple Random Sampling App')
|
23 |
+
st.markdown("""
|
24 |
+
## Description
|
25 |
+
This application performs simple random sampling on a specified population. Enter the population size,
|
26 |
+
sample size, and an optional random seed in the sidebar and press 'Generate Sample' to see the results.
|
27 |
+
|
28 |
+
## Instructions
|
29 |
+
- **Population Size**: Total number of items in your population.
|
30 |
+
- **Sample Size**: Number of items to randomly select from your population.
|
31 |
+
- **Random Seed**: A seed value to ensure reproducibility of your sample.
|
32 |
+
""")
|
33 |
+
|
34 |
+
if st.sidebar.button('Generate Sample'):
|
35 |
+
sample = perform_sampling(population_size, sample_size, seed)
|
36 |
+
if sample is not None:
|
37 |
+
st.write(f'### Random Sample Output')
|
38 |
+
st.write(f'Random Sample: {sample}')
|
39 |
+
st.write(f'Sample Size: {len(sample)}')
|
40 |
+
if seed is not None:
|
41 |
+
st.write(f'Random Seed Used: {seed}')
|
42 |
+
|
43 |
+
if __name__ == '__main__':
|
44 |
+
main()
|