akhaliq HF Staff commited on
Commit
ee67bed
·
verified ·
1 Parent(s): 5351a57

Show Built with ML Intern badge in the app UI

Browse files
Files changed (1) hide show
  1. app.py +37 -1
app.py CHANGED
@@ -40,6 +40,42 @@ MODEL_ID = "openbmb/MiniCPM-V-4.7-35B-A3B"
40
  DOWNSAMPLE_MODE = "16x"
41
  MAX_NEW_TOKENS = 512
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  # Load once at module scope and move to cuda here, not inside the GPU
44
  # functions: the spaces package intercepts the move, packs the weights, and
45
  # transfers them when a GPU is actually allocated — module scope costs no GPU
@@ -207,4 +243,4 @@ demo = gr.Workflow(
207
  )
208
 
209
  if __name__ == "__main__":
210
- demo.launch()
 
40
  DOWNSAMPLE_MODE = "16x"
41
  MAX_NEW_TOKENS = 512
42
 
43
+ # "Built with ML Intern" badge, injected into the page by launch(css=, js=).
44
+ # gr.Workflow must be the top-level app (it cannot nest inside gr.Blocks), so
45
+ # there is no gr.HTML slot — the badge is a fixed-position element appended to
46
+ # <body> on page load, visible in both the app view and the canvas view.
47
+ _BADGE_CSS = """
48
+ #ml-intern-badge {
49
+ position: fixed;
50
+ left: 12px;
51
+ bottom: 12px;
52
+ z-index: 1000;
53
+ line-height: 0;
54
+ }
55
+ #ml-intern-badge img { height: 28px; }
56
+ """
57
+
58
+ _BADGE_JS = """
59
+ function addMlInternBadge() {
60
+ if (document.getElementById('ml-intern-badge')) return;
61
+ const badge = document.createElement('a');
62
+ badge.id = 'ml-intern-badge';
63
+ badge.href = 'https://hf.co/chat?mode=ml-intern';
64
+ badge.target = '_blank';
65
+ badge.rel = 'noopener';
66
+ const img = document.createElement('img');
67
+ img.src = 'https://huggingface.co/datasets/huggingface/badges/resolve/main/built-with-ml-intern-sm.svg';
68
+ img.alt = 'Built with ML Intern';
69
+ badge.appendChild(img);
70
+ document.body.appendChild(badge);
71
+ }
72
+ if (document.body) {
73
+ addMlInternBadge();
74
+ } else {
75
+ document.addEventListener('DOMContentLoaded', addMlInternBadge);
76
+ }
77
+ """
78
+
79
  # Load once at module scope and move to cuda here, not inside the GPU
80
  # functions: the spaces package intercepts the move, packs the weights, and
81
  # transfers them when a GPU is actually allocated — module scope costs no GPU
 
243
  )
244
 
245
  if __name__ == "__main__":
246
+ demo.launch(css=_BADGE_CSS, js=_BADGE_JS)