| import gradio as gr |
| from llama_cpp import Llama |
|
|
| |
| print("Loading model... Please wait, isme 1-2 minute lag sakte hain.") |
| llm = Llama.from_pretrained( |
| repo_id="mradermacher/Qwable-9B-Claude-Fable-5-i1-GGUF", |
| filename="Qwable-9B-Claude-Fable-5.i1-IQ1_S.gguf", |
| n_ctx=2048, |
| n_threads=4, |
| ) |
| print("Model loaded successfully!") |
|
|
| |
| def predict(message, history): |
| |
| prompt = "<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n" |
| |
| for user_msg, bot_msg in history: |
| prompt += f"<|im_start|>user\n{user_msg}<|im_end|>\n<|im_start|>assistant\n{bot_msg}<|im_end|>\n" |
| |
| prompt += f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n" |
| |
| |
| output = llm( |
| prompt, |
| max_tokens=512, |
| stop=["<|im_end|>", "<|im_start|>"], |
| echo=False |
| ) |
| |
| return output['choices'][0]['text'] |
|
|
| |
| demo = gr.ChatInterface( |
| fn=predict, |
| title="Qwable 9B Claude Fable 5 (GGUF CPU)", |
| description="Running heavily quantized 9B model on Hugging Face Free CPU Space." |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch(server_name="0.0.0.0", server_port=7860) |