Rishi-Jain-27 commited on
Commit
83c1616
Β·
1 Parent(s): 5f66427

Changed button UI and system prompt.

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +12 -3
README.md CHANGED
@@ -9,7 +9,7 @@ python_version: '3.13'
9
  app_file: app.py
10
  pinned: false
11
  license: mit
12
- short_description: Code -> Flowchart. πŸ“Š
13
  ---
14
 
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
9
  app_file: app.py
10
  pinned: false
11
  license: mit
12
+ short_description: Turn your Python code into an easy, readable Mermaid.js flowchart. πŸ“Š
13
  ---
14
 
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -53,7 +53,7 @@ def generate_flowchart(src_code: str) -> str:
53
  1. OUTPUT FORMAT: Output ONLY valid, raw Mermaid.js syntax.
54
  2. NO MARKDOWN FENCING: Do not wrap the output in ```mermaid or ``` blocks. Start directly with the Mermaid graph definition, for example: graph TD.
55
  3. NO PROSE: Do not include introductory text, explanations, or concluding remarks. If the code cannot be parsed, output an isolated error node.
56
- 4. NODE NAMING: Paraphrase conditions into plain words β€” never put raw code, operators, quotes, or parentheses inside labels (write Index in bounds?, not i < len(nums))
57
  </constraints>
58
 
59
  <banned_vocabulary>
@@ -134,6 +134,7 @@ index_html = """
134
  textarea { flex: 1; background: #111827; color: #34d399; border: 1px solid #374151; padding: 10px; font-family: monospace; resize: none; border-radius: 4px; }
135
  button { background: #059669; color: white; border: none; padding: 12px; margin-top: 10px; cursor: pointer; font-weight: bold; border-radius: 4px; }
136
  button:hover { background: #10b981; }
 
137
  #flowchart-target { flex: 1; background: #ffffff; padding: 10px; border-radius: 4px; overflow: auto; display: flex; justify-content: center; align-items: start; }
138
  </style>
139
  </head>
@@ -168,12 +169,17 @@ index_html = """
168
  document.getElementById('submit-btn').addEventListener('click', async () => {
169
  const codeValue = document.getElementById('code-input').value;
170
  const targetDiv = document.getElementById('flowchart-target');
171
-
 
172
  if (!codeValue.trim()) {
173
  targetDiv.innerHTML = "<p style='color:red;'>Please input code first.</p>";
174
  return;
175
  }
176
 
 
 
 
 
177
  targetDiv.innerHTML = "Generating diagram...";
178
 
179
  try {
@@ -184,9 +190,12 @@ index_html = """
184
  // Inject the raw string into a clean layout block and re-trigger parsing
185
  targetDiv.innerHTML = `<pre class="mermaid">${mermaidSyntax}</pre>`;
186
  await mermaid.run();
187
-
188
  } catch (error) {
189
  targetDiv.innerHTML = `<p style='color:red;'>Error during generation: ${error.message}</p>`;
 
 
 
190
  }
191
  });
192
  </script>
 
53
  1. OUTPUT FORMAT: Output ONLY valid, raw Mermaid.js syntax.
54
  2. NO MARKDOWN FENCING: Do not wrap the output in ```mermaid or ``` blocks. Start directly with the Mermaid graph definition, for example: graph TD.
55
  3. NO PROSE: Do not include introductory text, explanations, or concluding remarks. If the code cannot be parsed, output an isolated error node.
56
+ 4. NODE NAMING: Paraphrase conditions into plain words β€” never put raw code, operators, quotes, parentheses, or square brackets/subscripts inside labels (write Index in bounds?, not i < len(nums); write Element is even?, not nums[i] % 2 == 0)
57
  </constraints>
58
 
59
  <banned_vocabulary>
 
134
  textarea { flex: 1; background: #111827; color: #34d399; border: 1px solid #374151; padding: 10px; font-family: monospace; resize: none; border-radius: 4px; }
135
  button { background: #059669; color: white; border: none; padding: 12px; margin-top: 10px; cursor: pointer; font-weight: bold; border-radius: 4px; }
136
  button:hover { background: #10b981; }
137
+ button:disabled { background: #374151; cursor: not-allowed; }
138
  #flowchart-target { flex: 1; background: #ffffff; padding: 10px; border-radius: 4px; overflow: auto; display: flex; justify-content: center; align-items: start; }
139
  </style>
140
  </head>
 
169
  document.getElementById('submit-btn').addEventListener('click', async () => {
170
  const codeValue = document.getElementById('code-input').value;
171
  const targetDiv = document.getElementById('flowchart-target');
172
+ const submitBtn = document.getElementById('submit-btn');
173
+
174
  if (!codeValue.trim()) {
175
  targetDiv.innerHTML = "<p style='color:red;'>Please input code first.</p>";
176
  return;
177
  }
178
 
179
+ // Disable the button while a request is in flight so a slow CPU
180
+ // generation can't be double-fired into a concurrent request.
181
+ submitBtn.disabled = true;
182
+ submitBtn.textContent = "Generating...";
183
  targetDiv.innerHTML = "Generating diagram...";
184
 
185
  try {
 
190
  // Inject the raw string into a clean layout block and re-trigger parsing
191
  targetDiv.innerHTML = `<pre class="mermaid">${mermaidSyntax}</pre>`;
192
  await mermaid.run();
193
+
194
  } catch (error) {
195
  targetDiv.innerHTML = `<p style='color:red;'>Error during generation: ${error.message}</p>`;
196
+ } finally {
197
+ submitBtn.disabled = false;
198
+ submitBtn.textContent = "Generate Flowchart";
199
  }
200
  });
201
  </script>