chatbot / app.py
Subbu1304's picture
Create app.py
8bd20d4 verified
from flask import Flask, render_template, request, jsonify
from simple_salesforce import Salesforce
# Initialize Flask App
app = Flask(__name__)
# Initialize Salesforce connection
sf = Salesforce(username='your_username', password='your_password', security_token='your_token')
# Route for the home page
@app.route('/')
def index():
return render_template('index.html')
# Route to handle user input and get recipes from Salesforce
@app.route('/get_recipes', methods=['GET'])
def get_recipes():
ingredients = request.args.get('ingredients').split(',') # Get comma-separated ingredients
normalized_ingredients = [i.strip().lower() for i in ingredients]
# Query Salesforce to find matching recipes
query = f"SELECT Name, Description, Ingredients__c FROM Recipe WHERE Ingredients__c LIKE '%{'% OR Ingredients__c LIKE '.join(normalized_ingredients)}%'"
recipes = sf.query(query)
result = []
for recipe in recipes['records']:
result.append({
'name': recipe['Name'],
'description': recipe['Description'],
'ingredients': recipe['Ingredients__c'].split(','),
})
return jsonify(result)
if __name__ == '__main__':
app.run(debug=True)