APP-1 demo improvements

#1
Files changed (6) hide show
  1. .gitattributes +0 -1
  2. .gitignore +0 -2
  3. README.md +7 -24
  4. app.py +12 -55
  5. assets/background_round.png +0 -3
  6. style.py +0 -68
.gitattributes CHANGED
@@ -33,4 +33,3 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
- *.png filter=lfs diff=lfs merge=lfs -text
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
.gitignore CHANGED
@@ -209,5 +209,3 @@ __marimo__/
209
  # Other custom ignores
210
  best_model
211
  model-cache
212
- *.onnx
213
- *.pt
 
209
  # Other custom ignores
210
  best_model
211
  model-cache
 
 
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: AlpineLLM Live Demo
3
  emoji: 🏔️
4
- colorFrom: indigo
5
- colorTo: blue
6
  sdk: gradio
7
  sdk_version: 5.42.0
8
  app_file: app.py
@@ -20,40 +20,23 @@ A domain-specific language model for alpine storytelling.
20
 
21
  Try asking about mountain adventures! 🏔️
22
 
23
- ## About AlpineLLM
24
 
25
- AlpineLLM-Tiny-10M-Base is a lightweight base language model with ~10.8 million trainable parameters. It was pre-trained from scratch on raw text corpora drawn primarily from public-domain literature on alpinism, including expedition narratives and climbing essays.
26
 
27
  This demo showcases the model’s text generation capabilities within its specialized domain. Please note that AlpineLLM is a base model, and it has not been fine-tuned for downstream tasks such as summarization or dialogue. Its outputs reflect patterns learned directly from the training texts.
28
 
29
- This space shows a free CPU-only demo of the model, so inference may take a few seconds. Text generation of the tiny model may lack full coherence due to its limited size and character-level tokenization. For improved results, consider using the source repository to load larger pretrained weights and run inference on a GPU.
30
 
31
  Complete source code and full model documentation is available in the related repositories.
32
 
33
  ### Related Repositories
34
 
