# tinyllama_gradio_prompt.py import gradio as gr from llama_cpp import Llama # Path to your GGUF model MODEL_PATH = "TinyLlama-1.1B-Chat-v1.0-Q4_K_M.gguf" # Load the model (CPU) model = Llama(model_path=MODEL_PATH) # Define a system prompt for better behavior SYSTEM_PROMPT = """ You are a helpful coding assistant and Linux command assistant. Answer clearly and concisely. Provide code examples in Python or commands in Linux terminal as requested. Format code using markdown triple backticks. Explain steps when necessary. Do not provide unnecessary text. """ def chat_with_model(user_input): if not user_input.strip(): return "Please type something." # Combine system prompt with user input prompt = SYSTEM_PROMPT + f"\nUser: {user_input}\nAssistant:" # Generate response response = model(prompt, max_tokens=200) return response['choices'][0]['text'].strip() # Create Gradio interface iface = gr.Interface( fn=chat_with_model, inputs=gr.Textbox(lines=21,placeholder="Type your message here..."), outputs=gr.Textbox(lines=21), title="TinyLlama Chat with Prompt", description="Chat with TinyLlama 1.1B (CPU, GGUF) with system prompt" ) # Launch the dashboard iface.launch(share=True)