jjin6573 commited on
Commit
43c2a6c
·
verified ·
1 Parent(s): 4051916

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +39 -22
app.py CHANGED
@@ -52,16 +52,29 @@ def load_readme_as_html():
52
  html = re.sub(r'^## (.+)$', r'<h2>\1</h2>', html, flags=re.MULTILINE)
53
  html = re.sub(r'^# (.+)$', r'<h1>\1</h1>', html, flags=re.MULTILINE)
54
 
55
- # Code blocks (remove extra newlines)
56
  def format_code_block(match):
57
  code = match.group(2).strip()
58
- return f'<pre><code>{code}</code></pre>'
 
 
 
59
  html = re.sub(r'```(\w*)\n(.*?)```', format_code_block, html, flags=re.DOTALL)
60
 
61
- # Images
62
- html = re.sub(r'<img src="([^"]+)"[^>]*>', r'<img src="\1" style="max-width:100%; height:auto; border-radius:8px;">', html)
 
63
 
64
- # Inline code
 
 
 
 
 
 
 
 
 
65
  html = re.sub(r'`([^`]+)`', r'<code>\1</code>', html)
66
 
67
  # Bold
@@ -99,14 +112,14 @@ def load_readme_as_html():
99
  else:
100
  if in_table:
101
  table_html.append('</tbody></table>')
102
- new_lines.append('\n'.join(table_html))
103
  table_html = []
104
  in_table = False
105
  new_lines.append(line)
106
 
107
  if in_table:
108
  table_html.append('</tbody></table>')
109
- new_lines.append('\n'.join(table_html))
110
 
111
  html = '\n'.join(new_lines)
112
 
@@ -114,7 +127,7 @@ def load_readme_as_html():
114
  html = re.sub(r'^- (.+)$', r'<li>\1</li>', html, flags=re.MULTILINE)
115
  html = re.sub(r'(<li>.*</li>\n?)+', r'<ul>\g<0></ul>', html)
116
 
117
- # Paragraphs
118
  lines = html.split('\n')
119
  result = []
120
  for line in lines:
@@ -124,8 +137,11 @@ def load_readme_as_html():
124
  else:
125
  result.append(line)
126
 
127
- # Escape curly braces for f-string compatibility
128
  final_html = '\n'.join(result)
 
 
 
129
  final_html = final_html.replace('{', '{{').replace('}', '}}')
130
  return final_html
131
  except Exception as e:
@@ -1238,10 +1254,7 @@ footer,
1238
  .docs-modal-overlay {
1239
  display: none;
1240
  position: fixed !important;
1241
- top: 0 !important;
1242
- left: 0 !important;
1243
- right: 0 !important;
1244
- bottom: 0 !important;
1245
  width: 100vw !important;
1246
  height: 100vh !important;
1247
  background: rgba(0, 0, 0, 0.85) !important;
@@ -1249,8 +1262,9 @@ footer,
1249
  z-index: 99999 !important;
1250
  justify-content: center !important;
1251
  align-items: center !important;
1252
- padding: 20px !important;
1253
  box-sizing: border-box !important;
 
 
1254
  }
1255
 
1256
  .docs-modal-overlay.active {
@@ -1258,16 +1272,19 @@ footer,
1258
  }
1259
 
1260
  .docs-modal {
 
1261
  background: #0d0d1a !important;
1262
  border: 2px solid #7c3aed !important;
1263
  border-radius: 20px !important;
1264
- width: calc(100vw - 40px) !important;
1265
- max-width: 1800px !important;
1266
- height: auto !important;
1267
- max-height: 55vh !important;
1268
  overflow: hidden !important;
1269
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.9) !important;
1270
- margin: 0 auto !important;
 
 
 
1271
  }
1272
 
