dotoking commited on
Commit
7bf8517
Β·
verified Β·
1 Parent(s): b2c5443

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -49
app.py CHANGED
@@ -1,49 +1,49 @@
1
- # app.py (Simplified Gradio code)
2
-
3
- import gradio as gr
4
- from cear_model import CEARModel
5
- import pandas as pd
6
- # ... (include logic to load PLATFORM_WEIGHTS)
7
-
8
- # Instantiate the model globally
9
- cear_analyzer = CEARModel()
10
-
11
- def analyze_user_data(input_table):
12
- # 1. Convert Gradio input (list of lists) to DataFrame
13
- user_data_df = pd.DataFrame(input_table, columns=['platform_name', 'minutes_per_week'])
14
- user_data_df['minutes_per_week'] = pd.to_numeric(user_data_df['minutes_per_week'], errors='coerce').fillna(0)
15
-
16
- # 2. Call the core model
17
- raw_scores = cear_analyzer.calculate_scores(user_data_df)
18
-
19
- # 3. Format output for the user (The "App" layer)
20
- summary = f"""
21
- ## πŸ“Š Analysis Summary
22
- - **Cultural Connectedness Score (C-Score):** **{raw_scores['C_Score']:.2f}**
23
- - **Algorithmic Risk Score (A-Risk):** **{raw_scores['A_Risk']:.2f}**
24
- - **Platform Diversity Index (D-Index):** **{raw_scores['D_Index']:.2f}**
25
- ---
26
- ### πŸ“ Interpretation
27
- *Your C-Score is based on logarithmically scaled time, reflecting diminishing returns. Your A-Risk is based on raw time, reflecting concentrated attention.*
28
- """
29
-
30
- # Return the formatted string and potentially a table of efficiency
31
- return summary, pd.DataFrame(raw_scores['Per_Platform_Efficiency'])
32
-
33
- # Define the Gradio interface
34
- iface = gr.Interface(
35
- fn=analyze_user_data,
36
- inputs=gr.Dataframe(
37
- headers=['platform_name', 'minutes_per_week'],
38
- row_count=5,
39
- col_count=(2, 'fixed'),
40
- label="Weekly Screen Time Input (Source data from OS Tracker)"
41
- ),
42
- outputs=[
43
- gr.Markdown(label="Score Results"),
44
- gr.Dataframe(label="Per-Platform Cultural Efficiency")
45
- ],
46
- title="CEAR Baseline: Cultural Exposure & Algorithmic Risk Analyzer"
47
- )
48
-
49
- iface.launch()
 
1
+ # app.py (Simplified Gradio code)
2
+
3
+ import gradio as gr
4
+ from cear_model import CEARModel
5
+ import pandas as pd
6
+ # ... (include logic to load PLATFORM_WEIGHTS)
7
+
8
+ # Instantiate the model globally
9
+ cear_analyzer = CEARModel()
10
+
11
+ def analyze_user_data(input_table):
12
+ # 1. Convert Gradio input (list of lists) to DataFrame
13
+ user_data_df = pd.DataFrame(input_table, columns=['platform_name', 'minutes_per_week'])
14
+ user_data_df['minutes_per_week'] = pd.to_numeric(user_data_df['minutes_per_week'], errors='coerce').fillna(0)
15
+
16
+ # 2. Call the core model
17
+ raw_scores = cear_analyzer.calculate_scores(user_data_df)
18
+
19
+ # 3. Format output for the user (The "App" layer)
20
+ summary = f"""
21
+ ## πŸ“Š Analysis Summary
22
+ - **Cultural Connectedness Score (C-Score):** **{raw_scores['C_Score']:.2f}**
23
+ - **Algorithmic Risk Score (A-Risk):** **{raw_scores['A_Risk']:.2f}**
24
+ - **Platform Diversity Index (D-Index):** **{raw_scores['D_Index']:.2f}**
25
+ ---
26
+ ### πŸ“ Interpretation
27
+ *Your C-Score is based on logarithmically scaled time, reflecting diminishing returns. Your A-Risk is based on raw time, reflecting concentrated attention.*
28
+ """
29
+
30
+ # Return the formatted string and potentially a table of efficiency
31
+ return summary, pd.DataFrame(raw_scores['Per_Platform_Efficiency'])
32
+
33
+ # Define the Gradio interface
34
+ iface = gr.Interface(
35
+ fn=analyze_user_data,
36
+ inputs=gr.Dataframe(
37
+ headers=['platform_name', 'minutes_per_week'],
38
+ row_count=5,
39
+ col_count=(2, 'fixed'),
40
+ label="Weekly Screen Time Input (Source data from OS Tracker)"
41
+ ),
42
+ outputs=[
43
+ gr.Markdown(label="Score Results"),
44
+ gr.Dataframe(label="Per-Platform Cultural Efficiency")
45
+ ],
46
+ title="CEAR Baseline: Cultural Exposure & Algorithmic Risk Analyzer"
47
+ )
48
+
49
+ iface.launch(server_name="0.0.0.0", server_port=7860)