akiko19191 commited on
Commit
953b8ab
·
verified ·
1 Parent(s): fdebd9e

Upload folder using huggingface_hub

Browse files
app/__pycache__/api.cpython-311.pyc CHANGED
Binary files a/app/__pycache__/api.cpython-311.pyc and b/app/__pycache__/api.cpython-311.pyc differ
 
app/__pycache__/config.cpython-311.pyc CHANGED
Binary files a/app/__pycache__/config.cpython-311.pyc and b/app/__pycache__/config.cpython-311.pyc differ
 
app/__pycache__/email_utils.cpython-311.pyc CHANGED
Binary files a/app/__pycache__/email_utils.cpython-311.pyc and b/app/__pycache__/email_utils.cpython-311.pyc differ
 
app/__pycache__/xero_utils.cpython-311.pyc CHANGED
Binary files a/app/__pycache__/xero_utils.cpython-311.pyc and b/app/__pycache__/xero_utils.cpython-311.pyc differ
 
app/api.py CHANGED
@@ -28,7 +28,7 @@ add_items_to_cart_function = {
28
  "description": "Extracts order details from a user's message to add products to their shopping cart. Can also set a delivery date.",
29
  "parameters": {
30
  "type": "object", "properties": {
31
- "items": { "type": "array", "description": "A list of items to add to the cart.", "items": { "type": "object", "properties": { "product_name": { "type": "string", "description": "The name of the product. This must match one of the available product names.", }, "quantity": { "type": "number", "description": "The quantity of the product.", }, "unit": { "type": "string", "description": "The unit of measure for the quantity (e.g., 'kg', 'pieces', 'box', 'bunch'). This must match one of the available units for the product.", }, }, "required": ["product_name", "quantity", "unit"], }, },
32
  # --- START NEW PARAMETER ---
33
  "delivery_date": {
34
  "type": "string",
@@ -585,7 +585,7 @@ DEFAULT_ABOUT_DATA = {
585
 
586
  DEFAULT_CONTACT_DATA = {
587
  "_id": "contact",
588
- "title": "Customer Care",
589
  "intro": "We're here to help! Reach out to us through any of the channels below. We aim to respond to all inquiries within 24 business hours.",
590
  "details": [
591
  {"type": "Phone Support", "value": "+1 (800) 123-4567"},
 
28
  "description": "Extracts order details from a user's message to add products to their shopping cart. Can also set a delivery date.",
29
  "parameters": {
30
  "type": "object", "properties": {
31
+ "items": { "type": "array", "description": "A list of items to add to the cart.", "items": { "type": "object", "properties": { "product_name": { "type": "string", "description": "The name of the product. This must match one of the available product names.", }, "quantity": { "type": "number", "description": "The quantity of the product.", }, "unit": { "type": "string", "description": "The unit of measure for the quantity (e.g., 'lb', 'pieces', 'box', 'bunch'). This must match one of the available units for the product.", }, }, "required": ["product_name", "quantity", "unit"], }, },
32
  # --- START NEW PARAMETER ---
33
  "delivery_date": {
34
  "type": "string",
 
585
 
586
  DEFAULT_CONTACT_DATA = {
587
  "_id": "contact",
588
+ "title": "Contact Us",
589
  "intro": "We're here to help! Reach out to us through any of the channels below. We aim to respond to all inquiries within 24 business hours.",
590
  "details": [
591
  {"type": "Phone Support", "value": "+1 (800) 123-4567"},
app/email_utils.py CHANGED
@@ -30,7 +30,7 @@ def send_order_confirmation_email(order, user):
30
  items_html = "<table border='1' cellpadding='5' cellspacing='0' style='border-collapse: collapse; width: 100%;'><tr><th style='text-align: left;'>Product</th><th style='text-align: center;'>Quantity</th></tr>"
31
  for item in order['populated_items']:
32
  if item['mode'] == 'weight':
33
- item['mode']='kg'
34
  items_html += f"<tr><td>{item['name']}</td><td style='text-align: center;'>{item['quantity']} {item['mode']}</td></tr>"
35
  items_html += "</table>"
36
 
 
30
  items_html = "<table border='1' cellpadding='5' cellspacing='0' style='border-collapse: collapse; width: 100%;'><tr><th style='text-align: left;'>Product</th><th style='text-align: center;'>Quantity</th></tr>"
31
  for item in order['populated_items']:
32
  if item['mode'] == 'weight':
33
+ item['mode']='lb'
34
  items_html += f"<tr><td>{item['name']}</td><td style='text-align: center;'>{item['quantity']} {item['mode']}</td></tr>"
35
  items_html += "</table>"
36
 
app/xero_utils.py CHANGED
@@ -81,22 +81,33 @@ def create_xero_contact_async(app_context, registration_data):
81
 
82
  # Prepare the detailed notes for the history record
83
  history_details = (
84
- f"--- Client Application Details ---\n"
85
- f"Business Type: {registration_data.get('businessType')}\n"
86
- f"Years Operating: {registration_data.get('yearsOperating')}\n"
87
- f"Number of Locations: {registration_data.get('numLocations')}\n"
88
- f"Estimated Weekly Volume: {registration_data.get('estimatedVolume')}\n\n"
89
- f"--- Logistics Information ---\n"
90
- f"Preferred Delivery Times: {registration_data.get('preferredDeliveryTimes')}\n"
91
- f"Has Loading Dock: {registration_data.get('hasLoadingDock')}\n"
92
- f"Special Delivery Instructions: {registration_data.get('specialDeliveryInstructions')}\n\n"
93
- f"--- Service & Billing ---\n"
94
- f"Reason for Switching: {registration_data.get('reasonForSwitch')}\n"
95
- f"Supplier Priorities: {registration_data.get('priorities')}\n"
96
- f"Preferred Payment Method: {registration_data.get('paymentMethod')}\n\n"
97
- f"--- Additional Notes ---\n"
98
- f"{registration_data.get('additionalNotes')}"
 
 
 
 
 
 
 
 
 
99
  )
 
 
100
 
101
  # Create the HistoryRecord payload
102
  history_record = HistoryRecord(details=history_details)
 
81
 
82
  # Prepare the detailed notes for the history record
83
  history_details = (
84
+ f"--- Client Application Details ---\n"
85
+ f"Business Name: {registration_data.get('businessName')}\n"
86
+ f"Contact Person: {registration_data.get('contactPerson')}\n"
87
+ f"Email: {registration_data.get('email')}\n"
88
+ f"Phone: {registration_data.get('phoneNumber')}\n"
89
+ f"Company Website: {registration_data.get('companyWebsite')}\n"
90
+ f"Business Address: {registration_data.get('businessAddress')}\n"
91
+ f"Business Type: {registration_data.get('businessType')}\n"
92
+ f"Years Operating: {registration_data.get('yearsOperating')}\n"
93
+ f"Number of Locations: {registration_data.get('numLocations')}\n"
94
+ f"Estimated Weekly Volume: {registration_data.get('estimatedVolume')}\n\n"
95
+
96
+ f"--- Logistics Information ---\n"
97
+ f"Preferred Delivery Times: {registration_data.get('preferredDeliveryTimes')}\n"
98
+ f"Has Loading Dock: {registration_data.get('hasLoadingDock')}\n"
99
+ f"Special Delivery Instructions: {registration_data.get('specialDeliveryInstructions')}\n"
100
+ f"Minimum Quantity Requirements: {registration_data.get('minQuantityRequirements')}\n\n"
101
+
102
+ f"--- Service & Billing ---\n"
103
+ f"Reason for Switching: {registration_data.get('reasonForSwitch')}\n"
104
+ f"Preferred Payment Method: {registration_data.get('paymentMethod')}\n\n"
105
+
106
+ f"--- Additional Notes ---\n"
107
+ f"{registration_data.get('additionalNotes')}"
108
  )
109
+ #f"Supplier Priorities: {registration_data.get('priorities')}\n"
110
+
111
 
112
  # Create the HistoryRecord payload
113
  history_record = HistoryRecord(details=history_details)
twillio_gemini_api.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import os
4
+ from flask import Flask, request
5
+ from dotenv import load_dotenv
6
+ import google.generativeai as genai
7
+ from twilio.twiml.messaging_response import MessagingResponse
8
+
9
+ # Load environment variables from .env file
10
+ load_dotenv()
11
+
12
+ # --- Initialize Flask App and APIs ---
13
+ app = Flask(__name__)
14
+
15
+ # Configure the Gemini API
16
+ try:
17
+ genai.configure(api_key=os.environ.get("GEMINI_API_KEY"))
18
+ # Initialize the Gemini-1.5-Pro model
19
+ # Use 'gemini-1.5-pro-latest' for the most recent version
20
+ model = genai.GenerativeModel('gemini-1.5-pro-latest')
21
+ print("Gemini model initialized successfully.")
22
+ except Exception as e:
23
+ print(f"Error initializing Gemini model: {e}")
24
+ model = None
25
+
26
+ # --- Define the Webhook Endpoint ---
27
+ @app.route("/sms", methods=['POST'])
28
+ def sms_reply():
29
+ """Respond to incoming messages with a Gemini-generated response."""
30
+
31
+ # Get the message body from the incoming Twilio request
32
+ incoming_msg = request.values.get('Body', '').strip()
33
+ print(f"Received message: '{incoming_msg}'")
34
+
35
+ # Start the TwiML response
36
+ twilio_resp = MessagingResponse()
37
+
38
+ if not model:
39
+ twilio_resp.message("The AI model is not configured correctly. Please check the server logs.")
40
+ return str(twilio_resp)
41
+
42
+ if not incoming_msg:
43
+ twilio_resp.message("Please send a message to get a response.")
44
+ return str(twilio_resp)
45
+
46
+ try:
47
+ # Send the message to Gemini API and get the response
48
+ print("Sending message to Gemini...")
49
+ gemini_response = model.generate_content(incoming_msg)
50
+
51
+ # Extract the text part of the response
52
+ ai_answer = gemini_response.text
53
+ print(f"Gemini response: '{ai_answer}'")
54
+
55
+ # Add the Gemini response to the TwiML message
56
+ twilio_resp.message(ai_answer)
57
+
58
+ except Exception as e:
59
+ print(f"An error occurred with the Gemini API: {e}")
60
+ # Send a user-friendly error message
61
+ error_message = "Sorry, I'm having trouble connecting to my brain right now. Please try again later."
62
+ twilio_resp.message(error_message)
63
+
64
+ # Return the TwiML response as a string
65
+ return str(twilio_resp)
66
+
67
+
68
+ # --- Run the Flask App ---
69
+ if __name__ == "__main__":
70
+ # The debug=True option is for development only.
71
+ # In production, use a proper WSGI server like Gunicorn or Waitress.
72
+ app.run(debug=True, port=5000)