Spaces:
Sleeping
Sleeping
Sync from GitHub via hub-sync
Browse files- __pycache__/app.cpython-312.pyc +0 -0
- android/app/build.gradle.kts +2 -2
- android/app/src/main/java/com/ahad/lyricsoverlay/OnlineLyricsClient.kt +13 -7
- android/app/src/main/java/com/ahad/lyricsoverlay/PlayerService.kt +3 -1
- lyr_service/__pycache__/__init__.cpython-312.pyc +0 -0
- lyr_service/__pycache__/domain.cpython-312.pyc +0 -0
- lyr_service/__pycache__/lyrics.cpython-312.pyc +0 -0
- lyr_service/__pycache__/provider.cpython-312.pyc +0 -0
- lyr_service/__pycache__/service.cpython-312.pyc +0 -0
- scripts/__pycache__/configure_space.cpython-312.pyc +0 -0
- scripts/__pycache__/smoke_space.cpython-312.pyc +0 -0
- scripts/configure_space.py +3 -0
- scripts/smoke_space.py +163 -0
- tests/__pycache__/test_domain.cpython-312.pyc +0 -0
- tests/__pycache__/test_lyrics.cpython-312.pyc +0 -0
- tests/__pycache__/test_provider.cpython-312.pyc +0 -0
- tests/__pycache__/test_service.cpython-312.pyc +0 -0
__pycache__/app.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-312.pyc and b/__pycache__/app.cpython-312.pyc differ
|
|
|
android/app/build.gradle.kts
CHANGED
|
@@ -11,8 +11,8 @@ android {
|
|
| 11 |
applicationId = "com.ahad.lyricsoverlay"
|
| 12 |
minSdk = 24
|
| 13 |
targetSdk = 34
|
| 14 |
-
versionCode =
|
| 15 |
-
versionName = "3.0.
|
| 16 |
|
| 17 |
}
|
| 18 |
|
|
|
|
| 11 |
applicationId = "com.ahad.lyricsoverlay"
|
| 12 |
minSdk = 24
|
| 13 |
targetSdk = 34
|
| 14 |
+
versionCode = 10
|
| 15 |
+
versionName = "3.0.2"
|
| 16 |
|
| 17 |
}
|
| 18 |
|
android/app/src/main/java/com/ahad/lyricsoverlay/OnlineLyricsClient.kt
CHANGED
|
@@ -106,19 +106,25 @@ class OnlineLyricsClient(
|
|
| 106 |
if (declaredSize > MAX_UPLOAD_BYTES) {
|
| 107 |
throw IOException("This song is larger than the 16 GB upload ceiling.")
|
| 108 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
val connection = open("$SPACE_ROOT/gradio_api/upload", "POST", UPLOAD_TIMEOUT_MS).apply {
|
| 110 |
doOutput = true
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
setRequestProperty("Content-Type", "multipart/form-data; boundary=$boundary")
|
| 113 |
}
|
| 114 |
activeConnection = connection
|
| 115 |
try {
|
| 116 |
BufferedOutputStream(connection.outputStream, BUFFER_BYTES).use { output ->
|
| 117 |
-
output.write(
|
| 118 |
-
output.write(
|
| 119 |
-
"Content-Disposition: form-data; name=\"files\"; filename=\"$safeName\"\r\n".toByteArray()
|
| 120 |
-
)
|
| 121 |
-
output.write("Content-Type: $mime\r\n\r\n".toByteArray())
|
| 122 |
resolver.openInputStream(uri)?.use { raw ->
|
| 123 |
BufferedInputStream(raw, BUFFER_BYTES).use { input ->
|
| 124 |
val buffer = ByteArray(BUFFER_BYTES)
|
|
@@ -139,7 +145,7 @@ class OnlineLyricsClient(
|
|
| 139 |
}
|
| 140 |
}
|
| 141 |
} ?: throw IOException("The selected audio file cannot be opened.")
|
| 142 |
-
output.write(
|
| 143 |
output.flush()
|
| 144 |
}
|
| 145 |
val body = readResponse(connection)
|
|
|
|
| 106 |
if (declaredSize > MAX_UPLOAD_BYTES) {
|
| 107 |
throw IOException("This song is larger than the 16 GB upload ceiling.")
|
| 108 |
}
|
| 109 |
+
val prefix = buildString {
|
| 110 |
+
append("--$boundary\r\n")
|
| 111 |
+
append("Content-Disposition: form-data; name=\"files\"; filename=\"$safeName\"\r\n")
|
| 112 |
+
append("Content-Type: $mime\r\n\r\n")
|
| 113 |
+
}.toByteArray(Charsets.UTF_8)
|
| 114 |
+
val suffix = "\r\n--$boundary--\r\n".toByteArray(Charsets.UTF_8)
|
| 115 |
val connection = open("$SPACE_ROOT/gradio_api/upload", "POST", UPLOAD_TIMEOUT_MS).apply {
|
| 116 |
doOutput = true
|
| 117 |
+
if (declaredSize >= 0L) {
|
| 118 |
+
setFixedLengthStreamingMode(prefix.size.toLong() + declaredSize + suffix.size)
|
| 119 |
+
} else {
|
| 120 |
+
setChunkedStreamingMode(BUFFER_BYTES)
|
| 121 |
+
}
|
| 122 |
setRequestProperty("Content-Type", "multipart/form-data; boundary=$boundary")
|
| 123 |
}
|
| 124 |
activeConnection = connection
|
| 125 |
try {
|
| 126 |
BufferedOutputStream(connection.outputStream, BUFFER_BYTES).use { output ->
|
| 127 |
+
output.write(prefix)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
resolver.openInputStream(uri)?.use { raw ->
|
| 129 |
BufferedInputStream(raw, BUFFER_BYTES).use { input ->
|
| 130 |
val buffer = ByteArray(BUFFER_BYTES)
|
|
|
|
| 145 |
}
|
| 146 |
}
|
| 147 |
} ?: throw IOException("The selected audio file cannot be opened.")
|
| 148 |
+
output.write(suffix)
|
| 149 |
output.flush()
|
| 150 |
}
|
| 151 |
val body = readResponse(connection)
|
android/app/src/main/java/com/ahad/lyricsoverlay/PlayerService.kt
CHANGED
|
@@ -864,7 +864,9 @@ class PlayerService : Service(), OnDeviceAiLyricsManager.Listener {
|
|
| 864 |
if (!success && currentSong()?.id == song.id) {
|
| 865 |
updateLyricsLoadState(LyricsLoadState.NOT_FOUND)
|
| 866 |
}
|
| 867 |
-
|
|
|
|
|
|
|
| 868 |
if (automaticLyricsSong?.id == song.id) automaticLyricsSong = null
|
| 869 |
startPendingAutomaticLyricsIfNeeded(song.id)
|
| 870 |
}
|
|
|
|
| 864 |
if (!success && currentSong()?.id == song.id) {
|
| 865 |
updateLyricsLoadState(LyricsLoadState.NOT_FOUND)
|
| 866 |
}
|
| 867 |
+
// Preserve a failed/canceled state long enough for LyricsActivity to show the real HTTP,
|
| 868 |
+
// TLS, timeout, or server message. The next explicit retry clears it before starting.
|
| 869 |
+
if (success) OnDeviceAiLyricsManager.clearFinishedResult()
|
| 870 |
if (automaticLyricsSong?.id == song.id) automaticLyricsSong = null
|
| 871 |
startPendingAutomaticLyricsIfNeeded(song.id)
|
| 872 |
}
|
lyr_service/__pycache__/__init__.cpython-312.pyc
CHANGED
|
Binary files a/lyr_service/__pycache__/__init__.cpython-312.pyc and b/lyr_service/__pycache__/__init__.cpython-312.pyc differ
|
|
|
lyr_service/__pycache__/domain.cpython-312.pyc
CHANGED
|
Binary files a/lyr_service/__pycache__/domain.cpython-312.pyc and b/lyr_service/__pycache__/domain.cpython-312.pyc differ
|
|
|
lyr_service/__pycache__/lyrics.cpython-312.pyc
CHANGED
|
Binary files a/lyr_service/__pycache__/lyrics.cpython-312.pyc and b/lyr_service/__pycache__/lyrics.cpython-312.pyc differ
|
|
|
lyr_service/__pycache__/provider.cpython-312.pyc
CHANGED
|
Binary files a/lyr_service/__pycache__/provider.cpython-312.pyc and b/lyr_service/__pycache__/provider.cpython-312.pyc differ
|
|
|
lyr_service/__pycache__/service.cpython-312.pyc
CHANGED
|
Binary files a/lyr_service/__pycache__/service.cpython-312.pyc and b/lyr_service/__pycache__/service.cpython-312.pyc differ
|
|
|
scripts/__pycache__/configure_space.cpython-312.pyc
CHANGED
|
Binary files a/scripts/__pycache__/configure_space.cpython-312.pyc and b/scripts/__pycache__/configure_space.cpython-312.pyc differ
|
|
|
scripts/__pycache__/smoke_space.cpython-312.pyc
ADDED
|
Binary file (8.19 kB). View file
|
|
|
scripts/configure_space.py
CHANGED
|
@@ -7,6 +7,8 @@ import sys
|
|
| 7 |
|
| 8 |
from huggingface_hub import HfApi
|
| 9 |
|
|
|
|
|
|
|
| 10 |
SPACE_ID = os.getenv("HF_SPACE_ID", "madarauchihagmailcom/My")
|
| 11 |
TOKEN = os.getenv("HF_TOKEN", "").strip()
|
| 12 |
|
|
@@ -27,3 +29,4 @@ print(
|
|
| 27 |
f"Configured {SPACE_ID}: stage={runtime.stage}, "
|
| 28 |
f"hardware={runtime.hardware}, requested={runtime.requested_hardware}"
|
| 29 |
)
|
|
|
|
|
|
| 7 |
|
| 8 |
from huggingface_hub import HfApi
|
| 9 |
|
| 10 |
+
from smoke_space import run_deployed_smoke_test
|
| 11 |
+
|
| 12 |
SPACE_ID = os.getenv("HF_SPACE_ID", "madarauchihagmailcom/My")
|
| 13 |
TOKEN = os.getenv("HF_TOKEN", "").strip()
|
| 14 |
|
|
|
|
| 29 |
f"Configured {SPACE_ID}: stage={runtime.stage}, "
|
| 30 |
f"hardware={runtime.hardware}, requested={runtime.requested_hardware}"
|
| 31 |
)
|
| 32 |
+
run_deployed_smoke_test(api)
|
scripts/smoke_space.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""End-to-end smoke test for the deployed upload, queue, Whisper, and LRC path."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import json
|
| 6 |
+
import time
|
| 7 |
+
from typing import Any
|
| 8 |
+
|
| 9 |
+
import requests
|
| 10 |
+
from huggingface_hub import HfApi
|
| 11 |
+
|
| 12 |
+
SPACE_ID = "madarauchihagmailcom/My"
|
| 13 |
+
SPACE_URL = "https://madarauchihagmailcom-my.hf.space"
|
| 14 |
+
# Public-domain recording of John F. Kennedy, distributed by whisper.cpp for ASR tests.
|
| 15 |
+
TEST_AUDIO_URL = (
|
| 16 |
+
"https://raw.githubusercontent.com/ggml-org/whisper.cpp/"
|
| 17 |
+
"master/samples/jfk.wav"
|
| 18 |
+
)
|
| 19 |
+
USER_AGENT = "Lyr-Deployment-Smoke/1.0"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class SmokeTestError(RuntimeError):
|
| 23 |
+
"""The public Android-facing workflow did not complete successfully."""
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def wait_for_space(
|
| 27 |
+
api: HfApi,
|
| 28 |
+
*,
|
| 29 |
+
repo_id: str = SPACE_ID,
|
| 30 |
+
timeout_seconds: int = 720,
|
| 31 |
+
) -> str:
|
| 32 |
+
"""Wait for the currently mirrored revision to become the running revision."""
|
| 33 |
+
|
| 34 |
+
deadline = time.monotonic() + timeout_seconds
|
| 35 |
+
last = "unknown"
|
| 36 |
+
while time.monotonic() < deadline:
|
| 37 |
+
target_sha = api.repo_info(repo_id=repo_id, repo_type="space").sha
|
| 38 |
+
runtime = api.get_space_runtime(repo_id=repo_id)
|
| 39 |
+
raw = runtime.raw or {}
|
| 40 |
+
running_sha = str(raw.get("sha") or "")
|
| 41 |
+
last = f"stage={runtime.stage}, target={target_sha}, running={running_sha}"
|
| 42 |
+
if runtime.stage == "RUNNING" and running_sha == target_sha:
|
| 43 |
+
return target_sha
|
| 44 |
+
time.sleep(10)
|
| 45 |
+
raise SmokeTestError(f"Space did not reach its mirrored revision: {last}")
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _request(method: str, url: str, **kwargs: Any) -> requests.Response:
|
| 49 |
+
headers = {"User-Agent": USER_AGENT, **kwargs.pop("headers", {})}
|
| 50 |
+
last_error: Exception | None = None
|
| 51 |
+
for attempt in range(3):
|
| 52 |
+
try:
|
| 53 |
+
response = requests.request(
|
| 54 |
+
method,
|
| 55 |
+
url,
|
| 56 |
+
headers=headers,
|
| 57 |
+
timeout=kwargs.pop("timeout", (30, 360)),
|
| 58 |
+
**kwargs,
|
| 59 |
+
)
|
| 60 |
+
if response.status_code not in {429, 500, 502, 503, 504}:
|
| 61 |
+
response.raise_for_status()
|
| 62 |
+
return response
|
| 63 |
+
last_error = SmokeTestError(
|
| 64 |
+
f"{method} {url} returned HTTP {response.status_code}"
|
| 65 |
+
)
|
| 66 |
+
except requests.RequestException as exc:
|
| 67 |
+
last_error = exc
|
| 68 |
+
if attempt < 2:
|
| 69 |
+
time.sleep((attempt + 1) * 8)
|
| 70 |
+
raise SmokeTestError(f"Request failed after retries: {last_error}")
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _upload_audio(audio: bytes) -> str:
|
| 74 |
+
response = _request(
|
| 75 |
+
"POST",
|
| 76 |
+
f"{SPACE_URL}/gradio_api/upload",
|
| 77 |
+
files={"files": ("jfk-public-domain.wav", audio, "audio/wav")},
|
| 78 |
+
)
|
| 79 |
+
payload = response.json()
|
| 80 |
+
if not isinstance(payload, list) or not payload:
|
| 81 |
+
raise SmokeTestError(f"Upload returned an invalid payload: {payload!r}")
|
| 82 |
+
first = payload[0]
|
| 83 |
+
if isinstance(first, dict):
|
| 84 |
+
path = str(first.get("path") or "")
|
| 85 |
+
else:
|
| 86 |
+
path = str(first)
|
| 87 |
+
if not path:
|
| 88 |
+
raise SmokeTestError("Upload did not return a server file path.")
|
| 89 |
+
return path
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def _start_transcription(path: str) -> str:
|
| 93 |
+
response = _request(
|
| 94 |
+
"POST",
|
| 95 |
+
f"{SPACE_URL}/gradio_api/call/v2/transcribe_song",
|
| 96 |
+
headers={"Content-Type": "application/json"},
|
| 97 |
+
data=json.dumps(
|
| 98 |
+
{
|
| 99 |
+
"audio_path": {
|
| 100 |
+
"path": path,
|
| 101 |
+
"meta": {"_type": "gradio.FileData"},
|
| 102 |
+
},
|
| 103 |
+
"title": "",
|
| 104 |
+
"artist": "",
|
| 105 |
+
"language_label": "English",
|
| 106 |
+
}
|
| 107 |
+
).encode(),
|
| 108 |
+
)
|
| 109 |
+
event_id = str(response.json().get("event_id") or "")
|
| 110 |
+
if not event_id:
|
| 111 |
+
raise SmokeTestError("Transcription call did not return an event ID.")
|
| 112 |
+
return event_id
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def _await_transcription(event_id: str) -> tuple[str, dict[str, Any]]:
|
| 116 |
+
response = _request(
|
| 117 |
+
"GET",
|
| 118 |
+
f"{SPACE_URL}/gradio_api/call/transcribe_song/{event_id}",
|
| 119 |
+
headers={"Accept": "text/event-stream"},
|
| 120 |
+
stream=True,
|
| 121 |
+
timeout=(30, 420),
|
| 122 |
+
)
|
| 123 |
+
event = ""
|
| 124 |
+
for raw_line in response.iter_lines(decode_unicode=True):
|
| 125 |
+
line = raw_line or ""
|
| 126 |
+
if line.startswith("event:"):
|
| 127 |
+
event = line.partition(":")[2].strip()
|
| 128 |
+
elif line.startswith("data:") and event == "error":
|
| 129 |
+
raise SmokeTestError("Gradio reported an error event.")
|
| 130 |
+
elif line.startswith("data:") and event == "complete":
|
| 131 |
+
outputs = json.loads(line.partition(":")[2].strip())
|
| 132 |
+
if not isinstance(outputs, list) or len(outputs) < 4:
|
| 133 |
+
raise SmokeTestError(
|
| 134 |
+
"Completion payload did not contain endpoint outputs."
|
| 135 |
+
)
|
| 136 |
+
lrc = str(outputs[1] or "").strip()
|
| 137 |
+
structured = outputs[3] if isinstance(outputs[3], dict) else {}
|
| 138 |
+
return lrc, structured
|
| 139 |
+
raise SmokeTestError("Transcription stream ended without a completion event.")
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def run_deployed_smoke_test(api: HfApi) -> dict[str, Any]:
|
| 143 |
+
revision = wait_for_space(api)
|
| 144 |
+
audio_response = _request("GET", TEST_AUDIO_URL, timeout=(30, 90))
|
| 145 |
+
if not 10_000 <= len(audio_response.content) <= 5_000_000:
|
| 146 |
+
raise SmokeTestError("Public-domain test audio had an unexpected size.")
|
| 147 |
+
path = _upload_audio(audio_response.content)
|
| 148 |
+
event_id = _start_transcription(path)
|
| 149 |
+
lrc, structured = _await_transcription(event_id)
|
| 150 |
+
if not structured.get("ok") or not lrc or "[" not in lrc:
|
| 151 |
+
raise SmokeTestError(
|
| 152 |
+
"Full transcription did not return successful synchronized lyrics: "
|
| 153 |
+
f"{structured!r}"
|
| 154 |
+
)
|
| 155 |
+
result = {
|
| 156 |
+
"revision": revision,
|
| 157 |
+
"source": structured.get("source"),
|
| 158 |
+
"language": structured.get("language"),
|
| 159 |
+
"lines": len(structured.get("lines") or []),
|
| 160 |
+
"audio_bytes": len(audio_response.content),
|
| 161 |
+
}
|
| 162 |
+
print(f"Deployed upload/transcription smoke passed: {json.dumps(result)}")
|
| 163 |
+
return result
|
tests/__pycache__/test_domain.cpython-312.pyc
CHANGED
|
Binary files a/tests/__pycache__/test_domain.cpython-312.pyc and b/tests/__pycache__/test_domain.cpython-312.pyc differ
|
|
|
tests/__pycache__/test_lyrics.cpython-312.pyc
CHANGED
|
Binary files a/tests/__pycache__/test_lyrics.cpython-312.pyc and b/tests/__pycache__/test_lyrics.cpython-312.pyc differ
|
|
|
tests/__pycache__/test_provider.cpython-312.pyc
CHANGED
|
Binary files a/tests/__pycache__/test_provider.cpython-312.pyc and b/tests/__pycache__/test_provider.cpython-312.pyc differ
|
|
|
tests/__pycache__/test_service.cpython-312.pyc
CHANGED
|
Binary files a/tests/__pycache__/test_service.cpython-312.pyc and b/tests/__pycache__/test_service.cpython-312.pyc differ
|
|
|