Spaces:
Sleeping
Sleeping
Deploy Buildsnpper chatbot Gradio interface
Browse files- Add Gradio chat interface for Buildsnpper platform
- Uses bricksandbotltd/buildsnpper-chatbot-Q4_K_M model
- Includes 8 example questions
- Supports conversation history
- Clean, simple UI for customer support
- README.md +36 -6
- app.py +108 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,13 +1,43 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Buildsnpper Chatbot
|
| 3 |
+
emoji: 🏗️
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# Buildsnpper SAP Assessor Platform Chatbot
|
| 14 |
+
|
| 15 |
+
A specialized chatbot for answering questions about the Buildsnpper SAP Assessor Platform.
|
| 16 |
+
|
| 17 |
+
## Model
|
| 18 |
+
|
| 19 |
+
This Space uses the fine-tuned Phi-4-mini-instruct model:
|
| 20 |
+
- **Model**: [bricksandbotltd/buildsnpper-chatbot-Q4_K_M](https://huggingface.co/bricksandbotltd/buildsnpper-chatbot-Q4_K_M)
|
| 21 |
+
- **Base**: microsoft/Phi-4-mini-instruct (3.8B parameters)
|
| 22 |
+
- **Format**: GGUF Q4_K_M quantized (~2.5GB)
|
| 23 |
+
- **Training**: LoRA fine-tuning on 89 Buildsnpper Q&A pairs
|
| 24 |
+
|
| 25 |
+
## Features
|
| 26 |
+
|
| 27 |
+
Ask questions about:
|
| 28 |
+
- Project and client management
|
| 29 |
+
- Subscriptions and credits
|
| 30 |
+
- Platform features and navigation
|
| 31 |
+
- Account management
|
| 32 |
+
- Common technical issues
|
| 33 |
+
- Report generation and exports
|
| 34 |
+
|
| 35 |
+
## Limitations
|
| 36 |
+
|
| 37 |
+
- Specialized for Buildsnpper platform questions only
|
| 38 |
+
- Not suitable for general conversation or off-topic queries
|
| 39 |
+
- Designed for customer support use cases
|
| 40 |
+
|
| 41 |
+
## License
|
| 42 |
+
|
| 43 |
+
MIT License
|
app.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Gradio interface for Buildsnpper Chatbot.
|
| 4 |
+
Deployed as a HuggingFace Space.
|
| 5 |
+
"""
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from llama_cpp import Llama
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
# Configuration
|
| 11 |
+
MODEL_REPO = "bricksandbotltd/buildsnpper-chatbot-Q4_K_M"
|
| 12 |
+
MODEL_FILE = "buildsnpper-chatbot-Q4_K_M.gguf"
|
| 13 |
+
|
| 14 |
+
# Initialize model (loaded once at startup)
|
| 15 |
+
print("Loading model...")
|
| 16 |
+
llm = Llama.from_pretrained(
|
| 17 |
+
repo_id=MODEL_REPO,
|
| 18 |
+
filename=MODEL_FILE,
|
| 19 |
+
n_ctx=2048, # Context window
|
| 20 |
+
n_threads=4, # CPU threads
|
| 21 |
+
verbose=False
|
| 22 |
+
)
|
| 23 |
+
print("Model loaded successfully!")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def chat(message, history):
|
| 27 |
+
"""
|
| 28 |
+
Process user message and generate response.
|
| 29 |
+
|
| 30 |
+
Args:
|
| 31 |
+
message: User's input message
|
| 32 |
+
history: List of [user_msg, bot_msg] pairs
|
| 33 |
+
|
| 34 |
+
Returns:
|
| 35 |
+
str: Bot's response
|
| 36 |
+
"""
|
| 37 |
+
# Build conversation history
|
| 38 |
+
messages = []
|
| 39 |
+
for user_msg, bot_msg in history:
|
| 40 |
+
messages.append({"role": "user", "content": user_msg})
|
| 41 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
| 42 |
+
|
| 43 |
+
# Add current message
|
| 44 |
+
messages.append({"role": "user", "content": message})
|
| 45 |
+
|
| 46 |
+
# Generate response
|
| 47 |
+
response = llm.create_chat_completion(
|
| 48 |
+
messages=messages,
|
| 49 |
+
temperature=0.1,
|
| 50 |
+
top_p=0.9,
|
| 51 |
+
max_tokens=300,
|
| 52 |
+
stop=["<|endoftext|>", "<|end|>"]
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
return response['choices'][0]['message']['content']
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# Example questions
|
| 59 |
+
examples = [
|
| 60 |
+
"How do I create a new project in Buildsnpper?",
|
| 61 |
+
"Can I transfer credits between clients?",
|
| 62 |
+
"How much do credits cost?",
|
| 63 |
+
"What happens when a client's subscription expires?",
|
| 64 |
+
"How do I assign a subscription to a client?",
|
| 65 |
+
"I forgot my password. How can I reset it?",
|
| 66 |
+
"How do I download reports?",
|
| 67 |
+
"Can multiple people work on the same project?",
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
# Create Gradio interface
|
| 71 |
+
with gr.Blocks(title="Buildsnpper Chatbot", theme=gr.themes.Soft()) as demo:
|
| 72 |
+
gr.Markdown(
|
| 73 |
+
"""
|
| 74 |
+
# Buildsnpper SAP Assessor Platform Chatbot
|
| 75 |
+
|
| 76 |
+
Ask questions about the Buildsnpper platform, including:
|
| 77 |
+
- Project and client management
|
| 78 |
+
- Subscriptions and credits
|
| 79 |
+
- Platform features and navigation
|
| 80 |
+
- Account management
|
| 81 |
+
- Technical issues
|
| 82 |
+
|
| 83 |
+
**Note**: This chatbot is specialized for Buildsnpper platform questions only.
|
| 84 |
+
"""
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
chatbot = gr.ChatInterface(
|
| 88 |
+
fn=chat,
|
| 89 |
+
examples=examples,
|
| 90 |
+
title="",
|
| 91 |
+
description="",
|
| 92 |
+
retry_btn=None,
|
| 93 |
+
undo_btn=None,
|
| 94 |
+
clear_btn="Clear Chat",
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
gr.Markdown(
|
| 98 |
+
"""
|
| 99 |
+
---
|
| 100 |
+
**Model**: [bricksandbotltd/buildsnpper-chatbot-Q4_K_M](https://huggingface.co/bricksandbotltd/buildsnpper-chatbot-Q4_K_M)
|
| 101 |
+
**Base Model**: microsoft/Phi-4-mini-instruct (3.8B parameters)
|
| 102 |
+
**Fine-tuned**: LoRA on 89 Buildsnpper Q&A pairs
|
| 103 |
+
**Format**: GGUF Q4_K_M quantized
|
| 104 |
+
"""
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
if __name__ == "__main__":
|
| 108 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|
| 2 |
+
llama-cpp-python>=0.2.0
|
| 3 |
+
huggingface-hub>=0.20.0
|