35
- - [**🤗 AlpineLLM Model Page @ HuggingFace**](https://huggingface.co/Borzyszkowski/AlpineLLM-Tiny-10M-Base)
36
  - [**⛏️ AlpineLLM Source Code @ GitHub**](https://github.com/Borzyszkowski/AlpineLLM)
37
 
38
- ### How to install?
39
-
40
- The software has been tested on Ubuntu 20.04 with CUDA 12.2 and Python3.10.
41
-
42
- Please use a Python virtual environment to install the dependencies:
43
-
44
- python3.10 -m venv venv_AlpineLLM
45
- source venv_AlpineLLM/bin/activate
46
- pip install -r requirements.txt
47
-
48
- ### How to start?
49
-
50
- The application starts automatically upon pushing changes to the Hugging Face Space.
51
- For local development, please run:
52
-
53
- ```
54
- python app.py
55
- ```
56
 
57
  ### Contact and technical support
58
  - <b>Bartek Borzyszkowski</b> <br>
59
  Web: <a href="https://borzyszkowski.github.io/">borzyszkowski.github.io</a>
 
 
1
  ---
2
  title: AlpineLLM Live Demo
3
  emoji: 🏔️
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
  sdk_version: 5.42.0
8
  app_file: app.py
 
20
 
21
  Try asking about mountain adventures! 🏔️
22
 
23
+ ### About AlpineLLM Tiny
24
 
25
+ AlpineLLM Tiny is a lightweight base language model with ~10.8 million trainable parameters. It was pre-trained from scratch on raw text corpora drawn primarily from public-domain literature on alpinism, including expedition narratives and climbing essays.
26
 
27
  This demo showcases the model’s text generation capabilities within its specialized domain. Please note that AlpineLLM is a base model, and it has not been fine-tuned for downstream tasks such as summarization or dialogue. Its outputs reflect patterns learned directly from the training texts.
28
 
29
+ This space shows a free CPU-only demo of the model, so inference may take a few seconds. Text generation of the tiny model may lack full coherence. For improved results, consider checking the source repository to load larger pretrained weights and run inference on a GPU.
30
 
31
  Complete source code and full model documentation is available in the related repositories.
32
 
33
  ### Related Repositories
34
 
35
+ - [**🤗 AlpineLLM Model Weights @ HuggingFace**](https://huggingface.co/Borzyszkowski/AlpineLLM-Model)
36
  - [**⛏️ AlpineLLM Source Code @ GitHub**](https://github.com/Borzyszkowski/AlpineLLM)
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  ### Contact and technical support
40
  - <b>Bartek Borzyszkowski</b> <br>
41
  Web: <a href="https://borzyszkowski.github.io/">borzyszkowski.github.io</a>
42
+
app.py CHANGED
@@ -1,6 +1,5 @@
1
  """ A simple Gradio web app to interact with the AlpineLLM model """
2
 
3
- import base64
4
  import gradio as gr
5
  import os
6
  import shutil
@@ -8,9 +7,8 @@ import torch
8
 
9
  from huggingface_hub import hf_hub_download
10
 
11
- from config_util import Config
12
  from demo_inference import AlpineLLMInference
13
- from style import custom_css
14
 
15
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
16
 
@@ -26,70 +24,29 @@ def download_model(cfg):
26
  return model_path
27
 
28
 
29
- def image_to_base64_data_url(filepath: str) -> str:
30
- """ Convert an image file to a Base64 data URL for embedding in HTML """
31
- try:
32
- ext = os.path.splitext(filepath)[1].lower()
33
- mime_types = {".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png", ".gif": "image/gif", ".webp": "image/webp", ".bmp": "image/bmp"}
34
- mime_type = mime_types.get(ext, "image/jpeg")
35
- with open(filepath, "rb") as image_file:
36
- encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
37
- return f"data:{mime_type};base64,{encoded_string}"
38
- except Exception as e:
39
- print(f"Error encoding image to Base64: {e}")
40
- return ""
41
-
42
-
43
  def start_app():
44
  """ Start the web app via Gradio with custom layout """
45
- GOOGLE_FONTS_URL = "<link href='https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;700&display=swap' rel='stylesheet'>"
46
- LOGO_IMAGE_PATH = "assets/background_round.png"
47
- logo_data_url = image_to_base64_data_url(LOGO_IMAGE_PATH) if os.path.exists(LOGO_IMAGE_PATH) else ""
48
- with gr.Blocks(head=GOOGLE_FONTS_URL, css=custom_css, theme=gr.themes.Soft()) as app:
49
- gr.HTML("""
50
- <div class="app-header">
51
- <h1>AlpineLLM Live Demo</h1>
52
- <p>
53
- A domain-specific language model for alpine storytelling. <br>
54
- Try asking about mountain adventures! 🏔️ <br>
55
- <strong>Author:</strong> <a href="https://borzyszkowski.github.io/">Bartek Borzyszkowski</a>
56
- </p>
57
- </div>
58
- """)
59
-
60
- gr.HTML(f"""
61
- <div class="app-header">
62
- <img src="{logo_data_url}" alt="AlpineLLM" style="max-height:10%; width: auto; margin: 10px auto; display: block;">
63
- </div>
64
- <div class="quick-links">
65
- <a href="https://github.com/Borzyszkowski/AlpineLLM" target="_blank">GitHub</a> | <a href="https://huggingface.co/Borzyszkowski/AlpineLLM-Tiny-10M-Base" target="_blank">Model Page</a>
66
- </div>
67
- <div class="notice">
68
- <strong>Heads up:</strong> This space shows a free CPU-only demo of the model, so inference may take a few seconds. Text generation of the tiny model may lack full coherence due to its limited size and character-level tokenization. Consider using the source repository to load larger pretrained weights and run inference on a GPU.
69
- </div>
70
- <br>
71
- """)
72
-
73
- gr.Markdown("<h3> About AlpineLLM</h3>")
74
  gr.Markdown(
75
- "<p>"
76
- "AlpineLLM-Tiny-10M-Base is a lightweight base language model with ~10.8 million trainable parameters. It was pre-trained from scratch on raw text corpora drawn primarily from public-domain literature on alpinism, including expedition narratives and climbing essays. <br><br>"
77
- "This demo showcases the model's text generation capabilities within its specialized domain. Please note that AlpineLLM is a base model, and it has not been fine-tuned for downstream tasks such as summarization or dialogue. Its outputs reflect patterns learned directly from the training texts. <br><br>"
78
  "</p>"
79
  )
 
80
  with gr.Row():
81
- with gr.Column(scale=2):
82
  prompt = gr.Textbox(
83
  lines=8,
84
  label="Your alpine prompt...",
85
  placeholder="A dawn climb on the Matterhorn..."
86
  )
87
  max_tokens = gr.Slider(50, 1000, value=300, step=10, label="Max output tokens")
88
- generate_btn = gr.Button("⛏️ Generate")
89
 
90
  with gr.Column(scale=2):
91
- output = gr.Textbox(lines=15, label="Generated Alpine Story", interactive=False)
92
- gr.Markdown("<br>")
93
 
94
  # Bind button click to inference
95
  generate_btn.click(
@@ -108,8 +65,8 @@ if __name__ == '__main__':
108
  cfg = {
109
  'cuda_id': 0,
110
  'model_type': 'transformer',
111
- 'repo_id': "Borzyszkowski/AlpineLLM-Tiny-10M-Base",
112
- 'model_name': "best_model.pt",
113
  'cache_dir': "./model-cache",
114
  }
115
  cfg = Config(cfg)
 
1
  """ A simple Gradio web app to interact with the AlpineLLM model """
2
 
 
3
  import gradio as gr
4
  import os
5
  import shutil
 
7
 
8
  from huggingface_hub import hf_hub_download
9
 
 
10
  from demo_inference import AlpineLLMInference
11
+ from config_util import Config
12
 
13
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
14
 
 
24
  return model_path
25
 
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  def start_app():
28
  """ Start the web app via Gradio with custom layout """
29
+ with gr.Blocks(css="""#builtwithgradio, .footer, .svelte-1ipelgc {display: none !important;}""") as app:
30
+ gr.Markdown("<h1 style='text-align: center;'> AlpineLLM App</h1>")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  gr.Markdown(
32
+ "<p style='text-align: center;'>"
33
+ "A domain-specific language model for alpine storytelling. <br>"
34
+ "Generate climbing stories, mountain impressions, and expedition-style text."
35
  "</p>"
36
  )
37
+
38
  with gr.Row():
39
+ with gr.Column(scale=1):
40
  prompt = gr.Textbox(
41
  lines=8,
42
  label="Your alpine prompt...",
43
  placeholder="A dawn climb on the Matterhorn..."
44
  )
45
  max_tokens = gr.Slider(50, 1000, value=300, step=10, label="Max output tokens")
46
+ generate_btn = gr.Button("🚀 Generate")
47
 
48
  with gr.Column(scale=2):
49
+ output = gr.Textbox(lines=20, label="Generated Alpine Story", interactive=False)
 
50
 
51
  # Bind button click to inference
52
  generate_btn.click(
 
65
  cfg = {
66
  'cuda_id': 0,
67
  'model_type': 'transformer',
68
+ 'repo_id': "Borzyszkowski/AlpineLLM-model",
69
+ 'model_name': "best_model",
70
  'cache_dir': "./model-cache",
71
  }
72
  cfg = Config(cfg)
assets/background_round.png DELETED

Git LFS Details

  • SHA256: 51b0b57feb466d72b04b9940abae9656dc251b519c0a04b45212f8fbc74396cf
  • Pointer size: 131 Bytes
  • Size of remote file: 476 kB
style.py DELETED
@@ -1,68 +0,0 @@
1
- # =========================
2
- # CSS & UI
3
- # =========================
4
- custom_css = """
5
- body, .gradio-container { font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif; }
6
- .app-header { text-align: center; max-width: 800px; margin: 0 auto 8px !important; }
7
- .gradio-container { padding: 4px 0 !important; max-width: 1200px !important; margin: 0 auto !important; }
8
- .gradio-container [data-testid="tabs"], .gradio-container .tabs { margin-top: 0 !important; }
9
- .gradio-container [data-testid="tabitem"], .gradio-container .tabitem { padding-top: 4px !important; }
10
- .gradio-container .wrap { gap: 0 !important; }
11
- .quick-links { text-align: center; padding: 8px 0; border: 1px solid #e5e7eb; border-radius: 8px; margin: 8px auto; max-width: 800px; }
12
- .quick-links a { margin: 0 12px; font-size: 14px; font-weight: 600; color: #3b82f6; text-decoration: none; }
13
- .quick-links a:hover { text-decoration: underline; }
14
- .prompt-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
15
- .prompt-grid button { height: 40px !important; padding: 0 12px !important; border-radius: 8px !important; font-weight: 600 !important; font-size: 13px !important; letter-spacing: 0.2px; }
16
- #image_preview_vl, #image_preview_doc { height: 400px !important; overflow: auto; }
17
- #image_preview_vl img, #image_preview_doc img, #vis_image_doc img { width: 100% !important; height: auto !important; object-fit: contain !important; display: block; }
18
- #md_preview_vl, #md_preview_doc { max-height: 540px; min-height: 180px; overflow: auto; scrollbar-gutter: stable both-edges; }
19
- #md_preview_vl .prose, #md_preview_doc .prose { line-height: 1.7 !important; }
20
- #md_preview_vl .prose img, #md_preview_doc .prose img { display: block; margin: 0 auto; max-width: 100%; height: auto; }
21
- .notice { margin: 8px auto 0; max-width: 800px; padding: 10px 12px; border: 1px solid #e5e7eb; border-radius: 8px; background: #f8fafc; font-size: 14px; line-height: 1.6; }
22
- .notice strong { font-weight: 700; }
23
- .notice a { color: #3b82f6; text-decoration: none; }
24
- .notice a:hover { text-decoration: underline; }
25
-
26
- /* Dark mode styles */
27
- @media (prefers-color-scheme: dark) {
28
- body, .gradio-container {
29
- background-color: #0f1117 !important;
30
- color: #f5f5f5 !important;
31
- }
32
-
33
- .notice {
34
- background: #1e293b !important;
35
- color: #f5f5f5 !important;
36
- border: 1px solid #334155 !important;
37
- }
38
-
39
- .notice a {
40
- color: #60a5fa !important;
41
- }
42
-
43
- .quick-links {
44
- border-color: #334155 !important;
45
- }
46
-
47
- .quick-links a {
48
- color: #93c5fd !important;
49
- }
50
- }
51
-
52
- /* Hide empty Gradio auto-scroll/anchor button or padding container near Markdown blocks */
53
- button.svelte-vuh1yp,
54
- div.svelte-vuh1yp:has(button),
55
- div#component-3 > div.wrap.center.full,
56
- div[id^="component-"][class*="hide-container"] .wrap.center.full {
57
- display: none !important;
58
- }
59
-
60
- /* Prevent extra padding on Markdown containers */
61
- div[class*="block"].hide-container {
62
- padding: 0 !important;
63
- margin: 0 !important;
64
- border: none !important;
65
- overflow: visible !important;
66
- }
67
-
68
- """