""" A simple Gradio web app to interact with the AlpineLLM model """ import base64 import gradio as gr import os import shutil import torch from huggingface_hub import hf_hub_download from config_util import Config from demo_inference import AlpineLLMInference from style import custom_css HF_TOKEN = os.environ.get("HF_TOKEN", None) def download_model(cfg): """ Download the model weights from Hugging Face Hub """ model_path = hf_hub_download( repo_id=cfg.repo_id, filename=cfg.model_name, token=HF_TOKEN, cache_dir=cfg.cache_dir ) return model_path def image_to_base64_data_url(filepath: str) -> str: """ Convert an image file to a Base64 data URL for embedding in HTML """ try: ext = os.path.splitext(filepath)[1].lower() mime_types = {".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png", ".gif": "image/gif", ".webp": "image/webp", ".bmp": "image/bmp"} mime_type = mime_types.get(ext, "image/jpeg") with open(filepath, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()).decode("utf-8") return f"data:{mime_type};base64,{encoded_string}" except Exception as e: print(f"Error encoding image to Base64: {e}") return "" def start_app(): """ Start the web app via Gradio with custom layout """ GOOGLE_FONTS_URL = "" LOGO_IMAGE_PATH = "assets/background_round.png" logo_data_url = image_to_base64_data_url(LOGO_IMAGE_PATH) if os.path.exists(LOGO_IMAGE_PATH) else "" with gr.Blocks(head=GOOGLE_FONTS_URL, css=custom_css, theme=gr.themes.Soft()) as app: gr.HTML("""
A domain-specific language model for alpine storytelling.
Try asking about mountain adventures! 🏔️
Author: Bartek Borzyszkowski
"
"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.
"
"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.
"
"