1273
  .docs-modal-header {
@@ -1309,7 +1326,7 @@ footer,
1309
  .docs-modal-content {
1310
  padding: 24px !important;
1311
  overflow-y: auto !important;
1312
- max-height: calc(55vh - 80px) !important;
1313
  color: #c7d2fe !important;
1314
  font-size: 15px !important;
1315
  line-height: 1.7 !important;
@@ -1323,8 +1340,8 @@ footer,
1323
  .docs-modal-content ul, .docs-modal-content ol { margin: 12px 0; padding-left: 24px; }
1324
  .docs-modal-content li { margin: 6px 0; }
1325
  .docs-modal-content code { background: rgba(124, 58, 237, 0.2); padding: 2px 6px; border-radius: 4px; font-family: 'SF Mono', 'Monaco', 'Consolas', monospace; font-size: 13px; color: #c4b5fd; }
1326
- .docs-modal-content pre { background: rgba(0, 0, 0, 0.4); border: 1px solid rgba(124, 58, 237, 0.2); border-radius: 12px; padding: 16px; overflow-x: auto; margin: 16px 0; }
1327
- .docs-modal-content pre code { background: transparent; padding: 0; color: #a5b4fc; }
1328
  .docs-modal-content table { width: 100%; border-collapse: collapse; margin: 16px 0; }
1329
  .docs-modal-content th, .docs-modal-content td { padding: 10px 12px; text-align: left; border: 1px solid rgba(124, 58, 237, 0.2); }
1330
  .docs-modal-content th { background: rgba(124, 58, 237, 0.15); color: #e0e7ff; font-weight: 600; }
 
52
  html = re.sub(r'^## (.+)$', r'<h2>\1</h2>', html, flags=re.MULTILINE)
53
  html = re.sub(r'^# (.+)$', r'<h1>\1</h1>', html, flags=re.MULTILINE)
54
 
55
+ # Code blocks - preserve content without adding extra newlines
56
  def format_code_block(match):
57
  code = match.group(2).strip()
58
+ # Replace internal newlines with a placeholder, then restore after processing
59
+ # This prevents the paragraph logic from adding extra breaks
60
+ code_escaped = code.replace('\n', '<!-- NEWLINE -->')
61
+ return f'<pre><code>{code_escaped}</code></pre>'
62
  html = re.sub(r'```(\w*)\n(.*?)```', format_code_block, html, flags=re.DOTALL)
63
 
64
+ # Images - convert relative paths to HuggingFace raw file URLs
65
+ # Handle both <img> tags and markdown image syntax
66
+ HF_BASE_URL = "https://huggingface.co/spaces/MCP-1st-Birthday/voicekit/resolve/main"
67
 
68
+ def convert_image_path(match):
69
+ src = match.group(1)
70
+ # If it's a relative path (not starting with http), convert to HF URL
71
+ if not src.startswith('http'):
72
+ src = f"{HF_BASE_URL}/{src}"
73
+ return f'<img src="{src}" style="max-width:100%; height:auto; border-radius:8px; margin:12px 0;">'
74
+
75
+ html = re.sub(r'<img src="([^"]+)"[^>]*>', convert_image_path, html)
76
+
77
+ # Inline code (but not inside <pre><code> blocks)
78
  html = re.sub(r'`([^`]+)`', r'<code>\1</code>', html)
79
 
80
  # Bold
 
112
  else:
113
  if in_table:
114
  table_html.append('</tbody></table>')
115
+ new_lines.append(''.join(table_html))
116
  table_html = []
117
  in_table = False
118
  new_lines.append(line)
119
 
120
  if in_table:
121
  table_html.append('</tbody></table>')
122
+ new_lines.append(''.join(table_html))
123
 
124
  html = '\n'.join(new_lines)
125
 
 
127
  html = re.sub(r'^- (.+)$', r'<li>\1</li>', html, flags=re.MULTILINE)
128
  html = re.sub(r'(<li>.*</li>\n?)+', r'<ul>\g<0></ul>', html)
129
 
130
+ # Paragraphs - skip lines that are inside pre/code blocks
131
  lines = html.split('\n')
132
  result = []
133
  for line in lines:
 
137
  else:
138
  result.append(line)
139
 
140
+ # Join and restore newlines in code blocks
141
  final_html = '\n'.join(result)
142
+ final_html = final_html.replace('<!-- NEWLINE -->', '\n')
143
+
144
+ # Escape curly braces for f-string compatibility
145
  final_html = final_html.replace('{', '{{').replace('}', '}}')
146
  return final_html
147
  except Exception as e:
 
1254
  .docs-modal-overlay {
1255
  display: none;
1256
  position: fixed !important;
1257
+ inset: 0 !important;
 
 
 
1258
  width: 100vw !important;
1259
  height: 100vh !important;
1260
  background: rgba(0, 0, 0, 0.85) !important;
 
1262
  z-index: 99999 !important;
1263
  justify-content: center !important;
1264
  align-items: center !important;
 
1265
  box-sizing: border-box !important;
1266
+ /* Ensure modal is centered on viewport regardless of scroll position */
1267
+ overflow: hidden !important;
1268
  }
1269
 
1270
  .docs-modal-overlay.active {
 
1272
  }
1273
 
1274
  .docs-modal {
1275
+ position: relative !important;
1276
  background: #0d0d1a !important;
1277
  border: 2px solid #7c3aed !important;
1278
  border-radius: 20px !important;
1279
+ width: calc(100vw - 80px) !important;
1280
+ max-width: 1200px !important;
1281
+ max-height: 80vh !important;
 
1282
  overflow: hidden !important;
1283
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.9) !important;
1284
+ /* Remove margin that could affect centering */
1285
+ margin: 0 !important;
1286
+ /* Prevent any transform inheritance issues */
1287
+ transform: none !important;
1288
  }
1289
 
1290
  .docs-modal-header {
 
1326
  .docs-modal-content {
1327
  padding: 24px !important;
1328
  overflow-y: auto !important;
1329
+ max-height: calc(80vh - 80px) !important;
1330
  color: #c7d2fe !important;
1331
  font-size: 15px !important;
1332
  line-height: 1.7 !important;
 
1340
  .docs-modal-content ul, .docs-modal-content ol { margin: 12px 0; padding-left: 24px; }
1341
  .docs-modal-content li { margin: 6px 0; }
1342
  .docs-modal-content code { background: rgba(124, 58, 237, 0.2); padding: 2px 6px; border-radius: 4px; font-family: 'SF Mono', 'Monaco', 'Consolas', monospace; font-size: 13px; color: #c4b5fd; }
1343
+ .docs-modal-content pre { background: rgba(0, 0, 0, 0.4); border: 1px solid rgba(124, 58, 237, 0.2); border-radius: 12px; padding: 16px; overflow-x: auto; margin: 16px 0; white-space: pre; }
1344
+ .docs-modal-content pre code { background: transparent; padding: 0; color: #a5b4fc; white-space: pre; display: block; }
1345
  .docs-modal-content table { width: 100%; border-collapse: collapse; margin: 16px 0; }
1346
  .docs-modal-content th, .docs-modal-content td { padding: 10px 12px; text-align: left; border: 1px solid rgba(124, 58, 237, 0.2); }
1347
  .docs-modal-content th { background: rgba(124, 58, 237, 0.15); color: #e0e7ff; font-weight: 600; }