Add application file
Browse files
app.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
|
|
|
|
| 4 |
|
| 5 |
def estimate_age_from_input(x):
|
| 6 |
try:
|
| 7 |
# Convert to float and get absolute value
|
| 8 |
x = abs(float(x))
|
| 9 |
-
|
| 10 |
# Base probability of different age groups (skewed young due to internet usage)
|
| 11 |
# Roughly based on internet usage demographics
|
| 12 |
age_brackets = {
|
|
@@ -18,7 +19,7 @@ def estimate_age_from_input(x):
|
|
| 18 |
(55, 64): 0.05, # Pre-retirement
|
| 19 |
(65, 100): 0.02 # Retirement
|
| 20 |
}
|
| 21 |
-
|
| 22 |
# Adjust probabilities based on input value
|
| 23 |
if x > 1000000 or x < -1000000:
|
| 24 |
# Very large/small numbers - likely young person testing limits
|
|
@@ -48,12 +49,14 @@ def estimate_age_from_input(x):
|
|
| 48 |
weights = [p for _, p in brackets]
|
| 49 |
chosen = random.choices(brackets, weights=weights)[0][0]
|
| 50 |
return random.randint(chosen[0], chosen[1])
|
| 51 |
-
|
| 52 |
except (ValueError, TypeError):
|
| 53 |
# Non-numeric input - assume young user testing system
|
| 54 |
return 19
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
st.write(x, ' I think you're about ', y)
|
| 59 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
# Prompt the user to input a value rather than using a slider
|
| 4 |
+
x = st.text_input('Enter a value, and I will guess your age!')
|
| 5 |
|
| 6 |
def estimate_age_from_input(x):
|
| 7 |
try:
|
| 8 |
# Convert to float and get absolute value
|
| 9 |
x = abs(float(x))
|
| 10 |
+
|
| 11 |
# Base probability of different age groups (skewed young due to internet usage)
|
| 12 |
# Roughly based on internet usage demographics
|
| 13 |
age_brackets = {
|
|
|
|
| 19 |
(55, 64): 0.05, # Pre-retirement
|
| 20 |
(65, 100): 0.02 # Retirement
|
| 21 |
}
|
| 22 |
+
|
| 23 |
# Adjust probabilities based on input value
|
| 24 |
if x > 1000000 or x < -1000000:
|
| 25 |
# Very large/small numbers - likely young person testing limits
|
|
|
|
| 49 |
weights = [p for _, p in brackets]
|
| 50 |
chosen = random.choices(brackets, weights=weights)[0][0]
|
| 51 |
return random.randint(chosen[0], chosen[1])
|
| 52 |
+
|
| 53 |
except (ValueError, TypeError):
|
| 54 |
# Non-numeric input - assume young user testing system
|
| 55 |
return 19
|
| 56 |
|
| 57 |
+
# Only attempt to calculate if input is provided
|
| 58 |
+
if x:
|
| 59 |
+
y = estimate_age_from_input(x)
|
| 60 |
+
st.write(f'You entered: {x}, I think you are about {y} years old!')
|
| 61 |
|
|
|
|
| 62 |
|