Update app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ INTENT_EXAMPLES = {
|
|
| 31 |
"complaint": ["sad", "problem", "issue", "complaint", "shikayat", "not working", "late"],
|
| 32 |
"order_status": ["order status", "track order", "mera order", "delivery"],
|
| 33 |
"refund": ["refund", "paise wapas", "return", "cancel order"],
|
| 34 |
-
"contact": ["contact number", "phone number", "customer support", "call"],
|
| 35 |
"portfolio": ["portfolio", "sample", "example", "kaam dikhao", "gallery"],
|
| 36 |
"general": []
|
| 37 |
}
|
|
@@ -55,7 +55,7 @@ def classify_intent_sbert(text):
|
|
| 55 |
OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
|
| 56 |
MODEL = "google/gemini-2.0-flash-lite-preview-02-05" # free
|
| 57 |
|
| 58 |
-
SYSTEM_PROMPT =
|
| 59 |
|
| 60 |
Services offered:
|
| 61 |
- High-end product photography (jewelry, cars, luxury goods)
|
|
@@ -106,7 +106,7 @@ def call_openrouter(prompt):
|
|
| 106 |
print(f"OpenRouter error: {e}")
|
| 107 |
return None
|
| 108 |
|
| 109 |
-
# ---------- Smart Fallback (
|
| 110 |
def fallback_response(prompt, intent):
|
| 111 |
p = prompt.lower()
|
| 112 |
if intent == "greeting":
|
|
@@ -124,6 +124,14 @@ def fallback_response(prompt, intent):
|
|
| 124 |
else:
|
| 125 |
return "- Main aapki kaise madad kar sakta hoon?\n- Humari services:\n • Product photography\n • Architecture renders\n • Corporate videos\n • Drone cinematography"
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
# ---------- Firebase Helpers ----------
|
| 128 |
def save_message(session_id, role, content, intent=None):
|
| 129 |
messages_ref = ref.child(f"chats/{session_id}/messages")
|
|
@@ -149,8 +157,7 @@ def chat():
|
|
| 149 |
intent = classify_intent_sbert(user_message)
|
| 150 |
print(f"🎯 Intent: {intent}")
|
| 151 |
|
| 152 |
-
#
|
| 153 |
-
# System prompt already has rules, so just pass user message
|
| 154 |
prompt = user_message
|
| 155 |
|
| 156 |
save_message(session_id, "user", user_message, intent)
|
|
|
|
| 31 |
"complaint": ["sad", "problem", "issue", "complaint", "shikayat", "not working", "late"],
|
| 32 |
"order_status": ["order status", "track order", "mera order", "delivery"],
|
| 33 |
"refund": ["refund", "paise wapas", "return", "cancel order"],
|
| 34 |
+
"contact": ["contact number", "phone number", "customer support", "call", "number"],
|
| 35 |
"portfolio": ["portfolio", "sample", "example", "kaam dikhao", "gallery"],
|
| 36 |
"general": []
|
| 37 |
}
|
|
|
|
| 55 |
OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
|
| 56 |
MODEL = "google/gemini-2.0-flash-lite-preview-02-05" # free
|
| 57 |
|
| 58 |
+
SYSTEM_PROMPT = """You are "VisionCraft AI" – a professional sales and support assistant for "Elite Visuals", a premium imagery business.
|
| 59 |
|
| 60 |
Services offered:
|
| 61 |
- High-end product photography (jewelry, cars, luxury goods)
|
|
|
|
| 106 |
print(f"OpenRouter error: {e}")
|
| 107 |
return None
|
| 108 |
|
| 109 |
+
# ---------- Smart Fallback (Bullet Points) ----------
|
| 110 |
def fallback_response(prompt, intent):
|
| 111 |
p = prompt.lower()
|
| 112 |
if intent == "greeting":
|
|
|
|
| 124 |
else:
|
| 125 |
return "- Main aapki kaise madad kar sakta hoon?\n- Humari services:\n • Product photography\n • Architecture renders\n • Corporate videos\n • Drone cinematography"
|
| 126 |
|
| 127 |
+
def get_ai_response(prompt, intent):
|
| 128 |
+
resp = call_openrouter(prompt)
|
| 129 |
+
if resp and resp.strip() and "error" not in resp.lower():
|
| 130 |
+
print("✅ OpenRouter succeeded")
|
| 131 |
+
return resp
|
| 132 |
+
print("⚠️ OpenRouter failed, using smart fallback")
|
| 133 |
+
return fallback_response(prompt, intent)
|
| 134 |
+
|
| 135 |
# ---------- Firebase Helpers ----------
|
| 136 |
def save_message(session_id, role, content, intent=None):
|
| 137 |
messages_ref = ref.child(f"chats/{session_id}/messages")
|
|
|
|
| 157 |
intent = classify_intent_sbert(user_message)
|
| 158 |
print(f"🎯 Intent: {intent}")
|
| 159 |
|
| 160 |
+
# System prompt already guides bullet points, so just pass user message
|
|
|
|
| 161 |
prompt = user_message
|
| 162 |
|
| 163 |
save_message(session_id, "user", user_message, intent)
|