Spaces:
Runtime error
Runtime error
Download main.py from hamzacodesnow989/chatbot: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/hamzacodesnow989/chatbot/resolve/main/main.py
- Command line
-
hf download hf://spaces/hamzacodesnow989/chatbot/main.py
-
curl -L -o main.py https://huggingface.co/spaces/hamzacodesnow989/chatbot/resolve/main/main.py
1.26 kB
| # 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) | |