File size: 1,845 Bytes
7bf8517
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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)