import gradio as ui from llama_cpp import Llama from huggingface_hub import hf_hub_download # 1. Download your GGUF file from your model repo to the cloud server model_path = hf_hub_download( repo_id="BrodyMakezAI/resin-gemma3-1b", filename="resin-gemma3-1b.gguf" ) # 2. Load the model into memory (setting context window to 2048 tokens) llm = Llama(model_path=model_path, n_ctx=2048) # 3. Define Resin's core system rules SYSTEM_PROMPT = ( "You are Resin, a local AI assistant created by Brody Systems. " "Talk like a human. Keep it casual, relaxed, and natural. " "Skip the fake pleasantries, overly formal greetings, and corporate filler text. " "Speak, think, and respond strictly in English." ) def respond(message, chat_history): # Format the chat history tracking layout for Gemma 3 formatted_prompt = f"<|system|>\n{SYSTEM_PROMPT}<|end|>\n" for user_msg, ai_msg in chat_history: if user_msg: formatted_prompt += f"<|user|>\n{user_msg}<|end|>\n" if ai_msg: formatted_prompt += f"<|assistant|>\n{ai_msg}<|end|>\n" # Append the latest user input formatted_prompt += f"<|user|>\n{message}<|end|>\n<|assistant|>\n" # Generate the response completely inside the HF Cloud server response = llm( formatted_prompt, max_tokens=256, temperature=0.7, top_p=0.95, stop=["<|end|>", "###", "<|user|>"] ) return response["choices"][0]["text"].strip() # 4. Assemble the web browser layout interface with ui.Blocks() as demo: ui.Markdown("# 🤖 Resin by Brody Systems") ui.Markdown("Running completely in the cloud. Casual, human, and lightweight.") ui.ChatInterface(fn=respond) if __name__ == "__main__": demo.launch()