ZahirJS commited on
Commit
72de955
·
verified ·
1 Parent(s): 5109fd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -93
app.py CHANGED
@@ -68,40 +68,42 @@ if __name__ == "__main__":
68
  """
69
  )
70
 
71
- # Global Color Picker - Repositioned and simplified layout
72
- with gr.Row(variant="panel", equal_height=True): # Removed mobile_collapse=False
73
- gr.Markdown("### Main Diagram Color") # Removed scale=1 from gr.Markdown
 
 
 
74
  base_color_picker = gr.ColorPicker(
75
  label="Select Base Color for Diagram",
76
- value=DEFAULT_BASE_COLOR, # Default to your dark color
77
  interactive=True,
78
  elem_id="main-color-picker",
79
- scale=2 # Allow color picker to take more space
80
  )
81
-
82
- # Add a small space after the color picker row before tabs
 
83
  gr.Markdown("<br>")
84
 
85
  with gr.Tabs():
86
  with gr.TabItem("Concept Map"):
87
- # Directly define gr.Interface and pass base_color_picker as an input
88
- gr.Interface(
89
- fn=generate_concept_map,
90
- inputs=[
91
- gr.Textbox(
92
- value=CONCEPT_MAP_JSON,
93
- placeholder="Paste JSON following the documented format",
94
- label="Structured JSON Input",
95
- lines=25
96
- ),
97
- base_color_picker # Pass the component directly as an input
98
- ],
99
- outputs=gr.Image(
100
- label="Generated Graph",
101
- type="filepath",
102
- show_download_button=True
103
- ),
104
- title="Concept Map Generator",
105
  )
106
  gr.Markdown("<br>")
107
  gr.Markdown("## Example Concept Maps")
@@ -110,23 +112,23 @@ if __name__ == "__main__":
110
  gr.Image(value="./images/cm2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
111
 
112
  with gr.TabItem("Synoptic Chart"):
113
- gr.Interface(
114
- fn=generate_synoptic_chart,
115
- inputs=[
116
- gr.Textbox(
117
- value=SYNOPTIC_CHART_JSON,
118
- placeholder="Paste JSON following the documented format",
119
- label="Structured JSON Input",
120
- lines=25
121
- ),
122
- base_color_picker # Pass the component directly as an input
123
- ],
124
- outputs=gr.Image(
125
- label="Generated Graph",
126
- type="filepath",
127
- show_download_button=True
128
- ),
129
- title="Synoptic Chart Generator",
130
  )
131
  gr.Markdown("<br>")
132
  gr.Markdown("## Example Synoptic Charts")
@@ -135,23 +137,23 @@ if __name__ == "__main__":
135
  gr.Image(value="./images/sc2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
136
 
137
  with gr.TabItem("Radial Diagram"):
138
- gr.Interface(
139
- fn=generate_radial_diagram,
140
- inputs=[
141
- gr.Textbox(
142
- value=RADIAL_DIAGRAM_JSON,
143
- placeholder="Paste JSON following the documented format",
144
- label="Structured JSON Input",
145
- lines=25
146
- ),
147
- base_color_picker # Pass the component directly as an input
148
- ],
149
- outputs=gr.Image(
150
- label="Generated Graph",
151
- type="filepath",
152
- show_download_button=True
153
- ),
154
- title="Radial Diagram Generator",
155
  )
156
  gr.Markdown("<br>")
157
  gr.Markdown("## Example Radial Diagrams")
@@ -161,23 +163,23 @@ if __name__ == "__main__":
161
 
162
  # New Tab for Process Flow Diagram
163
  with gr.TabItem("Process Flow"):
164
- gr.Interface(
165
- fn=generate_process_flow_diagram,
166
- inputs=[
167
- gr.Textbox(
168
- value=PROCESS_FLOW_JSON,
169
- placeholder="Paste JSON following the documented format",
170
- label="Structured JSON Input",
171
- lines=25
172
- ),
173
- base_color_picker # Pass the component directly as an input
174
- ],
175
- outputs=gr.Image(
176
- label="Generated Graph",
177
- type="filepath",
178
- show_download_button=True
179
- ),
180
- title="Process Flow Diagram Generator",
181
  )
182
  gr.Markdown("<br>")
183
  gr.Markdown("## Example Process Flow Diagrams")
@@ -187,23 +189,23 @@ if __name__ == "__main__":
187
 
188
  # New Tab for WBS Diagram
189
  with gr.TabItem("WBS Diagram"):
190
- gr.Interface(
191
- fn=generate_wbs_diagram,
192
- inputs=[
193
- gr.Textbox(
194
- value=WBS_DIAGRAM_JSON,
195
- placeholder="Paste JSON following the documented format",
196
- label="Structured JSON Input",
197
- lines=25
198
- ),
199
- base_color_picker # Pass the component directly as an input
200
- ],
201
- outputs=gr.Image(
202
- label="Generated Graph",
203
- type="filepath",
204
- show_download_button=True
205
- ),
206
- title="WBS Diagram Generator",
207
  )
208
  gr.Markdown("<br>")
209
  gr.Markdown("## Example WBS Diagrams")
 
68
  """
69
  )
70
 
