ZahirJS commited on
Commit
89c005a
·
verified ·
1 Parent(s): 077a09e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -29
app.py CHANGED
@@ -1,9 +1,10 @@
 
1
  import gradio as gr
2
  import json
3
  from graphviz import Digraph
4
  import os
5
  from tempfile import NamedTemporaryFile
6
- from sample_data import COMPLEX_SAMPLE_JSON # ¡Aquí está el import!
7
 
8
  def generate_concept_map(json_input: str) -> str:
9
  """
@@ -102,32 +103,48 @@ def generate_concept_map(json_input: str) -> str:
102
  fontsize='10'
103
  )
104
 
105
- # Process subnodes (rectangles with lighter fill)
106
- for subnode in node.get('subnodes', []):
107
- sub_id = subnode.get('id')
108
- sub_label = subnode.get('label')
109
- sub_rel = subnode.get('relationship')
110
-
111
- if not all([sub_id, sub_label, sub_rel]):
112
- raise ValueError(f"Invalid subnode: {subnode}")
113
 
114
- dot.node(
115
- sub_id,
116
- sub_label,
117
- shape='box',
118
- style='filled',
119
- fillcolor='#FFA726',
120
- fontcolor='white',
121
- fontsize='10'
122
- )
123
-
124
- dot.edge(
125
- node_id,
126
- sub_id,
127
- label=sub_rel,
128
- color='#E91E63',
129
- fontsize='8'
130
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
  # Save to temporary file
133
  with NamedTemporaryFile(delete=False, suffix='.png') as tmp:
@@ -143,7 +160,7 @@ if __name__ == "__main__":
143
  demo = gr.Interface(
144
  fn=generate_concept_map,
145
  inputs=gr.Textbox(
146
- value=COMPLEX_SAMPLE_JSON,
147
  placeholder="Paste JSON following the documented format",
148
  label="Structured JSON Input",
149
  lines=25
@@ -153,8 +170,8 @@ if __name__ == "__main__":
153
  type="filepath",
154
  show_download_button=True
155
  ),
156
- title="Advanced Concept Map Generator",
157
- description="Create multi-level concept maps from properly formatted JSON"
158
  )
159
 
160
  demo.launch(
 
1
+ # app.py
2
  import gradio as gr
3
  import json
4
  from graphviz import Digraph
5
  import os
6
  from tempfile import NamedTemporaryFile
7
+ from sample_data import COMPLEX_SAMPLE_JSON
8
 
9
  def generate_concept_map(json_input: str) -> str:
10
  """
 
103
  fontsize='10'
104
  )
105
 
106
+ # Helper function to recursively add subnodes and edges
107
+ def add_subnodes(parent_id, subnodes_list, fill_color, font_size, edge_color, edge_font_size):
108
+ for subnode in subnodes_list:
109
+ sub_id = subnode.get('id')
110
+ sub_label = subnode.get('label')
111
+ sub_rel = subnode.get('relationship')
 
 
112
 
113
+ if not all([sub_id, sub_label, sub_rel]):
114
+ raise ValueError(f"Invalid subnode: {subnode}")
115
+
116
+ dot.node(
117
+ sub_id,
118
+ sub_label,
119
+ shape='box',
120
+ style='filled',
121
+ fillcolor=fill_color,
122
+ fontcolor='white',
123
+ fontsize=str(font_size)
124
+ )
125
+
126
+ dot.edge(
127
+ parent_id,
128
+ sub_id,
129
+ label=sub_rel,
130
+ color=edge_color,
131
+ fontsize=str(edge_font_size)
132
+ )
133
+
134
+ # Recursively call for deeper levels
135
+ if 'subnodes' in subnode:
136
+ # Slightly adjust colors/sizes for deeper levels if desired
137
+ # For fixed 2 children per parent, you might keep colors consistent per level or vary them.
138
+ # Here, I'll slightly adjust font size for consistency with depth.
139
+ add_subnodes(sub_id, subnode['subnodes'],
140
+ '#FFA726' if font_size > 8 else '#FFCC80', # Lighter orange/yellow for deeper levels
141
+ font_size - 1 if font_size > 7 else font_size,
142
+ '#E91E63' if edge_font_size > 7 else '#FF5252', # Reddish for deeper edges
143
+ edge_font_size - 1 if edge_font_size > 7 else edge_font_size)
144
+
145
+ # Start processing subnodes from the first level
146
+ add_subnodes(node_id, node.get('subnodes', []), '#FFA726', 10, '#E91E63', 8)
147
+
148
 
149
  # Save to temporary file
150
  with NamedTemporaryFile(delete=False, suffix='.png') as tmp:
 
160
  demo = gr.Interface(
161
  fn=generate_concept_map,
162
  inputs=gr.Textbox(
163
+ value=COMPLEX_SAMPLE_JSON, # ¡Ahora usa el JSON AI simétrico y complejo!
164
  placeholder="Paste JSON following the documented format",
165
  label="Structured JSON Input",
166
  lines=25
 
170
  type="filepath",
171
  show_download_button=True
172
  ),
173
+ title="Advanced Concept Map Generator (Symmetric AI)",
174
+ description="Create symmetric, multi-level concept maps for AI from properly formatted JSON."
175
  )
176
 
177
  demo.launch(