CoolFace
Apppublic

tugcesi/Obesity-Risk-Classification

sourceHugging Facemitupdated 5mo agoView on Hugging Face
0likes
streamlit_app.py108 linesDownload Raw Back to src
1import streamlit as st2import pandas as pd3import numpy as np4import pickle5 6# ── Model Yükleme ─────────────────────────────────────────────────────────────7with open('src/model.pkl', 'rb') as f:8    model = pickle.load(f)9 10target_map_inverse = {11    0: 'Insufficient Weight',12    1: 'Normal Weight',13    2: 'Overweight Level I',14    3: 'Overweight Level II',15    4: 'Obesity Type I',16    5: 'Obesity Type II',17    6: 'Obesity Type III'18}19 20label_colors = {21    'Insufficient Weight' : '#3498db',22    'Normal Weight'       : '#2ecc71',23    'Overweight Level I'  : '#f1c40f',24    'Overweight Level II' : '#e67e22',25    'Obesity Type I'      : '#e74c3c',26    'Obesity Type II'     : '#c0392b',27    'Obesity Type III'    : '#922b21'28}29 30# ── Sayfa Ayarları ────────────────────────────────────────────────────────────31st.set_page_config(page_title='Obezite Risk Tahmini', page_icon='⚖️', layout='centered')32st.title('⚖️ Obezite Risk Tahmini')33st.markdown('Bilgilerinizi girerek obezite risk sınıfınızı öğrenin.')34st.divider()35 36# ── Kullanıcı Girdileri ───────────────────────────────────────────────────────37col1, col2 = st.columns(2)38 39with col1:40    gender  = st.selectbox('Cinsiyet', ['Male', 'Female'])41    age     = st.slider('Yaş', 14, 65, 25)42    height  = st.number_input('Boy (m)', 1.45, 1.98, 1.70, step=0.01)43    weight  = st.number_input('Kilo (kg)', 39.0, 170.0, 70.0, step=0.5)44    family  = st.selectbox('Ailede Obezite Geçmişi', ['yes', 'no'])45    favc    = st.selectbox('Yüksek Kalorili Yiyecek Tüketimi (FAVC)', ['yes', 'no'])46 47with col2:48    fcvc    = st.slider('Sebze Tüketimi (FCVC)', 1.0, 3.0, 2.0, step=0.1)49    ch2o    = st.slider('Günlük Su Tüketimi (CH2O)', 1.0, 3.0, 2.0, step=0.1)50    faf     = st.slider('Fiziksel Aktivite Sıklığı (FAF)', 0.0, 3.0, 1.0, step=0.1)51    tue     = st.slider('Teknoloji Kullanım Süresi (TUE)', 0.0, 2.0, 1.0, step=0.1)52    caec    = st.selectbox('Öğünler Arası Yeme (CAEC)', ['no', 'Sometimes', 'Frequently', 'Always'])53    calc    = st.selectbox('Alkol Tüketimi (CALC)', ['no', 'Sometimes', 'Frequently', 'Always'])54    scc     = st.selectbox('Kalori Takibi (SCC)', ['yes', 'no'])55 56st.divider()57 58# ── Tahmin ────────────────────────────────────────────────────────────────────59if st.button('🔍 Tahmin Et', use_container_width=True):60 61    caec_map = {'no': 0, 'Sometimes': 1, 'Frequently': 2, 'Always': 3}62    calc_map = {'no': 0, 'Sometimes': 1, 'Frequently': 2, 'Always': 3}63 64    bmi                 = weight / (height ** 2)65    weight_height_ratio = weight / height66    active_score        = faf - tue67    diet_score          = ch2o + fcvc68 69    input_data = pd.DataFrame([{70        'Gender'                        : 1 if gender == 'Male' else 0,71        'Age'                           : age,72        'Height'                        : height,73        'Weight'                        : weight,74        'family_history_with_overweight': 1 if family == 'yes' else 0,75        'FAVC'                          : 1 if favc == 'yes' else 0,76        'FCVC'                          : fcvc,77        'CAEC'                          : caec_map[caec],78        'CH2O'                          : ch2o,       # ← buraya taşındı79        'SCC'                           : 1 if scc == 'yes' else 0,80        'FAF'                           : faf,81        'TUE'                           : tue,82        'CALC'                          : calc_map[calc],83        'BMI'                           : bmi,84        'Weight_Height_Ratio'           : weight_height_ratio,  # ← sona taşındı85        'Active_Score'                  : active_score,86        'Diet_Score'                    : diet_score,87    }])88 89    pred        = model.predict(input_data)[0]90    pred_proba  = model.predict_proba(input_data)[0]91    label       = target_map_inverse[pred]92    color       = label_colors[label]93 94    st.markdown(f"""95    <div style='background-color:{color}22; border-left:6px solid {color};96                padding:20px; border-radius:8px; margin-top:10px'>97        <h2 style='color:{color}; margin:0'>🎯 {label}</h2>98        <p style='margin:5px 0 0 0; color:#555'>BMI: <b>{bmi:.1f}</b></p>99    </div>100    """, unsafe_allow_html=True)101 102    st.markdown('#### 📊 Sınıf Olasılıkları')103    proba_df = pd.DataFrame({104        'Sınıf'    : list(target_map_inverse.values()),105        'Olasılık' : pred_proba106    }).sort_values('Olasılık', ascending=False)107 108    st.bar_chart(proba_df.set_index('Sınıf')['Olasılık'])