UCS2014 commited on
Commit
3a3b3ae
·
verified ·
1 Parent(s): 8ec6473

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -20
app.py CHANGED
@@ -1,6 +1,8 @@
1
- import streamlit as st
2
- from pathlib import Path
3
  from html import escape
 
 
4
 
5
  # ---------- PATHS (subfolder-safe) ----------
6
  BASE_DIR = Path(__file__).parent # -> Landing_Page/
@@ -13,22 +15,23 @@ TAGLINE = "We Deliver Smart AI-Based Solutions For O&G Industry"
13
  APP1 = {
14
  "title": "ST_Geo_Mech",
15
  "url": "https://smart-thinking-ucs.hf.space/",
16
- "thumb": (ASSETS / "app1.png").as_posix(),
17
  "blurb": "Real-Time UCS Prediction",
18
  }
19
  APP2 = {
20
  "title": "ST_Log_GR",
21
  "url": "https://smart-thinking-gr.hf.space/",
22
- "thumb": (ASSETS / "app2.png").as_posix(),
23
  "blurb": "Real-Time GR Log Prediction",
24
  }
 
25
  LOGO_PATH = ASSETS / "logo.png"
26
 
27
  # ---------- PAGE META ----------
28
- page_icon = LOGO_PATH.as_posix() if LOGO_PATH.exists() else "🧭"
29
  st.set_page_config(page_title=f"{COMPANY_NAME} — Apps", page_icon=page_icon, layout="wide")
30
 
31
- # ---------- GLOBAL STYLES ----------
32
  st.markdown(
33
  """
34
  <style>
@@ -54,31 +57,41 @@ st.markdown(
54
  unsafe_allow_html=True,
55
  )
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  # ---------- HERO ----------
58
- logo_html = f'<img src="{LOGO_PATH.as_posix()}" alt="logo" />' if LOGO_PATH.exists() else ""
59
  st.markdown(
60
  '<div class="hero">' + logo_html + f"<h1>{COMPANY_NAME}</h1>" + f"<p>{TAGLINE}</p>" + "</div>",
61
  unsafe_allow_html=True,
62
  )
63
 
64
- # ---------- HELPERS ----------
65
- def img_or_placeholder(src: str, alt: str):
66
- p = Path(src)
67
- if p.exists():
68
- return f'<img class="thumb" src="{escape(src)}" alt="{escape(alt)}" />'
69
- return f'<div class="thumb">{escape(alt)}</div>'
70
-
71
- def app_card(app_dict: dict) -> str:
72
  return f"""
73
  <div class="card">
74
- {img_or_placeholder(app_dict['thumb'], app_dict['title'])}
75
- <h3>{escape(app_dict['title'])}</h3>
76
- <p>{escape(app_dict['blurb'])}</p>
77
- <a class="btn btn-primary" href="{escape(app_dict['url'])}" target="_self">Open {escape(app_dict['title'])}</a>
78
  </div>
79
  """
80
 
81
- # ---------- GRID (2 CARDS) ----------
82
  html_grid = f"<div class='grid'>{app_card(APP1)}{app_card(APP2)}</div>"
83
  st.markdown(html_grid, unsafe_allow_html=True)
84
 
 
1
+ import base64
2
+ import mimetypes
3
  from html import escape
4
+ from pathlib import Path
5
+ import streamlit as st
6
 
7
  # ---------- PATHS (subfolder-safe) ----------
8
  BASE_DIR = Path(__file__).parent # -> Landing_Page/
 
15
  APP1 = {
16
  "title": "ST_Geo_Mech",
17
  "url": "https://smart-thinking-ucs.hf.space/",
18
+ "thumb_path": ASSETS / "app1.png",
19
  "blurb": "Real-Time UCS Prediction",
20
  }
21
  APP2 = {
22
  "title": "ST_Log_GR",
23
  "url": "https://smart-thinking-gr.hf.space/",
24
+ "thumb_path": ASSETS / "app2.png",
25
  "blurb": "Real-Time GR Log Prediction",
26
  }
27
+
28
  LOGO_PATH = ASSETS / "logo.png"
29
 
30
  # ---------- PAGE META ----------
31
+ page_icon = str(LOGO_PATH) if LOGO_PATH.exists() else "🧭"
32
  st.set_page_config(page_title=f"{COMPANY_NAME} — Apps", page_icon=page_icon, layout="wide")
33
 
34
+ # ---------- STYLES ----------
35
  st.markdown(
36
  """
37
  <style>
 
57
  unsafe_allow_html=True,
58
  )
59
 
60
+ # ---------- IMAGE HELPERS ----------
61
+ def to_data_uri(path: Path) -> str | None:
62
+ """Return a data: URI for an image path, or None if missing."""
63
+ if not path.exists():
64
+ return None
65
+ mime, _ = mimetypes.guess_type(path.name)
66
+ if not mime:
67
+ mime = "image/png"
68
+ b64 = base64.b64encode(path.read_bytes()).decode("utf-8")
69
+ return f"data:{mime};base64,{b64}"
70
+
71
+ def img_or_placeholder(path: Path, alt: str) -> str:
72
+ uri = to_data_uri(path)
73
+ if uri:
74
+ return f'<img class="thumb" src="{uri}" alt="{escape(alt)}" />'
75
+ return f'<div class="thumb">{escape(alt)}</div>'
76
+
77
  # ---------- HERO ----------
78
+ logo_html = img_or_placeholder(LOGO_PATH, "logo") if LOGO_PATH.exists() else ""
79
  st.markdown(
80
  '<div class="hero">' + logo_html + f"<h1>{COMPANY_NAME}</h1>" + f"<p>{TAGLINE}</p>" + "</div>",
81
  unsafe_allow_html=True,
82
  )
83
 
84
+ # ---------- CARD RENDERING ----------
85
+ def app_card(app: dict) -> str:
 
 
 
 
 
 
86
  return f"""
87
  <div class="card">
88
+ {img_or_placeholder(app['thumb_path'], app['title'])}
89
+ <h3>{escape(app['title'])}</h3>
90
+ <p>{escape(app['blurb'])}</p>
91
+ <a class="btn btn-primary" href="{escape(app['url'])}" target="_self">Open {escape(app['title'])}</a>
92
  </div>
93
  """
94
 
 
95
  html_grid = f"<div class='grid'>{app_card(APP1)}{app_card(APP2)}</div>"
96
  st.markdown(html_grid, unsafe_allow_html=True)
97