Download app.py from moheith/Yulya: direct link, hf CLI and curl.
- Browser
- Download file 1.74 kB
-
https://huggingface.co/spaces/moheith/Yulya/resolve/main/app.py
- Command line
-
hf download hf://spaces/moheith/Yulya/app.py
-
curl -L -o app.py https://huggingface.co/spaces/moheith/Yulya/resolve/main/app.py
1.74 kB
| import chainlit as cl | |
| from llama_cpp import Llama | |
| # Load the highly compressed 1.5B Qwen model | |
| model_filename = "little_yulya.gguf" | |
| print("Loading Yulya into memory...") | |
| llm = Llama( | |
| model_path=model_filename, | |
| n_ctx=2048, | |
| verbose=False | |
| ) | |
| print("Brain loaded successfully!") | |
| async def start(): | |
| await cl.Message(content="Hello! I am Yulya. [Pose: Smug] Try not to ask stupid questions.").send() | |
| # Initialize the history array for the user session | |
| cl.user_session.set("history", []) | |
| async def main(message: cl.Message): | |
| history = cl.user_session.get("history") | |
| # Format the prompt using Qwen's ChatML format | |
| prompt = "<|im_start|>system\nYou are Yulya, a smug, tsundere AI coding assistant.<|im_end|>\n" | |
| # Add history | |
| for user_msg, ai_msg in history: | |
| prompt += f"<|im_start|>user\n{user_msg}<|im_end|>\n" | |
| prompt += f"<|im_start|>assistant\n{ai_msg}<|im_end|>\n" | |
| # Add new user message | |
| prompt += f"<|im_start|>user\n{message.content}<|im_end|>\n<|im_start|>assistant\n" | |
| # Send a "typing..." indicator to the UI | |
| msg = cl.Message(content="") | |
| await msg.send() | |
| # Generate the response via Llama CPP | |
| response = llm( | |
| prompt, | |
| max_tokens=256, | |
| stop=["<|im_end|>", "<|im_start|>"], | |
| echo=False | |
| ) | |
| bot_reply = response['choices'][0]['text'].strip() | |
| # Update history (keep last 5 interactions to save context) | |
| history.append((message.content, bot_reply)) | |
| if len(history) > 5: | |
| history.pop(0) | |
| cl.user_session.set("history", history) | |
| # Send the final response to the UI | |
| msg.content = bot_reply | |
| await msg.update() | |