norygano commited on
Commit
6b22889
·
1 Parent(s): a4cdb27

Presentation

Browse files
Files changed (3) hide show
  1. app.py +5 -13
  2. plot.py +10 -10
  3. requirements.txt +1 -1
app.py CHANGED
@@ -9,7 +9,7 @@ import os
9
 
10
  # Define initial threshold values at the top of the script
11
  default_cause_threshold = 20
12
- default_indicator_threshold = 3
13
 
14
  # Load the trained model and tokenizer
15
  model_directory = "norygano/causalBERT"
@@ -31,7 +31,7 @@ st.markdown(
31
  unsafe_allow_html=True
32
  )
33
  st.markdown("[Model](https://huggingface.co/norygano/causalBERT) | [Data](https://huggingface.co/datasets/norygano/causenv) | [Project](https://www.uni-trier.de/universitaet/fachbereiche-faecher/fachbereich-ii/faecher/germanistik/professurenfachteile/germanistische-linguistik/professoren/prof-dr-martin-wengeler/kontroverse-diskurse/individium-gesellschaft)")
34
- st.write("Tags indicators and causes in explicit attributions of causality. GER only (atm)")
35
 
36
  # Create tabs
37
  tab1, tab2, tab3, tab4, tab5 = st.tabs(["Prompt", "Indicators", "Causes", "Scatter", "Sankey"])
@@ -42,7 +42,7 @@ with tab1:
42
  "Autos stehen im Verdacht, Waldsterben zu verursachen.",
43
  "Fußball führt zu Waldschäden.",
44
  "Haustüren tragen zum Betonsterben bei.",
45
- ]), placeholder="Your Sentences here.")
46
 
47
  sentences = [sentence.strip() for sentence in sentences_input.splitlines() if sentence.strip()]
48
 
@@ -84,8 +84,6 @@ with tab1:
84
 
85
  # Research Insights Tab
86
  with tab2:
87
- st.write("## Indicators")
88
-
89
  # Overall
90
  st.subheader("Overall")
91
  fig_overall = indicator_chart(chart_type='overall')
@@ -97,29 +95,23 @@ with tab2:
97
  st.plotly_chart(fig_individual, use_container_width=True)
98
 
99
  with tab3:
100
- st.write("## Causes")
101
  fig_causes = causes_chart()
102
  st.plotly_chart(fig_causes, use_container_width=True)
103
 
104
  with tab4:
105
- st.write("## Scatter")
106
  fig_scatter = scatter()
107
  st.plotly_chart(fig_scatter, use_container_width=True)
108
 
109
  with tab5:
110
- st.write("## Sankey")
111
-
112
  # Fixed height for the Sankey chart container
113
  with st.container():
114
  # Retrieve slider values and generate the diagram
115
  cause_threshold = st.session_state.get("cause_threshold", default_cause_threshold)
116
  indicator_threshold = st.session_state.get("indicator_threshold", default_indicator_threshold)
117
-
118
  fig_sankey = sankey(cause_threshold=cause_threshold, indicator_threshold=indicator_threshold)
119
  st.plotly_chart(fig_sankey, use_container_width=True)
120
 
121
  # Place sliders below the chart container
122
  with st.container():
123
- st.write("Adjust thresholds for Sankey diagram:")
124
- cause_threshold = st.slider("Cause Threshold", min_value=1, max_value=100, value=default_cause_threshold, key="cause_threshold")
125
- indicator_threshold = st.slider("Indicator Threshold", min_value=1, max_value=100, value=default_indicator_threshold, key="indicator_threshold")
 
9
 
10
  # Define initial threshold values at the top of the script
11
  default_cause_threshold = 20
12
+ default_indicator_threshold = 15
13
 
14
  # Load the trained model and tokenizer
15
  model_directory = "norygano/causalBERT"
 
31
  unsafe_allow_html=True
32
  )
33
  st.markdown("[Model](https://huggingface.co/norygano/causalBERT) | [Data](https://huggingface.co/datasets/norygano/causenv) | [Project](https://www.uni-trier.de/universitaet/fachbereiche-faecher/fachbereich-ii/faecher/germanistik/professurenfachteile/germanistische-linguistik/professoren/prof-dr-martin-wengeler/kontroverse-diskurse/individium-gesellschaft)")
34
+ st.write("Tags indicators and causes in explicit attributions of causality.")
35
 
36
  # Create tabs
37
  tab1, tab2, tab3, tab4, tab5 = st.tabs(["Prompt", "Indicators", "Causes", "Scatter", "Sankey"])
 
42
  "Autos stehen im Verdacht, Waldsterben zu verursachen.",
43
  "Fußball führt zu Waldschäden.",
44
  "Haustüren tragen zum Betonsterben bei.",
45
+ ]), placeholder="German only (currently)")
46
 
47
  sentences = [sentence.strip() for sentence in sentences_input.splitlines() if sentence.strip()]
48
 
 
84
 
