Spaces:
Runtime error

File size: 1,258 Bytes
8a822ef
2e19777
8a822ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e19777
 
 
8a822ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e19777
8a822ef
 
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
# 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)