Spaces:
Sleeping
Sleeping
Ajit Panday
commited on
Commit
·
d538a8c
1
Parent(s):
3559931
Initial commit: Customer Support Chatbot with DialoGPT-medium
Browse files- .gitignore +11 -0
- README.md +54 -0
- app.py +69 -0
- requirements.txt +4 -0
.gitignore
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.py[cod]
|
| 3 |
+
*$py.class
|
| 4 |
+
.env
|
| 5 |
+
.venv
|
| 6 |
+
env/
|
| 7 |
+
venv/
|
| 8 |
+
ENV/
|
| 9 |
+
.idea/
|
| 10 |
+
.vscode/
|
| 11 |
+
*.log
|
README.md
CHANGED
|
@@ -12,3 +12,57 @@ short_description: AiAssistant
|
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 15 |
+
|
| 16 |
+
# Customer Support Chatbot
|
| 17 |
+
|
| 18 |
+
A beautiful chatbot built using DialoGPT-medium and the Victorano/customer-support-1k dataset. The chatbot features a clean and modern Gradio interface with conversation history support.
|
| 19 |
+
|
| 20 |
+
## Features
|
| 21 |
+
|
| 22 |
+
- Powered by DialoGPT-medium model
|
| 23 |
+
- Clean and modern Gradio interface
|
| 24 |
+
- Conversation history within the same session
|
| 25 |
+
- Copy button for messages
|
| 26 |
+
- Bot avatar using DiceBear API
|
| 27 |
+
- Responsive design
|
| 28 |
+
|
| 29 |
+
## Setup
|
| 30 |
+
|
| 31 |
+
1. Install the required dependencies:
|
| 32 |
+
```bash
|
| 33 |
+
pip install -r requirements.txt
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
2. Run the application:
|
| 37 |
+
```bash
|
| 38 |
+
python app.py
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
## Deployment on Hugging Face Spaces
|
| 42 |
+
|
| 43 |
+
1. Create a new Space on Hugging Face
|
| 44 |
+
2. Choose "Gradio" as the SDK
|
| 45 |
+
3. Upload these files to your Space:
|
| 46 |
+
- app.py
|
| 47 |
+
- requirements.txt
|
| 48 |
+
- README.md
|
| 49 |
+
|
| 50 |
+
The Space will automatically build and deploy your chatbot.
|
| 51 |
+
|
| 52 |
+
## Usage
|
| 53 |
+
|
| 54 |
+
1. Type your message in the text input box
|
| 55 |
+
2. Press Enter or click the Send button
|
| 56 |
+
3. The chatbot will generate a response based on your input
|
| 57 |
+
4. The conversation history will be maintained in the chat window
|
| 58 |
+
5. You can copy any message using the copy button that appears on hover
|
| 59 |
+
|
| 60 |
+
## Model Details
|
| 61 |
+
|
| 62 |
+
- Model: microsoft/DialoGPT-medium
|
| 63 |
+
- Dataset: Victorano/customer-support-1k
|
| 64 |
+
- Generation Parameters:
|
| 65 |
+
- max_length: 1000
|
| 66 |
+
- temperature: 0.7
|
| 67 |
+
- top_k: 50
|
| 68 |
+
- top_p: 0.9
|
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
from datasets import load_dataset
|
| 5 |
+
import random
|
| 6 |
+
|
| 7 |
+
# Load the model and tokenizer
|
| 8 |
+
model_name = "microsoft/DialoGPT-medium"
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 11 |
+
|
| 12 |
+
# Load the customer support dataset
|
| 13 |
+
dataset = load_dataset("Victorano/customer-support-1k")
|
| 14 |
+
|
| 15 |
+
def generate_response(message, history):
|
| 16 |
+
# Encode the user message
|
| 17 |
+
input_ids = tokenizer.encode(message + tokenizer.eos_token, return_tensors='pt')
|
| 18 |
+
|
| 19 |
+
# Generate response
|
| 20 |
+
with torch.no_grad():
|
| 21 |
+
output_ids = model.generate(
|
| 22 |
+
input_ids,
|
| 23 |
+
max_length=1000,
|
| 24 |
+
num_return_sequences=1,
|
| 25 |
+
no_repeat_ngram_size=2,
|
| 26 |
+
temperature=0.7,
|
| 27 |
+
top_k=50,
|
| 28 |
+
top_p=0.9,
|
| 29 |
+
pad_token_id=tokenizer.eos_token_id
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Decode and return the response
|
| 33 |
+
response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 34 |
+
return response
|
| 35 |
+
|
| 36 |
+
# Create the Gradio interface
|
| 37 |
+
with gr.Blocks(css="footer {display: none !important}") as demo:
|
| 38 |
+
gr.Markdown("""
|
| 39 |
+
# 🤖 Customer Support Chatbot
|
| 40 |
+
This chatbot is powered by DialoGPT-medium and trained on customer support conversations.
|
| 41 |
+
""")
|
| 42 |
+
|
| 43 |
+
chatbot = gr.Chatbot(
|
| 44 |
+
[],
|
| 45 |
+
elem_id="chatbot",
|
| 46 |
+
bubble_full_width=False,
|
| 47 |
+
avatar_images=(None, "https://api.dicebear.com/7.x/bottts/svg?seed=1"),
|
| 48 |
+
height=500,
|
| 49 |
+
show_copy_button=True,
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
with gr.Row():
|
| 53 |
+
txt = gr.Textbox(
|
| 54 |
+
show_label=False,
|
| 55 |
+
placeholder="Type your message here...",
|
| 56 |
+
container=False
|
| 57 |
+
)
|
| 58 |
+
submit_btn = gr.Button("Send", variant="primary")
|
| 59 |
+
|
| 60 |
+
# Handle user input and generate response
|
| 61 |
+
def user_input(message, history):
|
| 62 |
+
return "", history + [[message, generate_response(message, history)]]
|
| 63 |
+
|
| 64 |
+
# Connect the interface components
|
| 65 |
+
txt.submit(user_input, [txt, chatbot], [txt, chatbot])
|
| 66 |
+
submit_btn.click(user_input, [txt, chatbot], [txt, chatbot])
|
| 67 |
+
|
| 68 |
+
if __name__ == "__main__":
|
| 69 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.19.2
|
| 2 |
+
transformers==4.37.2
|
| 3 |
+
torch==2.2.0
|
| 4 |
+
datasets==2.17.1
|