85
  # Research Insights Tab
86
  with tab2:
 
 
87
  # Overall
88
  st.subheader("Overall")
89
  fig_overall = indicator_chart(chart_type='overall')
 
95
  st.plotly_chart(fig_individual, use_container_width=True)
96
 
97
  with tab3:
 
98
  fig_causes = causes_chart()
99
  st.plotly_chart(fig_causes, use_container_width=True)
100
 
101
  with tab4:
 
102
  fig_scatter = scatter()
103
  st.plotly_chart(fig_scatter, use_container_width=True)
104
 
105
  with tab5:
 
 
106
  # Fixed height for the Sankey chart container
107
  with st.container():
108
  # Retrieve slider values and generate the diagram
109
  cause_threshold = st.session_state.get("cause_threshold", default_cause_threshold)
110
  indicator_threshold = st.session_state.get("indicator_threshold", default_indicator_threshold)
 
111
  fig_sankey = sankey(cause_threshold=cause_threshold, indicator_threshold=indicator_threshold)
112
  st.plotly_chart(fig_sankey, use_container_width=True)
113
 
114
  # Place sliders below the chart container
115
  with st.container():
116
+ cause_threshold = st.slider("Cause >", min_value=1, max_value=100, value=default_cause_threshold, key="cause_threshold")
117
+ indicator_threshold = st.slider("Indicator >", min_value=1, max_value=100, value=default_indicator_threshold, key="indicator_threshold")
 
plot.py CHANGED
@@ -61,6 +61,7 @@ def indicator_chart(chart_type='overall'):
61
  texttemplate='%{y}',
62
  textposition='inside',
63
  textfont=dict(color='rgb(255, 255, 255)'),
 
64
  )
65
 
66
  fig.update_layout(
@@ -150,32 +151,31 @@ def scatter(include_modality=False):
150
  df_reduced = pd.concat([df_reduced, metadata.reset_index(drop=True)], axis=1)
151
 
152
  # Plotting the scatter plot
153
- hover_data = {'cause'}
154
  if include_modality:
155
  hover_data['Modality'] = True
156
 
 
 
 
 
157
  fig = px.scatter(
158
  df_reduced,
159
  x='Component 1',
160
  y='Component 2',
161
  color='subfolder', # Only subfolder colors will show in the legend
162
  symbol='indicator', # Symbols for indicators, without showing in legend
 
163
  hover_data=hover_data,
164
- labels={'Component 1': 'UMAP Dim 1', 'Component 2': 'UMAP Dim 2'},
165
  color_discrete_sequence=px.colors.qualitative.D3
166
  )
167
 
168
- # Hide the legend for all symbol traces (indicator-based traces)
169
- for trace in fig.data:
170
- if trace.marker.symbol is not None: # This targets symbol traces
171
- trace.showlegend = False
172
-
173
  fig.update_layout(
174
- xaxis=dict(showgrid=False),
175
- yaxis=dict(showgrid=False),
176
  showlegend=True, # Show only the subfolder legend
177
  legend=dict(
178
- title="Term", # Adjust title to indicate the subfolder legend
179
  yanchor="top",
180
  xanchor="left",
181
  borderwidth=1,
 
61
  texttemplate='%{y}',
62
  textposition='inside',
63
  textfont=dict(color='rgb(255, 255, 255)'),
64
+ insidetextanchor='middle'
65
  )
66
 
67
  fig.update_layout(
 
151
  df_reduced = pd.concat([df_reduced, metadata.reset_index(drop=True)], axis=1)
152
 
153
  # Plotting the scatter plot
154
+ hover_data = {'cause': True, 'Component 1': False, 'Component 2': False}
155
  if include_modality:
156
  hover_data['Modality'] = True
157
 
158
+ custom_labels = {
159
+ 'subfolder': 'Effect', # Renaming 'subfolder' to 'Category'
160
+ }
161
+
162
  fig = px.scatter(
163
  df_reduced,
164
  x='Component 1',
165
  y='Component 2',
166
  color='subfolder', # Only subfolder colors will show in the legend
167
  symbol='indicator', # Symbols for indicators, without showing in legend
168
+ labels=custom_labels,
169
  hover_data=hover_data,
 
170
  color_discrete_sequence=px.colors.qualitative.D3
171
  )
172
 
 
 
 
 
 
173
  fig.update_layout(
174
+ xaxis=dict(showgrid=True),
175
+ yaxis=dict(showgrid=True),
176
  showlegend=True, # Show only the subfolder legend
177
  legend=dict(
178
+ title="Effect, Indicator", # Adjust title to indicate the subfolder legend
179
  yanchor="top",
180
  xanchor="left",
181
  borderwidth=1,
requirements.txt CHANGED
@@ -3,4 +3,4 @@ transformers
3
  st-annotated-text
4
  plotly
5
  umap
6
- umap-learn
 
3
  st-annotated-text
4
  plotly
5
  umap
6
+ umap-learn[cpu]