71
+ # Global Color Picker - Repositioned for clarity and function
72
+ # This will hold the *value* of the currently selected color
73
+ current_base_color = gr.State(DEFAULT_BASE_COLOR)
74
+
75
+ with gr.Row(variant="panel"): # Simplified Row, removed equal_height
76
+ gr.Markdown("### Main Diagram Color")
77
  base_color_picker = gr.ColorPicker(
78
  label="Select Base Color for Diagram",
79
+ value=DEFAULT_BASE_COLOR,
80
  interactive=True,
81
  elem_id="main-color-picker",
 
82
  )
83
+ # Update the gr.State variable whenever the color picker changes
84
+ base_color_picker.change(fn=lambda x: x, inputs=base_color_picker, outputs=current_base_color)
85
+
86
  gr.Markdown("<br>")
87
 
88
  with gr.Tabs():
89
  with gr.TabItem("Concept Map"):
90
+ json_input_cm = gr.Textbox(
91
+ value=CONCEPT_MAP_JSON,
92
+ placeholder="Paste JSON following the documented format",
93
+ label="Structured JSON Input",
94
+ lines=25
95
+ )
96
+ output_cm = gr.Image(
97
+ label="Generated Graph",
98
+ type="filepath",
99
+ show_download_button=True
100
+ )
101
+ submit_btn_cm = gr.Button("Submit")
102
+
103
+ submit_btn_cm.click(
104
+ fn=generate_concept_map,
105
+ inputs=[json_input_cm, current_base_color], # Pass the State's value
106
+ outputs=output_cm
 
107
  )
108
  gr.Markdown("<br>")
109
  gr.Markdown("## Example Concept Maps")
 
112
  gr.Image(value="./images/cm2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
113
 
114
  with gr.TabItem("Synoptic Chart"):
115
+ json_input_sc = gr.Textbox(
116
+ value=SYNOPTIC_CHART_JSON,
117
+ placeholder="Paste JSON following the documented format",
118
+ label="Structured JSON Input",
119
+ lines=25
120
+ )
121
+ output_sc = gr.Image(
122
+ label="Generated Graph",
123
+ type="filepath",
124
+ show_download_button=True
125
+ )
126
+ submit_btn_sc = gr.Button("Submit")
127
+
128
+ submit_btn_sc.click(
129
+ fn=generate_synoptic_chart,
130
+ inputs=[json_input_sc, current_base_color], # Pass the State's value
131
+ outputs=output_sc
132
  )
133
  gr.Markdown("<br>")
134
  gr.Markdown("## Example Synoptic Charts")
 
137
  gr.Image(value="./images/sc2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
138
 
139
  with gr.TabItem("Radial Diagram"):
140
+ json_input_rd = gr.Textbox(
141
+ value=RADIAL_DIAGRAM_JSON,
142
+ placeholder="Paste JSON following the documented format",
143
+ label="Structured JSON Input",
144
+ lines=25
145
+ )
146
+ output_rd = gr.Image(
147
+ label="Generated Graph",
148
+ type="filepath",
149
+ show_download_button=True
150
+ )
151
+ submit_btn_rd = gr.Button("Submit")
152
+
153
+ submit_btn_rd.click(
154
+ fn=generate_radial_diagram,
155
+ inputs=[json_input_rd, current_base_color], # Pass the State's value
156
+ outputs=output_rd
157
  )
158
  gr.Markdown("<br>")
159
  gr.Markdown("## Example Radial Diagrams")
 
163
 
164
  # New Tab for Process Flow Diagram
165
  with gr.TabItem("Process Flow"):
166
+ json_input_pf = gr.Textbox(
167
+ value=PROCESS_FLOW_JSON,
168
+ placeholder="Paste JSON following the documented format",
169
+ label="Structured JSON Input",
170
+ lines=25
171
+ )
172
+ output_pf = gr.Image(
173
+ label="Generated Graph",
174
+ type="filepath",
175
+ show_download_button=True
176
+ )
177
+ submit_btn_pf = gr.Button("Submit")
178
+
179
+ submit_btn_pf.click(
180
+ fn=generate_process_flow_diagram,
181
+ inputs=[json_input_pf, current_base_color], # Pass the State's value
182
+ outputs=output_pf
183
  )
184
  gr.Markdown("<br>")
185
  gr.Markdown("## Example Process Flow Diagrams")
 
189
 
190
  # New Tab for WBS Diagram
191
  with gr.TabItem("WBS Diagram"):
192
+ json_input_wbs = gr.Textbox(
193
+ value=WBS_DIAGRAM_JSON,
194
+ placeholder="Paste JSON following the documented format",
195
+ label="Structured JSON Input",
196
+ lines=25
197
+ )
198
+ output_wbs = gr.Image(
199
+ label="Generated Graph",
200
+ type="filepath",
201
+ show_download_button=True
202
+ )
203
+ submit_btn_wbs = gr.Button("Submit")
204
+
205
+ submit_btn_wbs.click(
206
+ fn=generate_wbs_diagram,
207
+ inputs=[json_input_wbs, current_base_color], # Pass the State's value
208
+ outputs=output_wbs
209
  )
210
  gr.Markdown("<br>")
211
  gr.Markdown("## Example WBS Diagrams")