masoudc commited on
Commit
3739ad0
·
1 Parent(s): e2a7b28

Add application file

Browse files
Files changed (1) hide show
  1. app.py +56 -2
app.py CHANGED
@@ -1,5 +1,59 @@
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
 
3
+ x = st.slider('Select a value, and I'll guess your age!')
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 = {
13
+ (13, 17): 0.15, # Teens
14
+ (18, 24): 0.25, # Young adults
15
+ (25, 34): 0.30, # Early career
16
+ (35, 44): 0.15, # Mid career
17
+ (45, 54): 0.08, # Late career
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
25
+ return 18
26
+ elif x > 10000 or x < -10000:
27
+ # Large numbers - probably young
28
+ return 22
29
+ elif x == 69 or x == 420 or x == 80085:
30
+ # Meme numbers - likely teen/young adult
31
+ return 16
32
+ elif x == 0:
33
+ # Default/lazy input - use median young adult age
34
+ return 25
35
+ elif x == 1:
36
+ # Simple input - slight skew older
37
+ return 28
38
+ elif 1 <= x <= 100:
39
+ # Reasonable number - use weighted distribution
40
+ if x <= 20:
41
+ return 24 # Young skew for small numbers
42
+ else:
43
+ return min(int(x * 0.8 + 15), 75) # Scale up but cap at 75
44
+ else:
45
+ # Other numbers - use base distribution
46
+ import random
47
+ brackets = list(age_brackets.items())
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
+ y = estimate_age_from_input(x)
57
+
58
+ st.write(x, ' I think you're about ', y)
59