# app.py (Simplified Gradio code) import gradio as gr from cear_model import CEARModel import pandas as pd # ... (include logic to load PLATFORM_WEIGHTS) # Instantiate the model globally cear_analyzer = CEARModel() def analyze_user_data(input_table): # 1. Convert Gradio input (list of lists) to DataFrame user_data_df = pd.DataFrame(input_table, columns=['platform_name', 'minutes_per_week']) user_data_df['minutes_per_week'] = pd.to_numeric(user_data_df['minutes_per_week'], errors='coerce').fillna(0) # 2. Call the core model raw_scores = cear_analyzer.calculate_scores(user_data_df) # 3. Format output for the user (The "App" layer) summary = f""" ## 📊 Analysis Summary - **Cultural Connectedness Score (C-Score):** **{raw_scores['C_Score']:.2f}** - **Algorithmic Risk Score (A-Risk):** **{raw_scores['A_Risk']:.2f}** - **Platform Diversity Index (D-Index):** **{raw_scores['D_Index']:.2f}** --- ### 📝 Interpretation *Your C-Score is based on logarithmically scaled time, reflecting diminishing returns. Your A-Risk is based on raw time, reflecting concentrated attention.* """ # Return the formatted string and potentially a table of efficiency return summary, pd.DataFrame(raw_scores['Per_Platform_Efficiency']) # Define the Gradio interface iface = gr.Interface( fn=analyze_user_data, inputs=gr.Dataframe( headers=['platform_name', 'minutes_per_week'], row_count=5, col_count=(2, 'fixed'), label="Weekly Screen Time Input (Source data from OS Tracker)" ), outputs=[ gr.Markdown(label="Score Results"), gr.Dataframe(label="Per-Platform Cultural Efficiency") ], title="CEAR Baseline: Cultural Exposure & Algorithmic Risk Analyzer" ) iface.launch(server_name="0.0.0.0", server_port=7860)