ginipick commited on
Commit
f4b3178
ยท
verified ยท
1 Parent(s): c624e31

Update process_flow_generator.py

Browse files
Files changed (1) hide show
  1. process_flow_generator.py +108 -4
process_flow_generator.py CHANGED
@@ -2,15 +2,14 @@ import graphviz
2
  import json
3
  from tempfile import NamedTemporaryFile
4
  import os
 
5
 
6
  def generate_process_flow_diagram(json_input: str, output_format: str) -> str:
7
  """
8
  Generates a Process Flow Diagram (Flowchart) from JSON input.
9
-
10
  Args:
11
  json_input (str): A JSON string describing the process flow structure.
12
  It must follow the Expected JSON Format Example below.
13
-
14
  Expected JSON Format Example:
15
  {
16
  "start_node": "Start Inference Request",
@@ -80,7 +79,6 @@ def generate_process_flow_diagram(json_input: str, output_format: str) -> str:
80
  {"from": "log_error", "to": "end_inference_process", "label": "Error Handled"}
81
  ]
82
  }
83
-
84
  Returns:
85
  str: The filepath to the generated PNG image file.
86
  """
@@ -204,4 +202,110 @@ def generate_process_flow_diagram(json_input: str, output_format: str) -> str:
204
  except json.JSONDecodeError:
205
  return "Error: Invalid JSON format"
206
  except Exception as e:
207
- return f"Error: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import json
3
  from tempfile import NamedTemporaryFile
4
  import os
5
+ from PIL import Image
6
 
7
  def generate_process_flow_diagram(json_input: str, output_format: str) -> str:
8
  """
9
  Generates a Process Flow Diagram (Flowchart) from JSON input.
 
10
  Args:
11
  json_input (str): A JSON string describing the process flow structure.
12
  It must follow the Expected JSON Format Example below.
 
13
  Expected JSON Format Example:
14
  {
15
  "start_node": "Start Inference Request",
 
79
  {"from": "log_error", "to": "end_inference_process", "label": "Error Handled"}
80
  ]
81
  }
 
82
  Returns:
83
  str: The filepath to the generated PNG image file.
84
  """
 
202
  except json.JSONDecodeError:
203
  return "Error: Invalid JSON format"
204
  except Exception as e:
