Spaces:
Sleeping
Sleeping
Commit ·
4458bd1
0
Parent(s):
Initial commit
Browse files- .gitignore +7 -0
- .syncconfig +1 -0
- Dockerfile +7 -0
- README.md +8 -0
- app.py +12 -0
- requirements.txt +1 -0
- sync.ps1 +170 -0
.gitignore
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
.env
|
| 4 |
+
.DS_Store
|
| 5 |
+
*.log
|
| 6 |
+
.vscode/
|
| 7 |
+
*.tmp
|
.syncconfig
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{ "max_file_size_mb": 10, "ask_before_upload": true }
|
Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY requirements.txt .
|
| 4 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 5 |
+
COPY . .
|
| 6 |
+
EXPOSE 7860
|
| 7 |
+
CMD ["python", "app.py"]
|
README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: AdRL-Studio
|
| 3 |
+
colorFrom: purple
|
| 4 |
+
colorTo: blue
|
| 5 |
+
sdk: docker
|
| 6 |
+
app_port: 7860
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
app.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template_string
|
| 2 |
+
app = Flask(__name__)
|
| 3 |
+
HTML = """<!DOCTYPE html>
|
| 4 |
+
<html><head><title>AdRL-Studio</title></head>
|
| 5 |
+
<body style="font-family:Arial;max-width:800px;margin:50px auto;padding:20px">
|
| 6 |
+
<h1>AdRL-Studio</h1>
|
| 7 |
+
<p>Running on port 7860.</p>
|
| 8 |
+
<span style="background:#28a745;color:#fff;padding:5px 15px;border-radius:15px">Running</span>
|
| 9 |
+
</body></html>"""
|
| 10 |
+
@app.route('/')
|
| 11 |
+
def home(): return render_template_string(HTML)
|
| 12 |
+
if __name__ == '__main__': app.run(host='0.0.0.0', port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
flask==3.0.0
|
sync.ps1
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
param(
|
| 2 |
+
[string]$Message = "",
|
| 3 |
+
[switch]$PullOnly,
|
| 4 |
+
[switch]$Verbose
|
| 5 |
+
)
|
| 6 |
+
|
| 7 |
+
if ($Message -eq "" -and -not $PullOnly) {
|
| 8 |
+
$Message = "Update " + (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
if (-not $env:HF_TOKEN -or $env:HF_TOKEN.Trim().Length -lt 10) {
|
| 12 |
+
Write-Host "Error: HF_TOKEN not set"
|
| 13 |
+
Write-Host "Set with: [Environment]::SetEnvironmentVariable('HF_TOKEN','YOUR_TOKEN','User')"
|
| 14 |
+
exit 1
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
$repoRoot = git rev-parse --show-toplevel 2>$null
|
| 18 |
+
if ($LASTEXITCODE -ne 0) { Write-Host "Error: Not a git repository"; exit 1 }
|
| 19 |
+
Set-Location $repoRoot
|
| 20 |
+
|
| 21 |
+
$hfRemote = git remote get-url huggingface 2>$null
|
| 22 |
+
if ($LASTEXITCODE -ne 0) { Write-Host "Error: HuggingFace remote not configured"; exit 1 }
|
| 23 |
+
|
| 24 |
+
if ($hfRemote -match 'huggingface\.co/spaces/([^/]+)/(.+?)(?:\.git)?$') {
|
| 25 |
+
$hfUser = $Matches[1]
|
| 26 |
+
$hfSpace = $Matches[2]
|
| 27 |
+
} else { Write-Host "Error: Cannot parse HF remote"; exit 1 }
|
| 28 |
+
|
| 29 |
+
$config = @{ max_file_size_mb = 10; ask_before_upload = $true }
|
| 30 |
+
if (Test-Path ".syncconfig") {
|
| 31 |
+
try {
|
| 32 |
+
$configData = Get-Content ".syncconfig" -Raw | ConvertFrom-Json
|
| 33 |
+
$config.max_file_size_mb = $configData.max_file_size_mb
|
| 34 |
+
$config.ask_before_upload = $configData.ask_before_upload
|
| 35 |
+
} catch {}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
Write-Host "`n=== 3-Way Date-Priority Sync ===`n"
|
| 39 |
+
|
| 40 |
+
function Get-RemoteCommit($remote) {
|
| 41 |
+
$commit = git rev-parse "$remote/main" 2>$null
|
| 42 |
+
if ($LASTEXITCODE -eq 0) { return $commit }; return $null
|
| 43 |
+
}
|
| 44 |
+
function Get-RemoteDate($remote) {
|
| 45 |
+
$date = git log "$remote/main" -1 --format=%ci 2>$null
|
| 46 |
+
if ($LASTEXITCODE -eq 0 -and $date) { return [datetime]$date }
|
| 47 |
+
return [datetime]::MinValue
|
| 48 |
+
}
|
| 49 |
+
function Get-FileSize($path) {
|
| 50 |
+
if (Test-Path $path) { return (Get-Item $path).Length / 1MB }; return 0
|
| 51 |
+
}
|
| 52 |
+
function Ask-Upload($fileName, $sizeMB) {
|
| 53 |
+
Write-Host "`n[WARN] Large file: $fileName ($([math]::Round($sizeMB,2)) MB)"
|
| 54 |
+
Write-Host " 1. Yes - Upload this file"
|
| 55 |
+
Write-Host " 2. No - Skip this file"
|
| 56 |
+
Write-Host " 3. All - Upload all large files"
|
| 57 |
+
Write-Host " 4. Skip - Skip all large files"
|
| 58 |
+
$c = Read-Host "Choice [1-4] (default: 2)"; if ($c -eq "") { $c = "2" }; return $c
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
git add -A
|
| 62 |
+
$skipAll = $false; $uploadAll = $false
|
| 63 |
+
|
| 64 |
+
if ($config.ask_before_upload) {
|
| 65 |
+
$allFiles = git diff --cached --name-only --diff-filter=ACMR
|
| 66 |
+
$largeFiles = @()
|
| 67 |
+
foreach ($file in $allFiles) {
|
| 68 |
+
if (Test-Path $file) {
|
| 69 |
+
$sizeMB = Get-FileSize $file
|
| 70 |
+
if ($sizeMB -gt $config.max_file_size_mb) { $largeFiles += @{ Path=$file; Size=$sizeMB } }
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
if ($largeFiles.Count -gt 0) {
|
| 74 |
+
Write-Host "Found $($largeFiles.Count) large file(s) (>$($config.max_file_size_mb) MB)"
|
| 75 |
+
$filesToSkip = @()
|
| 76 |
+
foreach ($fileInfo in $largeFiles) {
|
| 77 |
+
if ($uploadAll) { continue }
|
| 78 |
+
if ($skipAll) { $filesToSkip += $fileInfo.Path; continue }
|
| 79 |
+
$c = Ask-Upload $fileInfo.Path $fileInfo.Size
|
| 80 |
+
switch ($c) {
|
| 81 |
+
"1" { continue } "2" { $filesToSkip += $fileInfo.Path }
|
| 82 |
+
"3" { $uploadAll = $true } "4" { $skipAll = $true; $filesToSkip += $fileInfo.Path }
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
if ($filesToSkip.Count -gt 0) {
|
| 86 |
+
Write-Host "Skipping $($filesToSkip.Count) file(s):"
|
| 87 |
+
foreach ($f in $filesToSkip) { git reset HEAD $f 2>$null | Out-Null; Write-Host " - $f" }
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
Write-Host "Fetching from remotes..."
|
| 93 |
+
git fetch github 2>$null; $ghExists = $LASTEXITCODE -eq 0
|
| 94 |
+
git fetch huggingface 2>$null; $hfExists = $LASTEXITCODE -eq 0
|
| 95 |
+
$isFirstPush = (-not $ghExists -and -not $hfExists)
|
| 96 |
+
|
| 97 |
+
if (-not $isFirstPush) {
|
| 98 |
+
$localCommit = git rev-parse HEAD 2>$null
|
| 99 |
+
$ghCommit = Get-RemoteCommit "github"
|
| 100 |
+
$hfCommit = Get-RemoteCommit "huggingface"
|
| 101 |
+
$localDate = git log HEAD -1 --format=%ci 2>$null
|
| 102 |
+
$localDateTime = if ($localDate) { [datetime]$localDate } else { [datetime]::MinValue }
|
| 103 |
+
$ghDate = Get-RemoteDate "github"
|
| 104 |
+
$hfDate = Get-RemoteDate "huggingface"
|
| 105 |
+
|
| 106 |
+
Write-Host "Last update dates:"
|
| 107 |
+
Write-Host " Local: $($localDateTime.ToString('yyyy-MM-dd HH:mm:ss'))"
|
| 108 |
+
if ($ghExists) { Write-Host " GitHub: $($ghDate.ToString('yyyy-MM-dd HH:mm:ss'))" }
|
| 109 |
+
if ($hfExists) { Write-Host " HuggingFace: $($hfDate.ToString('yyyy-MM-dd HH:mm:ss'))" }
|
| 110 |
+
Write-Host ""
|
| 111 |
+
|
| 112 |
+
$remotesToMerge = @()
|
| 113 |
+
if ($ghExists -and $ghCommit -and $localCommit -ne $ghCommit) {
|
| 114 |
+
$remotesToMerge += @{ Name="github"; Date=$ghDate; Commit=$ghCommit }
|
| 115 |
+
}
|
| 116 |
+
if ($hfExists -and $hfCommit -and $localCommit -ne $hfCommit) {
|
| 117 |
+
$remotesToMerge += @{ Name="huggingface"; Date=$hfDate; Commit=$hfCommit }
|
| 118 |
+
}
|
| 119 |
+
$remotesToMerge = $remotesToMerge | Sort-Object -Property Date -Descending
|
| 120 |
+
|
| 121 |
+
foreach ($remote in $remotesToMerge) {
|
| 122 |
+
$rName = $remote.Name; $rDate = $remote.Date.ToString('yyyy-MM-dd HH:mm:ss')
|
| 123 |
+
Write-Host "Merging from $rName (updated: $rDate)..."
|
| 124 |
+
git diff HEAD --quiet
|
| 125 |
+
if ($LASTEXITCODE -ne 0) { git commit -m "Local changes before $rName merge" 2>$null | Out-Null }
|
| 126 |
+
git merge "$rName/main" --no-edit 2>&1 | Out-Null
|
| 127 |
+
if ($LASTEXITCODE -ne 0) { Write-Host "[WARN] Conflict detected — keeping local version"; git merge --abort 2>$null }
|
| 128 |
+
else { Write-Host "[OK] Merged from $rName" }
|
| 129 |
+
$localCommit = git rev-parse HEAD 2>$null
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
$localCommit = git rev-parse HEAD 2>$null
|
| 133 |
+
if ($ghCommit -and $hfCommit -and $localCommit -eq $ghCommit -and $localCommit -eq $hfCommit) {
|
| 134 |
+
Write-Host "[OK] All 3 locations already in sync"
|
| 135 |
+
} elseif ($remotesToMerge.Count -eq 0) { Write-Host "[OK] Already in sync" }
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
if ($PullOnly) { Write-Host "`n[OK] Pull complete`n"; exit 0 }
|
| 139 |
+
|
| 140 |
+
git diff HEAD --quiet
|
| 141 |
+
if ($LASTEXITCODE -ne 0) {
|
| 142 |
+
git commit -m $Message; Write-Host "[OK] Committed: $Message"
|
| 143 |
+
} else {
|
| 144 |
+
$localCommit = git rev-parse HEAD 2>$null; $needsPush = $false
|
| 145 |
+
if ($ghExists) { $ghCommit = Get-RemoteCommit "github"; if ($localCommit -ne $ghCommit) { $needsPush = $true } } else { $needsPush = $true }
|
| 146 |
+
if ($hfExists) { $hfCommit = Get-RemoteCommit "huggingface"; if ($localCommit -ne $hfCommit) { $needsPush = $true } } else { $needsPush = $true }
|
| 147 |
+
if (-not $needsPush) { Write-Host "`n[OK] Already up-to-date`n"; exit 0 }
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
Write-Host "`nPushing to remotes..."
|
| 151 |
+
git push github main 2>&1 | Out-Null
|
| 152 |
+
if ($LASTEXITCODE -eq 0) { Write-Host "[OK] GitHub" }
|
| 153 |
+
else {
|
| 154 |
+
git push github main --force 2>&1 | Out-Null
|
| 155 |
+
if ($LASTEXITCODE -eq 0) { Write-Host "[OK] GitHub (forced)" } else { Write-Host "[ERROR] GitHub push failed" }
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
$hfUrl = "https://${hfUser}:$($env:HF_TOKEN)@huggingface.co/spaces/${hfUser}/${hfSpace}"
|
| 159 |
+
$pushOutput = git push $hfUrl main --force 2>&1
|
| 160 |
+
if ($Verbose) { Write-Host "Git output: $pushOutput" }
|
| 161 |
+
if ($LASTEXITCODE -eq 0) { Write-Host "[OK] HuggingFace" }
|
| 162 |
+
else {
|
| 163 |
+
Write-Host "[ERROR] HuggingFace push failed!"
|
| 164 |
+
Write-Host " $pushOutput"
|
| 165 |
+
Write-Host " Check: space exists at huggingface.co/spaces/${hfUser}/${hfSpace}"
|
| 166 |
+
Write-Host " Try: .\sync.ps1 -Verbose"
|
| 167 |
+
exit 1
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
Write-Host "`n[OK] Sync complete!`n"
|