Update app.py
Browse files
app.py
CHANGED
|
@@ -223,7 +223,7 @@ def generate_enriched_links(row):
|
|
| 223 |
markdown = f"🎧 [Watch {guest_name}'s episode here]({base_url}) - {short_summary}"
|
| 224 |
return [markdown]
|
| 225 |
|
| 226 |
-
def build_enhanced_prompt(user_question, context_results, top_workshops, user_preference=None, user_type='unknown', enriched_podcast_links=None, wants_details=False, current_topic=None, mode="Mode B", is_low_confidence=False, is_faq_match=False):
|
| 227 |
"""Builds the system prompt with strict formatting rules."""
|
| 228 |
|
| 229 |
# Dynamic Links from Structured Knowledge
|
|
@@ -310,6 +310,29 @@ REQUIRED RESPONSE FORMAT:
|
|
| 310 |
Here's a free resource that might help you move forward:
|
| 311 |
[Pick ONE: {single_podcast} OR Free Class at {free_class_url}]
|
| 312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
Questions? Contact info@getscenestudios.com"""
|
| 314 |
return prompt
|
| 315 |
|
|
@@ -698,18 +721,29 @@ def process_question(question: str, current_session_id: str):
|
|
| 698 |
activated_mode = "Mode B" # Default safe value
|
| 699 |
|
| 700 |
# 1. HARD POLICY CHECK (Internal critical issues only)
|
|
|
|
| 701 |
if detect_policy_issue(question) and should_include_email(question):
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 713 |
|
| 714 |
# 2. Handle Session & Knowledge State
|
| 715 |
update_knowledge_from_question(current_session_id, question)
|
|
@@ -806,9 +840,10 @@ def process_question(question: str, current_session_id: str):
|
|
| 806 |
has_session_context = (current_topic is not None) or (user_preference is not None)
|
| 807 |
|
| 808 |
FOLLOWUP_KEYWORDS = ['yes', 'no', 'sure', 'okay', 'thanks', 'thank you', 'please', 'go ahead', 'continue', 'more']
|
| 809 |
-
ACTING_KEYWORDS = ['class', 'workshop', 'coaching', 'studio', 'acting', 'online', 'person', 'atlanta', 'training', 'prefer', 'preference', 'format', 'recommendation', 'online class', 'online workshop','instudio class','instudio workshop', 'actor', 'scene', 'audition', 'theatre', 'film', 'tv', 'commercial', 'agent', 'rep', 'manager', 'instructor', 'role', 'auditing', 'audit', 'representation', 'summit', 'sign up', 'sign-up', 'register', 'enroll', 'schedule', 'cancel', 'reschedule', 'how do i', 'podcast', 'podcasts', 'youtube', 'episode', 'episodes', 'watch']
|
| 810 |
|
| 811 |
is_acting_related = (
|
|
|
|
| 812 |
len(categories) > 0 or
|
| 813 |
detect_response_type(question) == "support" or
|
| 814 |
any(re.search(rf'\b{re.escape(k)}\b', question.lower()) for k in ACTION_KEYWORDS) or
|
|
@@ -882,7 +917,8 @@ def process_question(question: str, current_session_id: str):
|
|
| 882 |
current_topic=current_topic,
|
| 883 |
mode=activated_mode,
|
| 884 |
is_low_confidence=is_low_confidence,
|
| 885 |
-
is_faq_match=is_faq_match
|
|
|
|
| 886 |
)
|
| 887 |
|
| 888 |
# LLM messages
|
|
@@ -1041,5 +1077,12 @@ with gr.Blocks(title="Get Scene Studios Chatbot") as demo:
|
|
| 1041 |
)
|
| 1042 |
|
| 1043 |
# Launch the app
|
| 1044 |
-
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1045 |
demo.launch()
|
|
|
|
| 223 |
markdown = f"🎧 [Watch {guest_name}'s episode here]({base_url}) - {short_summary}"
|
| 224 |
return [markdown]
|
| 225 |
|
| 226 |
+
def build_enhanced_prompt(user_question, context_results, top_workshops, user_preference=None, user_type='unknown', enriched_podcast_links=None, wants_details=False, current_topic=None, mode="Mode B", is_low_confidence=False, is_faq_match=False, is_policy_query=False):
|
| 227 |
"""Builds the system prompt with strict formatting rules."""
|
| 228 |
|
| 229 |
# Dynamic Links from Structured Knowledge
|
|
|
|
| 310 |
Here's a free resource that might help you move forward:
|
| 311 |
[Pick ONE: {single_podcast} OR Free Class at {free_class_url}]
|
| 312 |
|
| 313 |
+
Questions? Contact info@getscenestudios.com"""
|
| 314 |
+
return prompt
|
| 315 |
+
|
| 316 |
+
# --- POLICY QUERY MODE ---
|
| 317 |
+
if is_policy_query:
|
| 318 |
+
prompt = f"""{PERSONA_INSTRUCTION}
|
| 319 |
+
|
| 320 |
+
You are acting as a helpful mentor assisting with a policy-related inquiry (refund, cancellation, or billing).
|
| 321 |
+
|
| 322 |
+
CRITICAL INSTRUCTIONS:
|
| 323 |
+
1. Be extremely polite, warm, and professional.
|
| 324 |
+
2. If the user is asking for a refund or to cancel, you MUST ask them for a reason if they haven't provided one yet.
|
| 325 |
+
3. If they haven't mentioned which class or podcast they are referring to, ask them politely to specify.
|
| 326 |
+
4. Let them know it's no problem at all and that we want to make sure they are taken care of.
|
| 327 |
+
5. Always provide the contact email: info@getscenestudios.com for them to finalize their request.
|
| 328 |
+
6. Do NOT suggest new workshops or podcasts in this response.
|
| 329 |
+
7. ACKNOWLEDGE their situation first.
|
| 330 |
+
|
| 331 |
+
USER'S QUESTION: {user_question}
|
| 332 |
+
|
| 333 |
+
REQUIRED RESPONSE FORMAT:
|
| 334 |
+
[Your polite, mentor-like response asking for missing details or acknowledging the reason]
|
| 335 |
+
|
| 336 |
Questions? Contact info@getscenestudios.com"""
|
| 337 |
return prompt
|
| 338 |
|
|
|
|
| 721 |
activated_mode = "Mode B" # Default safe value
|
| 722 |
|
| 723 |
# 1. HARD POLICY CHECK (Internal critical issues only)
|
| 724 |
+
is_policy_query = False
|
| 725 |
if detect_policy_issue(question) and should_include_email(question):
|
| 726 |
+
q_lower = question.lower()
|
| 727 |
+
|
| 728 |
+
# Specific handling for late/miss issues
|
| 729 |
+
is_late_miss = any(re.search(rf'\b{re.escape(word)}\b', q_lower) for word in ['late', 'miss', 'missed', 'attendance', 'attend'])
|
| 730 |
+
|
| 731 |
+
if is_late_miss:
|
| 732 |
+
ans = "Don't worry! You can email info@getscenestudios.com and our team will help you with any attendance or scheduling issues."
|
| 733 |
+
log_question(
|
| 734 |
+
question=question,
|
| 735 |
+
session_id=current_session_id,
|
| 736 |
+
category="policy_late_miss",
|
| 737 |
+
answer=ans,
|
| 738 |
+
detected_mode="Mode B",
|
| 739 |
+
routing_question=None,
|
| 740 |
+
rule_triggered="late_miss_polite",
|
| 741 |
+
link_provided=False
|
| 742 |
+
)
|
| 743 |
+
return ans
|
| 744 |
+
|
| 745 |
+
# For refund/cancel, we set a flag and continue to LLM for conversational response
|
| 746 |
+
is_policy_query = True
|
| 747 |
|
| 748 |
# 2. Handle Session & Knowledge State
|
| 749 |
update_knowledge_from_question(current_session_id, question)
|
|
|
|
| 840 |
has_session_context = (current_topic is not None) or (user_preference is not None)
|
| 841 |
|
| 842 |
FOLLOWUP_KEYWORDS = ['yes', 'no', 'sure', 'okay', 'thanks', 'thank you', 'please', 'go ahead', 'continue', 'more']
|
| 843 |
+
ACTING_KEYWORDS = ['class', 'workshop', 'coaching', 'studio', 'acting', 'online', 'person', 'atlanta', 'training', 'prefer', 'preference', 'format', 'recommendation', 'online class', 'online workshop','instudio class','instudio workshop', 'actor', 'scene', 'audition', 'theatre', 'film', 'tv', 'commercial', 'agent', 'rep', 'manager', 'instructor', 'role', 'auditing', 'audit', 'representation', 'summit', 'sign up', 'sign-up', 'register', 'enroll', 'schedule', 'cancel', 'reschedule', 'how do i', 'podcast', 'podcasts', 'youtube', 'episode', 'episodes', 'watch', 'refund']
|
| 844 |
|
| 845 |
is_acting_related = (
|
| 846 |
+
is_policy_query or
|
| 847 |
len(categories) > 0 or
|
| 848 |
detect_response_type(question) == "support" or
|
| 849 |
any(re.search(rf'\b{re.escape(k)}\b', question.lower()) for k in ACTION_KEYWORDS) or
|
|
|
|
| 917 |
current_topic=current_topic,
|
| 918 |
mode=activated_mode,
|
| 919 |
is_low_confidence=is_low_confidence,
|
| 920 |
+
is_faq_match=is_faq_match,
|
| 921 |
+
is_policy_query=is_policy_query
|
| 922 |
)
|
| 923 |
|
| 924 |
# LLM messages
|
|
|
|
| 1077 |
)
|
| 1078 |
|
| 1079 |
# Launch the app
|
| 1080 |
+
if __name__ == "__main__":
|
| 1081 |
+
print("\n" + "="*60)
|
| 1082 |
+
print("🎬 Get Scene Studios Chatbot")
|
| 1083 |
+
print("="*60)
|
| 1084 |
+
print("\n✅ No Flask API needed - all processing is done directly!")
|
| 1085 |
+
print("🌐 Gradio interface will open in your browser")
|
| 1086 |
+
print("="*60 + "\n")
|
| 1087 |
+
|
| 1088 |
demo.launch()
|