Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -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 = """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)
|
|
@@ -65,20 +65,24 @@ Services offered:
|
|
| 65 |
- AI-enhanced photo editing & retouching
|
| 66 |
- 4K/8K video production for commercials
|
| 67 |
|
| 68 |
-
Tone: Polite, professional, enthusiastic. Use Urdu/Hindi mix if customer does
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
Guidelines:
|
| 71 |
-
- For
|
| 72 |
-
-
|
| 73 |
-
-
|
| 74 |
-
- For complaints: apologize, offer discount on next service
|
| 75 |
-
- Never generate random legal/contract text. Stay focused on imagery.
|
| 76 |
-
- Keep answers concise but helpful.
|
| 77 |
-
|
| 78 |
-
Example:
|
| 79 |
-
Customer: "Contact number?"
|
| 80 |
-
You: "Sir, Elite Visuals ka contact: +92 300 1234567. Kya main aapki service mein madad kar sakta hoon?"
|
| 81 |
-
"""
|
| 82 |
|
| 83 |
def call_openrouter(prompt):
|
| 84 |
if not OPENROUTER_API_KEY:
|
|
@@ -106,27 +110,19 @@ def call_openrouter(prompt):
|
|
| 106 |
def fallback_response(prompt, intent):
|
| 107 |
p = prompt.lower()
|
| 108 |
if intent == "greeting":
|
| 109 |
-
return "Wa-Alaikum-Assalam! Main Elite Visuals ka assistant hoon.
|
| 110 |
elif intent == "contact":
|
| 111 |
-
return "
|
| 112 |
elif intent == "pricing":
|
| 113 |
-
return "
|
| 114 |
elif intent == "portfolio":
|
| 115 |
-
return "
|
| 116 |
elif intent == "complaint":
|
| 117 |
-
return "Maazrat,
|
| 118 |
elif intent == "order_status":
|
| 119 |
-
return "Order status check karne ke liye
|
| 120 |
else:
|
| 121 |
-
return "Main aapki kaise madad kar sakta hoon?
|
| 122 |
-
|
| 123 |
-
def get_ai_response(prompt, intent):
|
| 124 |
-
resp = call_openrouter(prompt)
|
| 125 |
-
if resp and resp.strip() and "error" not in resp.lower():
|
| 126 |
-
print("β
OpenRouter succeeded")
|
| 127 |
-
return resp
|
| 128 |
-
print("β οΈ OpenRouter failed, using smart fallback")
|
| 129 |
-
return fallback_response(prompt, intent)
|
| 130 |
|
| 131 |
# ---------- Firebase Helpers ----------
|
| 132 |
def save_message(session_id, role, content, intent=None):
|
|
|
|
| 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 = 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)
|
|
|
|
| 65 |
- AI-enhanced photo editing & retouching
|
| 66 |
- 4K/8K video production for commercials
|
| 67 |
|
| 68 |
+
Tone: Polite, professional, enthusiastic. Use Urdu/Hindi mix if customer does.
|
| 69 |
+
|
| 70 |
+
**IMPORTANT OUTPUT RULE:** Always answer in bullet points (using dashes or asterisks). Never write long paragraphs. Break information into clear, short points.
|
| 71 |
+
|
| 72 |
+
Example correct output for "contact number":
|
| 73 |
+
- π Phone: +92 300 1234567
|
| 74 |
+
- βοΈ Email: hello@elitevisuals.com
|
| 75 |
+
- π Website: www.elitevisuals.com
|
| 76 |
+
|
| 77 |
+
Example for pricing:
|
| 78 |
+
- Product photography: PKR 15,000β25,000 per session
|
| 79 |
+
- Architecture renders: PKR 30,000β50,000 per project
|
| 80 |
+
- Corporate video: PKR 50,000β2,00,000 (depending on length)
|
| 81 |
|
| 82 |
Guidelines:
|
| 83 |
+
- For complaints: apologize in one line, then bullet points for solution.
|
| 84 |
+
- Never generate random legal/contract text.
|
| 85 |
+
- Keep each bullet point short (max 15 words)."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
def call_openrouter(prompt):
|
| 88 |
if not OPENROUTER_API_KEY:
|
|
|
|
| 110 |
def fallback_response(prompt, intent):
|
| 111 |
p = prompt.lower()
|
| 112 |
if intent == "greeting":
|
| 113 |
+
return "- Wa-Alaikum-Assalam! π\n- Main Elite Visuals ka assistant hoon.\n- Main aapki in cheezon mein madad kar sakta hoon: product photography, 3D rendering, video production."
|
| 114 |
elif intent == "contact":
|
| 115 |
+
return "- π Phone: +92 300 1234567\n- βοΈ Email: hello@elitevisuals.com\n- π Website: www.elitevisuals.com"
|
| 116 |
elif intent == "pricing":
|
| 117 |
+
return "- πΈ Product photography: PKR 15,000β25,000/session\n- ποΈ Architecture renders: PKR 30,000β50,000/project\n- π₯ Corporate video: PKR 50,000β2,00,000\n- π‘ Exact quote ke liye apni requirement bhejein."
|
| 118 |
elif intent == "portfolio":
|
| 119 |
+
return "- π· Instagram: @elitevisuals\n- π₯οΈ Website gallery: www.elitevisuals.com/gallery\n- π Sample PDF: bhej sakte hain email par"
|
| 120 |
elif intent == "complaint":
|
| 121 |
+
return "- π Maazrat, issue ke liye.\n- π’ Apna order ID bhejein.\n- π Priority resolve karenge.\n- π Next order par 10% discount."
|
| 122 |
elif intent == "order_status":
|
| 123 |
+
return "- π¦ Order status check karne ke liye:\n β’ Order ID\n β’ Email address\n- β±οΈ 24 ghante mein update de denge."
|
| 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):
|