File size: 1,106 Bytes
54229c5
 
 
 
 
 
 
 
 
 
 
 
 
 
b73c443
54229c5
 
 
 
 
 
 
18780e7
b73c443
 
 
 
 
18780e7
 
b73c443
 
 
 
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
import streamlit as st
from huggingface_hub import hf_hub_download
from llama_cpp import Llama

# Hugging Face model repo details
HF_MODEL_REPO = "anush76/unsloth-model"
MODEL_FILENAME = "unsloth.Q4_K_M.gguf"

# Download model from Hugging Face Hub
st.sidebar.write("πŸ“₯ Downloading model from Hugging Face...")
model_path = hf_hub_download(repo_id=HF_MODEL_REPO, filename=MODEL_FILENAME)

# Load the model with llama-cpp-python
st.sidebar.write("πŸ”„ Loading model...")
llm = Llama(model_path=model_path, n_threads=8, n_batch=512, n_gpu_layers=20)

# Streamlit UI
st.title("πŸ¦₯ Unsloth Chatbot")
st.write("πŸ’¬ Ask me anything!")

user_input = st.text_input("You:")
if user_input:
    response = llm.create_completion(
        prompt=f"Answer in a clear paragraph format:\n\n{user_input}",
        max_tokens=300,  # Ensures a complete response
        temperature=0.6,  
        top_p=0.9,
        stream=False  # Disables word-by-word output
    )

    full_response = response["choices"][0]["text"].strip()
    
    # Format response into a paragraph
    st.write("πŸ€– Chatbot:\n\n", full_response)