Spaces:
Running
Running
Sync from GitHub via hub-sync
Browse files- README.md +31 -1
- VERSION +1 -0
- main.py +56 -10
- pyproject.toml +1 -0
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -1 +1,31 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: github-sync-test
|
| 3 |
+
emoji: "🤗"
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: gradio
|
| 7 |
+
app_file: main.py
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# github-sync-test
|
| 12 |
+
|
| 13 |
+
Simple Gradio demo to test GitHub to Hugging Face Space sync.
|
| 14 |
+
|
| 15 |
+
## How the demo works
|
| 16 |
+
|
| 17 |
+
1. Update code in this repository.
|
| 18 |
+
2. Commit and push to GitHub.
|
| 19 |
+
3. GitHub Actions runs the sync workflow.
|
| 20 |
+
4. Hugging Face Space rebuilds and shows your latest change.
|
| 21 |
+
|
| 22 |
+
## Quick test
|
| 23 |
+
|
| 24 |
+
1. Change the title text in main.py.
|
| 25 |
+
2. Push to master.
|
| 26 |
+
3. Open the Space and verify the new title appears.
|
| 27 |
+
|
| 28 |
+
## Version badge
|
| 29 |
+
|
| 30 |
+
The app header shows a version badge with `Version`, `Commit`, and `Loaded` timestamp.
|
| 31 |
+
It reads `GITHUB_SHA`, `COMMIT_SHA`, `SPACE_COMMIT_SHA`, or the generated `VERSION` file, then falls back to `local`.
|
VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
cbbc3af3374a284e87b4919dab5d86e69b3a4459
|
main.py
CHANGED
|
@@ -1,14 +1,60 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
|
| 5 |
|
| 6 |
-
response = client.chat_completion(
|
| 7 |
-
model="zai-org/GLM-5.1",
|
| 8 |
-
messages=[
|
| 9 |
-
{"role": "user", "content": "What is 1 + 1 ?"}
|
| 10 |
-
],
|
| 11 |
-
max_tokens=100,
|
| 12 |
-
)
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime as dt
|
| 2 |
import os
|
| 3 |
+
from pathlib import Path
|
| 4 |
|
| 5 |
+
import gradio as gr
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
def _build_label() -> str:
|
| 9 |
+
version_file = Path("VERSION")
|
| 10 |
+
version_from_file = ""
|
| 11 |
+
if version_file.exists():
|
| 12 |
+
version_from_file = version_file.read_text(encoding="utf-8").strip()
|
| 13 |
+
|
| 14 |
+
commit = (
|
| 15 |
+
os.getenv("GITHUB_SHA")
|
| 16 |
+
or os.getenv("COMMIT_SHA")
|
| 17 |
+
or os.getenv("SPACE_COMMIT_SHA")
|
| 18 |
+
or version_from_file
|
| 19 |
+
or "local"
|
| 20 |
+
)
|
| 21 |
+
short_commit = commit[:7] if commit != "local" else commit
|
| 22 |
+
version = os.getenv("APP_VERSION") or short_commit
|
| 23 |
+
deployed_at = dt.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
|
| 24 |
+
return f"Version: {version} | Commit: {short_commit} | Loaded: {deployed_at}"
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def echo_with_meta(message: str) -> str:
|
| 28 |
+
clean = (message or "").strip()
|
| 29 |
+
if not clean:
|
| 30 |
+
return "Type something to test your CI/CD sync."
|
| 31 |
+
|
| 32 |
+
now = dt.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
|
| 33 |
+
return (
|
| 34 |
+
f"You typed: {clean}\n"
|
| 35 |
+
f"Length: {len(clean)} characters\n"
|
| 36 |
+
f"Built from GitHub sync demo\n"
|
| 37 |
+
f"Timestamp: {now}"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
with gr.Blocks(title="GitHub to Hugging Face Sync Demo") as demo:
|
| 42 |
+
gr.Markdown("# GitHub to Hugging Face CI/CD Demo")
|
| 43 |
+
gr.Markdown(f"**{_build_label()}**")
|
| 44 |
+
gr.Markdown(
|
| 45 |
+
"Edit this app in GitHub, push a commit, and your Hugging Face Space updates automatically."
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
text = gr.Textbox(
|
| 49 |
+
label="Try a message",
|
| 50 |
+
placeholder="Change this app in GitHub and test it here",
|
| 51 |
+
lines=3,
|
| 52 |
+
)
|
| 53 |
+
output = gr.Textbox(label="Result", lines=6)
|
| 54 |
+
run_btn = gr.Button("Run")
|
| 55 |
+
|
| 56 |
+
run_btn.click(fn=echo_with_meta, inputs=[text], outputs=[output])
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
demo.launch()
|
pyproject.toml
CHANGED
|
@@ -5,5 +5,6 @@ description = "Add your description here"
|
|
| 5 |
readme = "README.md"
|
| 6 |
requires-python = ">=3.13"
|
| 7 |
dependencies = [
|
|
|
|
| 8 |
"huggingface-hub>=1.11.0",
|
| 9 |
]
|
|
|
|
| 5 |
readme = "README.md"
|
| 6 |
requires-python = ">=3.13"
|
| 7 |
dependencies = [
|
| 8 |
+
"gradio>=5.49.1",
|
| 9 |
"huggingface-hub>=1.11.0",
|
| 10 |
]
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio>=5.49.1
|