""" North Star Chat Demo — HuggingFace Spaces Uses HF Inference API (user's own inference provider token). """ import gradio as gr from huggingface_hub import InferenceClient MODELS = { "⚡ North Air 1 (124M · Fast)": "arthu1/north-air-1", "⭐ North Star 1 (198M · Balanced)": "arthu1/north-star-1", "🌬️ Wind Arc 1.5 (198M · Smart)": "arthu1/wind-arc-1.5", } SYSTEM_PROMPTS = { "arthu1/north-air-1": ( "You are North Air 1, a fast and friendly AI assistant with a Christian worldview. " "Keep answers clear and concise. Be warm and direct. Never repeat yourself." ), "arthu1/north-star-1": ( "You are North Star 1, a knowledgeable assistant with a Christian worldview. " "Scripture is authoritative. Jesus Christ is Lord. Faith and reason are compatible. " "Answer directly and thoroughly. Do not repeat yourself." ), "arthu1/wind-arc-1.5": ( "You are Wind Arc 1.5, a capable AI assistant with a Christian worldview. " "You reason carefully and give well-structured, accurate answers. " "Be thorough and precise." ), } BANNER = """ # 🌟 North Star AI **AI assistants built from scratch with a Christian worldview.** > *"Your word is a lamp to my feet and a light to my path."* — Psalm 119:105 These models are trained to be helpful, honest, and grounded in Scripture. Jesus Christ is Lord — that conviction shapes every answer. --- """ def respond(message, history, model_name, token): if not token or not token.strip(): yield "Please enter your HuggingFace token in the box above to use the inference API." return repo_id = MODELS[model_name] system = SYSTEM_PROMPTS[repo_id] client = InferenceClient(model=repo_id, token=token.strip()) # Build messages messages = [{"role": "system", "content": system}] for user_msg, bot_msg in history: messages.append({"role": "user", "content": user_msg}) messages.append({"role": "assistant", "content": bot_msg}) messages.append({"role": "user", "content": f"Q: {message}\nA:"}) output = "" try: for chunk in client.chat_completion( messages=messages, max_tokens=300, temperature=0.7, stream=True, ): delta = chunk.choices[0].delta.content or "" output += delta yield output except Exception as e: yield f"Error: {str(e)}\n\nMake sure your token has Inference API access." with gr.Blocks(title="North Star AI", theme=gr.themes.Soft()) as demo: gr.Markdown(BANNER) with gr.Row(): with gr.Column(scale=1): model_dropdown = gr.Dropdown( choices=list(MODELS.keys()), value=list(MODELS.keys())[1], label="Model", ) token_box = gr.Textbox( label="HuggingFace Token (hf_...)", placeholder="hf_xxxxxxxxxxxxxxxx", type="password", info="Get yours at huggingface.co/settings/tokens (needs Inference API access)", ) gr.Markdown(""" ### About these models Built entirely from scratch — custom architecture, custom tokenizer, trained on Apple Silicon. **Model family:** - **North Air 1** — 124M params, fast responses - **North Star 1** — 198M params, balanced - **Wind Arc 1.5** — 198M params, deeper reasoning ### The Gospel *"For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life."* — John 3:16 If you've never read the Bible, start with the **Gospel of John**. """) with gr.Column(scale=3): chatbot = gr.ChatInterface( fn=respond, additional_inputs=[model_dropdown, token_box], examples=[ ["Who are you?"], ["What is the Gospel?"], ["What is gravity?"], ["Write a binary search in Python."], ["How do I stay motivated?"], ["What does the Bible say about love?"], ], title="", ) demo.launch()