Update app.py
Browse files
app.py
CHANGED
|
@@ -4,34 +4,10 @@ import gradio as gr
|
|
| 4 |
from concept_map_generator import generate_concept_map
|
| 5 |
from synoptic_chart_generator import generate_synoptic_chart
|
| 6 |
from radial_diagram_generator import generate_radial_diagram
|
| 7 |
-
from process_flow_generator import generate_process_flow_diagram
|
| 8 |
-
from wbs_diagram_generator import generate_wbs_diagram
|
| 9 |
|
| 10 |
-
from sample_data import CONCEPT_MAP_JSON, SYNOPTIC_CHART_JSON, RADIAL_DIAGRAM_JSON, PROCESS_FLOW_JSON, WBS_DIAGRAM_JSON
|
| 11 |
-
|
| 12 |
-
def create_interface(generator_fn, sample_json, title, base_color_input): # Added base_color_input
|
| 13 |
-
"""
|
| 14 |
-
Helper function to create a Gradio Interface for a specific generator.
|
| 15 |
-
"""
|
| 16 |
-
# Create a wrapper function to pass the color input to the generator
|
| 17 |
-
def wrapped_generator_fn(json_input):
|
| 18 |
-
return generator_fn(json_input, base_color_input.value) # Pass the value from the color picker
|
| 19 |
-
|
| 20 |
-
return gr.Interface(
|
| 21 |
-
fn=wrapped_generator_fn, # Use the wrapper function
|
| 22 |
-
inputs=gr.Textbox(
|
| 23 |
-
value=sample_json,
|
| 24 |
-
placeholder="Paste JSON following the documented format",
|
| 25 |
-
label="Structured JSON Input",
|
| 26 |
-
lines=25
|
| 27 |
-
),
|
| 28 |
-
outputs=gr.Image(
|
| 29 |
-
label="Generated Graph",
|
| 30 |
-
type="filepath",
|
| 31 |
-
show_download_button=True
|
| 32 |
-
),
|
| 33 |
-
title=title,
|
| 34 |
-
)
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
| 37 |
# Define the default dark color
|
|
@@ -92,38 +68,66 @@ if __name__ == "__main__":
|
|
| 92 |
"""
|
| 93 |
)
|
| 94 |
|
| 95 |
-
# Global Color Picker
|
| 96 |
-
with gr.Row():
|
| 97 |
-
gr.
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
with gr.Tabs():
|
| 107 |
with gr.TabItem("Concept Map"):
|
| 108 |
-
#
|
| 109 |
-
|
| 110 |
-
generate_concept_map,
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
)
|
| 115 |
-
gr.Markdown("<br>")
|
| 116 |
gr.Markdown("## Example Concept Maps")
|
| 117 |
with gr.Row():
|
| 118 |
gr.Image(value="./images/cm1.png", label="Sample 1", show_label=True, interactive=False, height="auto", width="100%")
|
| 119 |
gr.Image(value="./images/cm2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
|
| 120 |
|
| 121 |
with gr.TabItem("Synoptic Chart"):
|
| 122 |
-
|
| 123 |
-
generate_synoptic_chart,
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
)
|
| 128 |
gr.Markdown("<br>")
|
| 129 |
gr.Markdown("## Example Synoptic Charts")
|
|
@@ -132,11 +136,23 @@ if __name__ == "__main__":
|
|
| 132 |
gr.Image(value="./images/sc2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
|
| 133 |
|
| 134 |
with gr.TabItem("Radial Diagram"):
|
| 135 |
-
|
| 136 |
-
generate_radial_diagram,
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
)
|
| 141 |
gr.Markdown("<br>")
|
| 142 |
gr.Markdown("## Example Radial Diagrams")
|
|
@@ -146,31 +162,55 @@ if __name__ == "__main__":
|
|
| 146 |
|
| 147 |
# New Tab for Process Flow Diagram
|
| 148 |
with gr.TabItem("Process Flow"):
|
| 149 |
-
|
| 150 |
-
generate_process_flow_diagram,
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
)
|
| 155 |
gr.Markdown("<br>")
|
| 156 |
gr.Markdown("## Example Process Flow Diagrams")
|
| 157 |
with gr.Row():
|
| 158 |
gr.Image(value="./images/pf1.png", label="Sample 1", show_label=True, interactive=False, height="auto", width="100%")
|
| 159 |
-
gr.Image(value="./images/pf2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
|
| 160 |
|
| 161 |
# New Tab for WBS Diagram
|
| 162 |
with gr.TabItem("WBS Diagram"):
|
| 163 |
-
|
| 164 |
-
generate_wbs_diagram,
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
)
|
| 169 |
gr.Markdown("<br>")
|
| 170 |
gr.Markdown("## Example WBS Diagrams")
|
| 171 |
with gr.Row():
|
| 172 |
gr.Image(value="./images/wbs1.png", label="Sample 1", show_label=True, interactive=False, height="auto", width="100%")
|
| 173 |
-
gr.Image(value="./images/wbs2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
|
| 174 |
|
| 175 |
demo.launch(
|
| 176 |
mcp_server=True,
|
|
|
|
| 4 |
from concept_map_generator import generate_concept_map
|
| 5 |
from synoptic_chart_generator import generate_synoptic_chart
|
| 6 |
from radial_diagram_generator import generate_radial_diagram
|
| 7 |
+
from process_flow_generator import generate_process_flow_diagram
|
| 8 |
+
from wbs_diagram_generator import generate_wbs_diagram
|
| 9 |
|
| 10 |
+
from sample_data import CONCEPT_MAP_JSON, SYNOPTIC_CHART_JSON, RADIAL_DIAGRAM_JSON, PROCESS_FLOW_JSON, WBS_DIAGRAM_JSON
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
if __name__ == "__main__":
|
| 13 |
# Define the default dark color
|
|
|
|
| 68 |
"""
|
| 69 |
)
|
| 70 |
|
| 71 |
+
# Global Color Picker - Repositioned
|
| 72 |
+
with gr.Row(variant="panel"): # Using variant="panel" for better visual grouping
|
| 73 |
+
with gr.Column(scale=1):
|
| 74 |
+
gr.Markdown("### Main Diagram Color")
|
| 75 |
+
with gr.Column(scale=2):
|
| 76 |
+
base_color_picker = gr.ColorPicker(
|
| 77 |
+
label="Select Base Color for Diagram",
|
| 78 |
+
value=DEFAULT_BASE_COLOR, # Default to your dark color
|
| 79 |
+
interactive=True,
|
| 80 |
+
elem_id="main-color-picker"
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# Add a small space after the color picker row before tabs
|
| 84 |
+
gr.Markdown("<br>")
|
| 85 |
|
| 86 |
with gr.Tabs():
|
| 87 |
with gr.TabItem("Concept Map"):
|
| 88 |
+
# Directly define gr.Interface and pass base_color_picker as an input
|
| 89 |
+
gr.Interface(
|
| 90 |
+
fn=generate_concept_map,
|
| 91 |
+
inputs=[
|
| 92 |
+
gr.Textbox(
|
| 93 |
+
value=CONCEPT_MAP_JSON,
|
| 94 |
+
placeholder="Paste JSON following the documented format",
|
| 95 |
+
label="Structured JSON Input",
|
| 96 |
+
lines=25
|
| 97 |
+
),
|
| 98 |
+
base_color_picker # Pass the component directly as an input
|
| 99 |
+
],
|
| 100 |
+
outputs=gr.Image(
|
| 101 |
+
label="Generated Graph",
|
| 102 |
+
type="filepath",
|
| 103 |
+
show_download_button=True
|
| 104 |
+
),
|
| 105 |
+
title="Concept Map Generator",
|
| 106 |
)
|
| 107 |
+
gr.Markdown("<br>")
|
| 108 |
gr.Markdown("## Example Concept Maps")
|
| 109 |
with gr.Row():
|
| 110 |
gr.Image(value="./images/cm1.png", label="Sample 1", show_label=True, interactive=False, height="auto", width="100%")
|
| 111 |
gr.Image(value="./images/cm2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
|
| 112 |
|
| 113 |
with gr.TabItem("Synoptic Chart"):
|
| 114 |
+
gr.Interface(
|
| 115 |
+
fn=generate_synoptic_chart,
|
| 116 |
+
inputs=[
|
| 117 |
+
gr.Textbox(
|
| 118 |
+
value=SYNOPTIC_CHART_JSON,
|
| 119 |
+
placeholder="Paste JSON following the documented format",
|
| 120 |
+
label="Structured JSON Input",
|
| 121 |
+
lines=25
|
| 122 |
+
),
|
| 123 |
+
base_color_picker # Pass the component directly as an input
|
| 124 |
+
],
|
| 125 |
+
outputs=gr.Image(
|
| 126 |
+
label="Generated Graph",
|
| 127 |
+
type="filepath",
|
| 128 |
+
show_download_button=True
|
| 129 |
+
),
|
| 130 |
+
title="Synoptic Chart Generator",
|
| 131 |
)
|
| 132 |
gr.Markdown("<br>")
|
| 133 |
gr.Markdown("## Example Synoptic Charts")
|
|
|
|
| 136 |
gr.Image(value="./images/sc2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
|
| 137 |
|
| 138 |
with gr.TabItem("Radial Diagram"):
|
| 139 |
+
gr.Interface(
|
| 140 |
+
fn=generate_radial_diagram,
|
| 141 |
+
inputs=[
|
| 142 |
+
gr.Textbox(
|
| 143 |
+
value=RADIAL_DIAGRAM_JSON,
|
| 144 |
+
placeholder="Paste JSON following the documented format",
|
| 145 |
+
label="Structured JSON Input",
|
| 146 |
+
lines=25
|
| 147 |
+
),
|
| 148 |
+
base_color_picker # Pass the component directly as an input
|
| 149 |
+
],
|
| 150 |
+
outputs=gr.Image(
|
| 151 |
+
label="Generated Graph",
|
| 152 |
+
type="filepath",
|
| 153 |
+
show_download_button=True
|
| 154 |
+
),
|
| 155 |
+
title="Radial Diagram Generator",
|
| 156 |
)
|
| 157 |
gr.Markdown("<br>")
|
| 158 |
gr.Markdown("## Example Radial Diagrams")
|
|
|
|
| 162 |
|
| 163 |
# New Tab for Process Flow Diagram
|
| 164 |
with gr.TabItem("Process Flow"):
|
| 165 |
+
gr.Interface(
|
| 166 |
+
fn=generate_process_flow_diagram,
|
| 167 |
+
inputs=[
|
| 168 |
+
gr.Textbox(
|
| 169 |
+
value=PROCESS_FLOW_JSON,
|
| 170 |
+
placeholder="Paste JSON following the documented format",
|
| 171 |
+
label="Structured JSON Input",
|
| 172 |
+
lines=25
|
| 173 |
+
),
|
| 174 |
+
base_color_picker # Pass the component directly as an input
|
| 175 |
+
],
|
| 176 |
+
outputs=gr.Image(
|
| 177 |
+
label="Generated Graph",
|
| 178 |
+
type="filepath",
|
| 179 |
+
show_download_button=True
|
| 180 |
+
),
|
| 181 |
+
title="Process Flow Diagram Generator",
|
| 182 |
)
|
| 183 |
gr.Markdown("<br>")
|
| 184 |
gr.Markdown("## Example Process Flow Diagrams")
|
| 185 |
with gr.Row():
|
| 186 |
gr.Image(value="./images/pf1.png", label="Sample 1", show_label=True, interactive=False, height="auto", width="100%")
|
| 187 |
+
gr.Image(value="./images/pf2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
|
| 188 |
|
| 189 |
# New Tab for WBS Diagram
|
| 190 |
with gr.TabItem("WBS Diagram"):
|
| 191 |
+
gr.Interface(
|
| 192 |
+
fn=generate_wbs_diagram,
|
| 193 |
+
inputs=[
|
| 194 |
+
gr.Textbox(
|
| 195 |
+
value=WBS_DIAGRAM_JSON,
|
| 196 |
+
placeholder="Paste JSON following the documented format",
|
| 197 |
+
label="Structured JSON Input",
|
| 198 |
+
lines=25
|
| 199 |
+
),
|
| 200 |
+
base_color_picker # Pass the component directly as an input
|
| 201 |
+
],
|
| 202 |
+
outputs=gr.Image(
|
| 203 |
+
label="Generated Graph",
|
| 204 |
+
type="filepath",
|
| 205 |
+
show_download_button=True
|
| 206 |
+
),
|
| 207 |
+
title="WBS Diagram Generator",
|
| 208 |
)
|
| 209 |
gr.Markdown("<br>")
|
| 210 |
gr.Markdown("## Example WBS Diagrams")
|
| 211 |
with gr.Row():
|
| 212 |
gr.Image(value="./images/wbs1.png", label="Sample 1", show_label=True, interactive=False, height="auto", width="100%")
|
| 213 |
+
gr.Image(value="./images/wbs2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
|
| 214 |
|
| 215 |
demo.launch(
|
| 216 |
mcp_server=True,
|