Download app.py from dotoking/CEAR: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/dotoking/CEAR/resolve/main/app.py
- Command line
-
hf download hf://dotoking/CEAR/app.py
-
curl -L -o app.py https://huggingface.co/dotoking/CEAR/resolve/main/app.py
1.85 kB
| # 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) |