Spaces:
Sleeping
Sleeping
Update Home.py
Browse files
Home.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
import base64
|
|
|
|
|
|
|
| 2 |
from pathlib import Path
|
|
|
|
| 3 |
|
| 4 |
import streamlit as st
|
| 5 |
|
|
@@ -8,6 +11,51 @@ from src.ui_style import apply_global_style
|
|
| 8 |
st.set_page_config(page_title="Home", layout="wide")
|
| 9 |
apply_global_style()
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
logo_path = Path(__file__).resolve().parent / "icons" / "logo.png"
|
| 12 |
logo_data_uri = ""
|
| 13 |
if logo_path.exists():
|
|
|
|
| 1 |
import base64
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
from pathlib import Path
|
| 5 |
+
from urllib import request
|
| 6 |
|
| 7 |
import streamlit as st
|
| 8 |
|
|
|
|
| 11 |
st.set_page_config(page_title="Home", layout="wide")
|
| 12 |
apply_global_style()
|
| 13 |
|
| 14 |
+
|
| 15 |
+
def _log_visit_once() -> None:
|
| 16 |
+
if st.session_state.get("home_visit_logged"):
|
| 17 |
+
return
|
| 18 |
+
webhook_url = os.getenv("FEEDBACK_WEBHOOK_URL", "").strip()
|
| 19 |
+
webhook_token = os.getenv("FEEDBACK_WEBHOOK_TOKEN", "").strip()
|
| 20 |
+
if not webhook_url:
|
| 21 |
+
return
|
| 22 |
+
|
| 23 |
+
endpoint = webhook_url
|
| 24 |
+
if webhook_token:
|
| 25 |
+
sep = "&" if "?" in webhook_url else "?"
|
| 26 |
+
endpoint = f"{webhook_url}{sep}token={webhook_token}"
|
| 27 |
+
|
| 28 |
+
payload = {
|
| 29 |
+
"submitted_at_utc": st.session_state.get("session_start_utc", ""),
|
| 30 |
+
"name": "",
|
| 31 |
+
"email": "",
|
| 32 |
+
"page": "Home",
|
| 33 |
+
"category": "Visit",
|
| 34 |
+
"rating": "",
|
| 35 |
+
"message": "Automatic site visit log",
|
| 36 |
+
"allow_contact": False,
|
| 37 |
+
"source": "huggingface_space",
|
| 38 |
+
}
|
| 39 |
+
try:
|
| 40 |
+
req = request.Request(
|
| 41 |
+
endpoint,
|
| 42 |
+
data=json.dumps(payload).encode("utf-8"),
|
| 43 |
+
method="POST",
|
| 44 |
+
headers={"Content-Type": "application/json"},
|
| 45 |
+
)
|
| 46 |
+
with request.urlopen(req, timeout=12):
|
| 47 |
+
pass
|
| 48 |
+
except Exception:
|
| 49 |
+
pass
|
| 50 |
+
st.session_state["home_visit_logged"] = True
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
if "session_start_utc" not in st.session_state:
|
| 54 |
+
from datetime import datetime, timezone
|
| 55 |
+
|
| 56 |
+
st.session_state["session_start_utc"] = datetime.now(timezone.utc).isoformat()
|
| 57 |
+
_log_visit_once()
|
| 58 |
+
|
| 59 |
logo_path = Path(__file__).resolve().parent / "icons" / "logo.png"
|
| 60 |
logo_data_uri = ""
|
| 61 |
if logo_path.exists():
|