Spaces:
Running
Running
Commit
·
055a113
1
Parent(s):
79b525f
committing it all
Browse files- .dockerignore +1 -0
- .gitignore +1 -0
- Dockerfile +19 -0
- README.md +3 -2
- app.py +96 -0
- requirements.txt +15 -0
.dockerignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
venv/
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
venv/
|
Dockerfile
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use a slim Python base image
|
2 |
+
FROM python:3.11-slim
|
3 |
+
|
4 |
+
# Set work directory
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# Install dependencies
|
8 |
+
COPY requirements.txt .
|
9 |
+
RUN pip install -r requirements.txt
|
10 |
+
|
11 |
+
# Copy app code
|
12 |
+
COPY . .
|
13 |
+
|
14 |
+
# Expose Flask port
|
15 |
+
EXPOSE 8988
|
16 |
+
|
17 |
+
# Run the server
|
18 |
+
CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:8988", "app:app"]
|
19 |
+
|
README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
---
|
2 |
title: Xet Spec
|
3 |
-
emoji:
|
4 |
colorFrom: purple
|
5 |
-
colorTo:
|
6 |
sdk: docker
|
|
|
7 |
pinned: false
|
8 |
license: mit
|
9 |
short_description: The Xet Spec
|
|
|
1 |
---
|
2 |
title: Xet Spec
|
3 |
+
emoji: 🕶
|
4 |
colorFrom: purple
|
5 |
+
colorTo: red
|
6 |
sdk: docker
|
7 |
+
app_port: 8988
|
8 |
pinned: false
|
9 |
license: mit
|
10 |
short_description: The Xet Spec
|
app.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, Response
|
2 |
+
import requests
|
3 |
+
import markdown
|
4 |
+
import re
|
5 |
+
|
6 |
+
app = Flask(__name__)
|
7 |
+
|
8 |
+
BASE_URL = "https://raw.githubusercontent.com/huggingface/xet-core/refs/heads/assaf/spec/spec/"
|
9 |
+
ENTRY_FILE = "spec.md"
|
10 |
+
|
11 |
+
CSS_STYLE = """
|
12 |
+
<style>
|
13 |
+
body {
|
14 |
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
15 |
+
max-width: 800px;
|
16 |
+
margin: 2rem auto;
|
17 |
+
padding: 1rem;
|
18 |
+
line-height: 1.6;
|
19 |
+
color: #333;
|
20 |
+
background: #fafafa;
|
21 |
+
}
|
22 |
+
h1, h2, h3, h4 {
|
23 |
+
border-bottom: 1px solid #ddd;
|
24 |
+
padding-bottom: 0.3rem;
|
25 |
+
margin-top: 2rem;
|
26 |
+
}
|
27 |
+
a {
|
28 |
+
color: #007acc;
|
29 |
+
text-decoration: none;
|
30 |
+
}
|
31 |
+
a:hover {
|
32 |
+
text-decoration: underline;
|
33 |
+
}
|
34 |
+
pre {
|
35 |
+
background: #f4f4f4;
|
36 |
+
padding: 1rem;
|
37 |
+
border-radius: 6px;
|
38 |
+
overflow-x: auto;
|
39 |
+
}
|
40 |
+
code {
|
41 |
+
background: #f4f4f4;
|
42 |
+
padding: 0.2rem 0.4rem;
|
43 |
+
border-radius: 4px;
|
44 |
+
}
|
45 |
+
</style>
|
46 |
+
"""
|
47 |
+
|
48 |
+
HTML_TEMPLATE = """<!DOCTYPE html>
|
49 |
+
<html lang="en">
|
50 |
+
<head>
|
51 |
+
<meta charset="UTF-8">
|
52 |
+
<title>Markdown Viewer</title>
|
53 |
+
{css}
|
54 |
+
</head>
|
55 |
+
<body>
|
56 |
+
{content}
|
57 |
+
</body>
|
58 |
+
</html>
|
59 |
+
"""
|
60 |
+
|
61 |
+
|
62 |
+
def fetch_and_render_md(path: str = ENTRY_FILE) -> str:
|
63 |
+
url = BASE_URL + path
|
64 |
+
resp = requests.get(url)
|
65 |
+
if resp.status_code != 200:
|
66 |
+
return f"<h1>Error {resp.status_code}</h1><p>Could not fetch {url}</p>"
|
67 |
+
|
68 |
+
md_text = resp.text
|
69 |
+
|
70 |
+
# Rewrite links: ../spec/foo.md → /view/foo.md
|
71 |
+
md_text = re.sub(
|
72 |
+
r"\.\./spec/([^\s)]+)",
|
73 |
+
r"/view/\1",
|
74 |
+
md_text
|
75 |
+
)
|
76 |
+
|
77 |
+
# Convert to HTML
|
78 |
+
html_content = markdown.markdown(md_text, extensions=["extra", "toc"])
|
79 |
+
return HTML_TEMPLATE.format(css=CSS_STYLE, content=html_content)
|
80 |
+
|
81 |
+
|
82 |
+
@app.route("/")
|
83 |
+
def index():
|
84 |
+
html = fetch_and_render_md()
|
85 |
+
return Response(html, mimetype="text/html")
|
86 |
+
|
87 |
+
|
88 |
+
@app.route("/view/<path:subpath>")
|
89 |
+
def view(subpath):
|
90 |
+
html = fetch_and_render_md(subpath)
|
91 |
+
return Response(html, mimetype="text/html")
|
92 |
+
|
93 |
+
|
94 |
+
if __name__ == "__main__":
|
95 |
+
app.run(port=8988)
|
96 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
blinker==1.9.0
|
2 |
+
certifi==2025.8.3
|
3 |
+
charset-normalizer==3.4.3
|
4 |
+
click==8.2.1
|
5 |
+
Flask==3.1.2
|
6 |
+
gunicorn==23.0.0
|
7 |
+
idna==3.10
|
8 |
+
itsdangerous==2.2.0
|
9 |
+
Jinja2==3.1.6
|
10 |
+
Markdown==3.8.2
|
11 |
+
MarkupSafe==3.0.2
|
12 |
+
packaging==25.0
|
13 |
+
requests==2.32.5
|
14 |
+
urllib3==2.5.0
|
15 |
+
Werkzeug==3.1.3
|