205
+ return f"Error: {str(e)}"
206
+
207
+ # PPT ํ†ตํ•ฉ์„ ์œ„ํ•œ ์ถ”๊ฐ€ ํ•จ์ˆ˜
208
+ def generate_process_flow_for_ppt(topic: str, context: str, style: str = "Business Workflow") -> Image.Image:
209
+ """
210
+ PPT ์ƒ์„ฑ๊ธฐ์—์„œ ์‚ฌ์šฉํ•  ํ”„๋กœ์„ธ์Šค ํ”Œ๋กœ์šฐ ๋‹ค์ด์–ด๊ทธ๋žจ ์ƒ์„ฑ
211
+
212
+ Args:
213
+ topic: ํ”„๋ ˆ์  ํ…Œ์ด์…˜ ์ฃผ์ œ
214
+ context: ์Šฌ๋ผ์ด๋“œ ์ปจํ…์ŠคํŠธ
215
+ style: ์Šคํƒ€์ผ ํƒ€์ž…
216
+
217
+ Returns:
218
+ PIL Image ๊ฐ์ฒด
219
+ """
220
+ # ์ปจํ…์ŠคํŠธ์— ๋”ฐ๋ฅธ ํ”„๋กœ์„ธ์Šค ํ”Œ๋กœ์šฐ JSON ์ƒ์„ฑ
221
+ if "ํ”„๋กœ์„ธ์Šค" in context or "process" in context.lower():
222
+ # ๋น„์ฆˆ๋‹ˆ์Šค ํ”„๋กœ์„ธ์Šค ํ”Œ๋กœ์šฐ
223
+ flow_json = {
224
+ "start_node": "์‹œ์ž‘",
225
+ "nodes": [
226
+ {"id": "analyze", "label": "ํ˜„ํ™ฉ ๋ถ„์„", "type": "process"},
227
+ {"id": "plan", "label": "๊ณ„ํš ์ˆ˜๋ฆฝ", "type": "process"},
228
+ {"id": "review", "label": "๊ฒ€ํ†  ํ•„์š”?", "type": "decision"},
229
+ {"id": "implement", "label": "์‹คํ–‰", "type": "process"},
230
+ {"id": "monitor", "label": "๋ชจ๋‹ˆํ„ฐ๋ง", "type": "process"},
231
+ {"id": "complete", "label": "์™„๋ฃŒ", "type": "end"}
232
+ ],
233
+ "connections": [
234
+ {"from": "์‹œ์ž‘", "to": "analyze", "label": ""},
235
+ {"from": "analyze", "to": "plan", "label": "๋ถ„์„ ์™„๋ฃŒ"},
236
+ {"from": "plan", "to": "review", "label": ""},
237
+ {"from": "review", "to": "implement", "label": "์Šน์ธ"},
238
+ {"from": "review", "to": "plan", "label": "์žฌ๊ฒ€ํ† "},
239
+ {"from": "implement", "to": "monitor", "label": ""},
240
+ {"from": "monitor", "to": "complete", "label": "๋ชฉํ‘œ ๋‹ฌ์„ฑ"}
241
+ ]
242
+ }
243
+ elif "์ผ์ •" in context or "timeline" in context.lower():
244
+ # ํ”„๋กœ์ ํŠธ ์ผ์ • ํ”Œ๋กœ์šฐ
245
+ flow_json = {
246
+ "start_node": "ํ”„๋กœ์ ํŠธ ์‹œ์ž‘",
247
+ "nodes": [
248
+ {"id": "phase1", "label": "1๋‹จ๊ณ„: ๊ธฐํš", "type": "process"},
249
+ {"id": "milestone1", "label": "๊ธฐํš ๊ฒ€ํ† ", "type": "decision"},
250
+ {"id": "phase2", "label": "2๋‹จ๊ณ„: ๊ฐœ๋ฐœ", "type": "process"},
251
+ {"id": "phase3", "label": "3๋‹จ๊ณ„: ํ…Œ์ŠคํŠธ", "type": "process"},
252
+ {"id": "launch", "label": "๋Ÿฐ์นญ", "type": "io"},
253
+ {"id": "end", "label": "ํ”„๋กœ์ ํŠธ ์ข…๋ฃŒ", "type": "end"}
254
+ ],
255
+ "connections": [
256
+ {"from": "ํ”„๋กœ์ ํŠธ ์‹œ์ž‘", "to": "phase1", "label": ""},
257
+ {"from": "phase1", "to": "milestone1", "label": "4์ฃผ"},
258
+ {"from": "milestone1", "to": "phase2", "label": "์Šน์ธ"},
259
+ {"from": "milestone1", "to": "phase1", "label": "๋ณด์™„"},
260
+ {"from": "phase2", "to": "phase3", "label": "8์ฃผ"},
261
+ {"from": "phase3", "to": "launch", "label": "2์ฃผ"},
262
+ {"from": "launch", "to": "end", "label": ""}
263
+ ]
264
+ }
265
+ else:
266
+ # ๊ธฐ๋ณธ ์›Œํฌํ”Œ๋กœ์šฐ
267
+ flow_json = {
268
+ "start_node": "์‹œ์ž‘",
269
+ "nodes": [
270
+ {"id": "input", "label": "์ž…๋ ฅ ๋‹จ๊ณ„", "type": "io"},
271
+ {"id": "process", "label": "์ฒ˜๋ฆฌ ๋‹จ๊ณ„", "type": "process"},
272
+ {"id": "check", "label": "๊ฒ€์ฆ", "type": "decision"},
273
+ {"id": "output", "label": "์ถœ๋ ฅ ๋‹จ๊ณ„", "type": "io"},
274
+ {"id": "end", "label": "์ข…๋ฃŒ", "type": "end"}
275
+ ],
276
+ "connections": [
277
+ {"from": "์‹œ์ž‘", "to": "input", "label": ""},
278
+ {"from": "input", "to": "process", "label": "๋ฐ์ดํ„ฐ"},
279
+ {"from": "process", "to": "check", "label": ""},
280
+ {"from": "check", "to": "output", "label": "ํ†ต๊ณผ"},
281
+ {"from": "check", "to": "process", "label": "์žฌ์ฒ˜๋ฆฌ"},
282
+ {"from": "output", "to": "end", "label": ""}
283
+ ]
284
+ }
285
+
286
+ # JSON์„ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜
287
+ json_str = json.dumps(flow_json, ensure_ascii=False)
288
+
289
+ # ํ”„๋กœ์„ธ์Šค ํ”Œ๋กœ์šฐ ๋‹ค์ด์–ด๊ทธ๋žจ ์ƒ์„ฑ
290
+ png_path = generate_process_flow_diagram(json_str, 'png')
291
+
292
+ if png_path.startswith("Error:"):
293
+ # ์—๋Ÿฌ ๋ฐœ์ƒ ์‹œ ๊ธฐ๋ณธ ์ด๋ฏธ์ง€ ๋ฐ˜ํ™˜
294
+ from PIL import Image, ImageDraw, ImageFont
295
+ img = Image.new('RGB', (800, 600), 'white')
296
+ draw = ImageDraw.Draw(img)
297
+ draw.text((400, 300), png_path, fill='red', anchor='mm')
298
+ return img
299
+
300
+ # PNG ํŒŒ์ผ์„ PIL Image๋กœ ๋ณ€ํ™˜
301
+ with Image.open(png_path) as img:
302
+ # ์ด๋ฏธ์ง€ ๋ณต์‚ฌ๋ณธ ์ƒ์„ฑ (ํŒŒ์ผ ๋‹ซ๊ธฐ ์œ„ํ•ด)
303
+ img_copy = img.copy()
304
+
305
+ # ์ž„์‹œ ํŒŒ์ผ ์‚ญ์ œ
306
+ try:
307
+ os.unlink(png_path)
308
+ except:
309
+ pass
310
+
311
+ return img_copy