Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -257,171 +257,10 @@ def download():
|
|
257 |
download_name=filename,
|
258 |
mimetype='text/markdown'
|
259 |
)
|
|
|
|
|
|
|
260 |
|
261 |
-
html_template = """
|
262 |
-
<!DOCTYPE html>
|
263 |
-
<html>
|
264 |
-
<head>
|
265 |
-
<title>Repo & Files to Markdown</title>
|
266 |
-
<style>
|
267 |
-
body {
|
268 |
-
font-family: Arial, sans-serif;
|
269 |
-
margin: 20px;
|
270 |
-
max-width: 1200px;
|
271 |
-
margin: 0 auto;
|
272 |
-
}
|
273 |
-
.container {
|
274 |
-
padding: 20px;
|
275 |
-
}
|
276 |
-
textarea {
|
277 |
-
width: 100%;
|
278 |
-
height: 400px;
|
279 |
-
margin-top: 20px;
|
280 |
-
font-family: monospace;
|
281 |
-
}
|
282 |
-
button {
|
283 |
-
padding: 10px 20px;
|
284 |
-
background-color: #4CAF50;
|
285 |
-
color: white;
|
286 |
-
border: none;
|
287 |
-
cursor: pointer;
|
288 |
-
margin: 5px;
|
289 |
-
}
|
290 |
-
button:hover {
|
291 |
-
background-color: #45a049;
|
292 |
-
}
|
293 |
-
#output {
|
294 |
-
margin-top: 20px;
|
295 |
-
border: 1px solid #ddd;
|
296 |
-
padding: 20px;
|
297 |
-
background-color: #f9f9f9;
|
298 |
-
}
|
299 |
-
.spinner {
|
300 |
-
display: none;
|
301 |
-
border: 4px solid #f3f3f3;
|
302 |
-
border-top: 4px solid #3498db;
|
303 |
-
border-radius: 50%;
|
304 |
-
width: 30px;
|
305 |
-
height: 30px;
|
306 |
-
animation: spin 1s linear infinite;
|
307 |
-
margin: 20px auto;
|
308 |
-
}
|
309 |
-
@keyframes spin {
|
310 |
-
0% { transform: rotate(0deg); }
|
311 |
-
100% { transform: rotate(360deg); }
|
312 |
-
}
|
313 |
-
</style>
|
314 |
-
</head>
|
315 |
-
<body>
|
316 |
-
<div class="container">
|
317 |
-
<h1>Repository & Files to Markdown Converter</h1>
|
318 |
-
<p>Enter a GitHub/Hugging Face Space URL (e.g., https://huggingface.co/spaces/username/space)</p>
|
319 |
-
<input type="text" id="repoUrl" style="width: 100%; padding: 8px;" placeholder="Enter GitHub or Hugging Face Space URL">
|
320 |
-
<p>OR upload files (select multiple files or a folder - folder upload supported in Chrome)</p>
|
321 |
-
<input type="file" id="fileInput" multiple webkitdirectory style="margin: 10px 0;">
|
322 |
-
<br>
|
323 |
-
<button onclick="processRepo()">Convert URL</button>
|
324 |
-
<button onclick="processFiles()">Convert Files</button>
|
325 |
-
<button id="downloadBtn" style="display: none;" onclick="downloadMarkdown()">Download .md</button>
|
326 |
-
<div id="spinner" class="spinner"></div>
|
327 |
-
|
328 |
-
<h2>Markdown Output:</h2>
|
329 |
-
<textarea id="markdownOutput" readonly></textarea>
|
330 |
-
|
331 |
-
<h2>Preview:</h2>
|
332 |
-
<div id="output"></div>
|
333 |
-
</div>
|
334 |
-
<script>
|
335 |
-
let currentMarkdown = '';
|
336 |
-
let currentFilename = '';
|
337 |
-
|
338 |
-
async function processRepo() {
|
339 |
-
const repoUrl = document.getElementById('repoUrl').value;
|
340 |
-
await processContent('/process', { repo_url: repoUrl });
|
341 |
-
}
|
342 |
-
|
343 |
-
async function processFiles() {
|
344 |
-
const files = document.getElementById('fileInput').files;
|
345 |
-
if (files.length === 0) {
|
346 |
-
alert('Please select at least one file or folder');
|
347 |
-
return;
|
348 |
-
}
|
349 |
-
|
350 |
-
const formData = new FormData();
|
351 |
-
for (let file of files) {
|
352 |
-
formData.append('files[]', file);
|
353 |
-
}
|
354 |
-
|
355 |
-
await processContent('/process', formData, false);
|
356 |
-
}
|
357 |
-
|
358 |
-
async function processContent(url, data, isJson = true) {
|
359 |
-
const spinner = document.getElementById('spinner');
|
360 |
-
const buttons = document.querySelectorAll('button');
|
361 |
-
|
362 |
-
spinner.style.display = 'block';
|
363 |
-
buttons.forEach(btn => btn.disabled = true);
|
364 |
-
|
365 |
-
try {
|
366 |
-
const options = {
|
367 |
-
method: 'POST',
|
368 |
-
...(isJson ? {
|
369 |
-
headers: { 'Content-Type': 'application/json' },
|
370 |
-
body: JSON.stringify(data)
|
371 |
-
} : { body: data })
|
372 |
-
};
|
373 |
-
|
374 |
-
const response = await fetch(url, options);
|
375 |
-
const result = await response.json();
|
376 |
-
|
377 |
-
if (result.error) {
|
378 |
-
alert(result.error);
|
379 |
-
return;
|
380 |
-
}
|
381 |
-
|
382 |
-
currentMarkdown = result.markdown;
|
383 |
-
currentFilename = result.filename;
|
384 |
-
document.getElementById('markdownOutput').value = result.markdown;
|
385 |
-
document.getElementById('output').innerHTML = result.html;
|
386 |
-
document.getElementById('downloadBtn').style.display = 'inline-block';
|
387 |
-
} catch (error) {
|
388 |
-
alert('An error occurred: ' + error.message);
|
389 |
-
} finally {
|
390 |
-
spinner.style.display = 'none';
|
391 |
-
buttons.forEach(btn => btn.disabled = false);
|
392 |
-
}
|
393 |
-
}
|
394 |
-
|
395 |
-
async function downloadMarkdown() {
|
396 |
-
try {
|
397 |
-
const response = await fetch('/download', {
|
398 |
-
method: 'POST',
|
399 |
-
headers: {
|
400 |
-
'Content-Type': 'application/json',
|
401 |
-
},
|
402 |
-
body: JSON.stringify({
|
403 |
-
markdown: currentMarkdown,
|
404 |
-
filename: currentFilename
|
405 |
-
})
|
406 |
-
});
|
407 |
-
|
408 |
-
const blob = await response.blob();
|
409 |
-
const url = window.URL.createObjectURL(blob);
|
410 |
-
const a = document.createElement('a');
|
411 |
-
a.href = url;
|
412 |
-
a.download = currentFilename;
|
413 |
-
document.body.appendChild(a);
|
414 |
-
a.click();
|
415 |
-
a.remove();
|
416 |
-
window.URL.revokeObjectURL(url);
|
417 |
-
} catch (error) {
|
418 |
-
alert('Error downloading file: ' + error.message);
|
419 |
-
}
|
420 |
-
}
|
421 |
-
</script>
|
422 |
-
</body>
|
423 |
-
</html>
|
424 |
-
"""
|
425 |
|
426 |
if not os.path.exists('templates'):
|
427 |
os.makedirs('templates')
|
|
|
257 |
download_name=filename,
|
258 |
mimetype='text/markdown'
|
259 |
)
|
260 |
+
with open("html_template.html", "r") as f:
|
261 |
+
html_template=f.readlines()
|
262 |
+
f.close()
|
263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
|
265 |
if not os.path.exists('templates'):
|
266 |
os.makedirs('templates')
|