Spaces:
Sleeping
Sleeping
Update app_gradio_messenger.py
Browse files- app_gradio_messenger.py +29 -4
app_gradio_messenger.py
CHANGED
|
@@ -2,7 +2,9 @@ from __future__ import annotations
|
|
| 2 |
|
| 3 |
import html
|
| 4 |
import os
|
|
|
|
| 5 |
from threading import Lock
|
|
|
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
|
|
@@ -16,10 +18,33 @@ INITIAL_HISTORY = [{"role": "assistant", "content": INITIAL_GREETING}]
|
|
| 16 |
|
| 17 |
SERVICES: ChatServices | None = None
|
| 18 |
SERVICES_LOCK = Lock()
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
MEGUMIN_SVG = """
|
| 25 |
<svg viewBox="0 0 420 560" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Megumin inspired illustration">
|
|
|
|
| 2 |
|
| 3 |
import html
|
| 4 |
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
from threading import Lock
|
| 7 |
+
from urllib.parse import quote
|
| 8 |
|
| 9 |
import gradio as gr
|
| 10 |
|
|
|
|
| 18 |
|
| 19 |
SERVICES: ChatServices | None = None
|
| 20 |
SERVICES_LOCK = Lock()
|
| 21 |
+
APP_DIR = Path(__file__).resolve().parent
|
| 22 |
+
IMAGE_EXTENSIONS = (".png", ".jpg", ".jpeg", ".webp")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def resolve_megumin_image_path() -> Path:
|
| 26 |
+
configured_path = os.getenv("MEGUMIN_IMAGE_PATH", "").strip()
|
| 27 |
+
if configured_path:
|
| 28 |
+
return Path(configured_path).expanduser().resolve()
|
| 29 |
+
|
| 30 |
+
source_dir = APP_DIR / "source_file"
|
| 31 |
+
preferred_stem = "megumin_profile"
|
| 32 |
+
|
| 33 |
+
for extension in IMAGE_EXTENSIONS:
|
| 34 |
+
candidate = source_dir / f"{preferred_stem}{extension}"
|
| 35 |
+
if candidate.exists():
|
| 36 |
+
return candidate.resolve()
|
| 37 |
+
|
| 38 |
+
for extension in IMAGE_EXTENSIONS:
|
| 39 |
+
matches = sorted(source_dir.glob(f"*{extension}"))
|
| 40 |
+
if matches:
|
| 41 |
+
return matches[0].resolve()
|
| 42 |
+
|
| 43 |
+
return source_dir / f"{preferred_stem}.png"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
MEGUMIN_IMAGE_PATH = resolve_megumin_image_path()
|
| 47 |
+
MEGUMIN_IMAGE_URL = f"/gradio_api/file={quote(MEGUMIN_IMAGE_PATH.as_posix(), safe='/:')}"
|
| 48 |
|
| 49 |
MEGUMIN_SVG = """
|
| 50 |
<svg viewBox="0 0 420 560" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Megumin inspired illustration">
|