File size: 1,909 Bytes
64e7c03
 
 
 
 
 
 
 
 
191db0a
64e7c03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191db0a
 
 
 
 
 
 
 
64e7c03
 
 
191db0a
 
64e7c03
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
from flask import Flask, request, jsonify
from transformers import pipeline
from simple_salesforce import Salesforce

app = Flask(__name__)

# Load the Hugging Face model for Question Answering (FAQ-based)
faq_model = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")

# Salesforce connection (replace with your credentials)
sf = Salesforce(username='your_username', password='your_password', security_token='your_security_token')

# Function to get the answer from the model
def get_answer(question, context):
    result = faq_model(question=question, context=context)
    return result['answer']

# Function to create a case in Salesforce if the chatbot requires more assistance
def create_case(subject, description):
    case = sf.Case.create({
        'Subject': subject,
        'Description': description,
        'Status': 'New',
        'Priority': 'Medium'
    })
    return case

# Route to handle the user’s question
@app.route('/ask', methods=['POST'])
def ask_question():
    data = request.get_json()
    question = data.get('question')

    # Define the FAQ context (static or dynamic data can be used here)
    faq_context = """
    Here are some frequently asked questions and answers about our services.
    1. How do I contact customer support? - You can email us at support@company.com.
    2. What are your business hours? - We are open from 9 AM to 6 PM, Monday to Friday.
    3. How do I reset my password? - Click on 'Forgot Password' on the login page.
    """
    
    # Get the answer to the question
    answer = get_answer(question, faq_context)

    # If the answer suggests further help, create a case in Salesforce
    if "contact us" in answer or "need help" in answer:
        create_case('Customer Support Needed', answer)

    return jsonify({"answer": answer})

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=5000)