Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
| 3 |
from concept_map_generator import generate_concept_map
|
| 4 |
from synoptic_chart_generator import generate_synoptic_chart
|
| 5 |
from radial_diagram_generator import generate_radial_diagram
|
| 6 |
-
from
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
"""
|
| 10 |
Helper function to create a Gradio Interface for a specific generator.
|
| 11 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
return gr.Interface(
|
| 13 |
-
fn=
|
| 14 |
inputs=gr.Textbox(
|
| 15 |
value=sample_json,
|
| 16 |
placeholder="Paste JSON following the documented format",
|
|
@@ -26,6 +34,9 @@ def create_interface(generator_fn, sample_json, title):
|
|
| 26 |
)
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
| 29 |
with gr.Blocks(
|
| 30 |
title="Advanced Graph Generator",
|
| 31 |
css="""
|
|
@@ -52,6 +63,7 @@ if __name__ == "__main__":
|
|
| 52 |
border-radius: 8px;
|
| 53 |
padding: 10px;
|
| 54 |
}
|
|
|
|
| 55 |
.gradio-container.dark {
|
| 56 |
--tw-bg-opacity: 1;
|
| 57 |
background-color: rgb(24 24 27 / var(--tw-bg-opacity));
|
|
@@ -73,97 +85,92 @@ if __name__ == "__main__":
|
|
| 73 |
) as demo:
|
| 74 |
gr.Markdown(
|
| 75 |
"""
|
| 76 |
-
# Graphify: Generate concept maps, synoptic charts and radial diagrams
|
| 77 |
Choose a graph type and provide your JSON data to generate a visual representation.
|
| 78 |
All graphs maintain a consistent, elegant style with rounded boxes,
|
| 79 |
a dark-to-light color gradient, and a clean white background.
|
| 80 |
"""
|
| 81 |
)
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
with gr.Tabs():
|
| 84 |
with gr.TabItem("Concept Map"):
|
|
|
|
| 85 |
concept_map_interface = create_interface(
|
| 86 |
generate_concept_map,
|
| 87 |
CONCEPT_MAP_JSON,
|
| 88 |
-
"Concept Map Generator"
|
|
|
|
| 89 |
)
|
| 90 |
-
gr.Markdown("<br>")
|
| 91 |
gr.Markdown("## Example Concept Maps")
|
| 92 |
-
with gr.Row():
|
| 93 |
-
gr.Image(
|
| 94 |
-
|
| 95 |
-
label="Sample Concept Map 1",
|
| 96 |
-
show_label=True,
|
| 97 |
-
interactive=False,
|
| 98 |
-
height="auto",
|
| 99 |
-
width="100%",
|
| 100 |
-
elem_id="concept-map-example-image1"
|
| 101 |
-
)
|
| 102 |
-
gr.Image(
|
| 103 |
-
value="./images/cm2.png",
|
| 104 |
-
label="Sample Concept Map 2",
|
| 105 |
-
show_label=True,
|
| 106 |
-
interactive=False,
|
| 107 |
-
height="auto",
|
| 108 |
-
width="100%",
|
| 109 |
-
elem_id="concept-map-example-image2"
|
| 110 |
-
)
|
| 111 |
|
| 112 |
with gr.TabItem("Synoptic Chart"):
|
| 113 |
synoptic_chart_interface = create_interface(
|
| 114 |
generate_synoptic_chart,
|
| 115 |
SYNOPTIC_CHART_JSON,
|
| 116 |
-
"Synoptic Chart Generator"
|
|
|
|
| 117 |
)
|
| 118 |
-
gr.Markdown("<br>")
|
| 119 |
gr.Markdown("## Example Synoptic Charts")
|
| 120 |
with gr.Row():
|
| 121 |
-
gr.Image(
|
| 122 |
-
|
| 123 |
-
label="Sample Synoptic Chart 1",
|
| 124 |
-
show_label=True,
|
| 125 |
-
interactive=False,
|
| 126 |
-
height="auto",
|
| 127 |
-
width="100%",
|
| 128 |
-
elem_id="synoptic-chart-example-image1"
|
| 129 |
-
)
|
| 130 |
-
gr.Image(
|
| 131 |
-
value="./images/sc2.png",
|
| 132 |
-
label="Sample Synoptic Chart 2",
|
| 133 |
-
show_label=True,
|
| 134 |
-
interactive=False,
|
| 135 |
-
height="auto",
|
| 136 |
-
width="100%",
|
| 137 |
-
elem_id="synoptic-chart-example-image2"
|
| 138 |
-
)
|
| 139 |
|
| 140 |
with gr.TabItem("Radial Diagram"):
|
| 141 |
radial_diagram_interface = create_interface(
|
| 142 |
generate_radial_diagram,
|
| 143 |
RADIAL_DIAGRAM_JSON,
|
| 144 |
-
"Radial Diagram Generator"
|
|
|
|
| 145 |
)
|
| 146 |
-
gr.Markdown("<br>")
|
| 147 |
gr.Markdown("## Example Radial Diagrams")
|
| 148 |
-
with gr.Row():
|
| 149 |
-
gr.Image(
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
demo.launch(
|
| 169 |
mcp_server=True,
|
|
@@ -171,3 +178,4 @@ if __name__ == "__main__":
|
|
| 171 |
server_port=7860,
|
| 172 |
server_name="0.0.0.0"
|
| 173 |
)
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# Import generator functions and sample JSONs
|
| 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 # New Import
|
| 8 |
+
from wbs_diagram_generator import generate_wbs_diagram # New Import
|
| 9 |
|
| 10 |
+
from sample_data import CONCEPT_MAP_JSON, SYNOPTIC_CHART_JSON, RADIAL_DIAGRAM_JSON, PROCESS_FLOW_JSON, WBS_DIAGRAM_JSON # New Imports
|
| 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",
|
|
|
|
| 34 |
)
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
| 37 |
+
# Define the default dark color
|
| 38 |
+
DEFAULT_BASE_COLOR = '#19191a'
|
| 39 |
+
|
| 40 |
with gr.Blocks(
|
| 41 |
title="Advanced Graph Generator",
|
| 42 |
css="""
|
|
|
|
| 63 |
border-radius: 8px;
|
| 64 |
padding: 10px;
|
| 65 |
}
|
| 66 |
+
/* Dark mode styles, adjust if needed */
|
| 67 |
.gradio-container.dark {
|
| 68 |
--tw-bg-opacity: 1;
|
| 69 |
background-color: rgb(24 24 27 / var(--tw-bg-opacity));
|
|
|
|
| 85 |
) as demo:
|
| 86 |
gr.Markdown(
|
| 87 |
"""
|
| 88 |
+
# Graphify: Generate concept maps, synoptic charts and radial diagrams from JSON!
|
| 89 |
Choose a graph type and provide your JSON data to generate a visual representation.
|
| 90 |
All graphs maintain a consistent, elegant style with rounded boxes,
|
| 91 |
a dark-to-light color gradient, and a clean white background.
|
| 92 |
"""
|
| 93 |
)
|
| 94 |
|
| 95 |
+
# Global Color Picker
|
| 96 |
+
with gr.Row():
|
| 97 |
+
gr.Markdown("### Main Diagram Color")
|
| 98 |
+
# Changed to gr.ColorPicker for custom color selection
|
| 99 |
+
base_color_picker = gr.ColorPicker(
|
| 100 |
+
label="Select Base Color for Diagram",
|
| 101 |
+
value=DEFAULT_BASE_COLOR, # Default to your dark color
|
| 102 |
+
interactive=True,
|
| 103 |
+
elem_id="main-color-picker"
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
with gr.Tabs():
|
| 107 |
with gr.TabItem("Concept Map"):
|
| 108 |
+
# Pass the base_color_picker component to create_interface
|
| 109 |
concept_map_interface = create_interface(
|
| 110 |
generate_concept_map,
|
| 111 |
CONCEPT_MAP_JSON,
|
| 112 |
+
"Concept Map Generator",
|
| 113 |
+
base_color_picker # Pass the component itself
|
| 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 |
synoptic_chart_interface = create_interface(
|
| 123 |
generate_synoptic_chart,
|
| 124 |
SYNOPTIC_CHART_JSON,
|
| 125 |
+
"Synoptic Chart Generator",
|
| 126 |
+
base_color_picker
|
| 127 |
)
|
| 128 |
+
gr.Markdown("<br>")
|
| 129 |
gr.Markdown("## Example Synoptic Charts")
|
| 130 |
with gr.Row():
|
| 131 |
+
gr.Image(value="./images/sc1.png", label="Sample 1", show_label=True, interactive=False, height="auto", width="100%")
|
| 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 |
radial_diagram_interface = create_interface(
|
| 136 |
generate_radial_diagram,
|
| 137 |
RADIAL_DIAGRAM_JSON,
|
| 138 |
+
"Radial Diagram Generator",
|
| 139 |
+
base_color_picker
|
| 140 |
)
|
| 141 |
+
gr.Markdown("<br>")
|
| 142 |
gr.Markdown("## Example Radial Diagrams")
|
| 143 |
+
with gr.Row():
|
| 144 |
+
gr.Image(value="./images/rd1.png", label="Sample 1", show_label=True, interactive=False, height="auto", width="100%")
|
| 145 |
+
gr.Image(value="./images/rd2.png", label="Sample 2", show_label=True, interactive=False, height="auto", width="100%")
|
| 146 |
+
|
| 147 |
+
# New Tab for Process Flow Diagram
|
| 148 |
+
with gr.TabItem("Process Flow"):
|
| 149 |
+
process_flow_interface = create_interface(
|
| 150 |
+
generate_process_flow_diagram,
|
| 151 |
+
PROCESS_FLOW_JSON,
|
| 152 |
+
"Process Flow Diagram Generator",
|
| 153 |
+
base_color_picker
|
| 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%") # You'll need to create this image
|
| 160 |
+
|
| 161 |
+
# New Tab for WBS Diagram
|
| 162 |
+
with gr.TabItem("WBS Diagram"):
|
| 163 |
+
wbs_diagram_interface = create_interface(
|
| 164 |
+
generate_wbs_diagram,
|
| 165 |
+
WBS_DIAGRAM_JSON,
|
| 166 |
+
"WBS Diagram Generator",
|
| 167 |
+
base_color_picker
|
| 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%") # You'll need to create this image
|
| 174 |
|
| 175 |
demo.launch(
|
| 176 |
mcp_server=True,
|
|
|
|
| 178 |
server_port=7860,
|
| 179 |
server_name="0.0.0.0"
|
| 180 |
)
|
| 181 |
+
|