Rishi-Jain-27 commited on
Commit
b8bb08b
·
1 Parent(s): 475b4b5

Fixed bug in mermaid output

Browse files
Files changed (1) hide show
  1. app.py +5 -14
app.py CHANGED
@@ -37,7 +37,7 @@ def generate_flowchart(src_code: str) -> str:
37
  # check if src_code is empty
38
  if not src_code.strip(): return ""
39
 
40
- # Set system prompt.
41
  system_prompt = dedent("""
42
  ## Role/Persona
43
  You are a senior staff software architect and compiler engineer specializing in visual control-flow mapping. Your philosophy is pure utility: you translate raw execution logic into highly accurate, scannable, structural diagrams without any conversational filler, meta-commentary, or stylistic fluff.
@@ -104,20 +104,11 @@ def generate_flowchart(src_code: str) -> str:
104
 
105
  content = response["choices"][0]["message"]["content"]
106
 
107
- # ----- DEBUG ----- #
108
- print("=" * 40)
109
- print("FINISH REASON:", response["choices"][0].get("finish_reason"))
110
- print("RAW CONTENT >>>")
111
- print(repr(content)) # repr so we see whitespace / empty
112
- print("<<< END RAW")
113
-
114
- cleaned = re.sub(r'<thinking>.*?</thinking>', '', content, flags=re.DOTALL)
115
- print("CLEANED >>>", repr(cleaned.strip()))
116
- print("=" * 40)
117
- # ----- END DEBUG ----- #
118
-
119
  # remove the thinking tags from the response
120
- # cleaned = re.sub(r'<thinking>.*?</thinking>', '', content, flags=re.DOTALL)
 
 
 
121
  return cleaned.strip() # and remove excess whitespace
122
 
123
  # ----- Custom Frontend ----- #
 
37
  # check if src_code is empty
38
  if not src_code.strip(): return ""
39
 
40
+ # Set system prompt
41
  system_prompt = dedent("""
42
  ## Role/Persona
43
  You are a senior staff software architect and compiler engineer specializing in visual control-flow mapping. Your philosophy is pure utility: you translate raw execution logic into highly accurate, scannable, structural diagrams without any conversational filler, meta-commentary, or stylistic fluff.
 
104
 
105
  content = response["choices"][0]["message"]["content"]
106
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  # remove the thinking tags from the response
108
+ cleaned = re.sub(r'<thinking>.*?</thinking>', '', content, flags=re.DOTALL)
109
+ # Mermaid can't parse double quotes inside [node labels] (e.g. C[Return "Active"]);
110
+ # source-code string literals leak them, so downgrade to single quotes which parse fine.
111
+ cleaned = cleaned.replace('"', "'")
112
  return cleaned.strip() # and remove excess whitespace
113
 
114
  # ----- Custom Frontend ----- #