Spaces:
Build error
Build error
File size: 1,800 Bytes
86697d9 6143d33 86697d9 6143d33 86697d9 6143d33 86697d9 6143d33 86697d9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 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() |