Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,7 @@ from gradio_client import Client
|
|
| 32 |
# ============================================================
|
| 33 |
|
| 34 |
APP_NAME = "X-RUDRA"
|
| 35 |
-
VERSION = "3.8.
|
| 36 |
|
| 37 |
M1_REPO = os.getenv("M1_REPO", "Shrijanagain/M1")
|
| 38 |
M2_REPO = os.getenv("M2_REPO", "Shrijanagain/M2")
|
|
@@ -75,10 +75,6 @@ def get_m2_client():
|
|
| 75 |
|
| 76 |
# ============================================================
|
| 77 |
# MODEL-BASED INTENT CLASSIFIER
|
| 78 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 79 |
-
# Uses M1 (or M2) to decide ACTION or CASUAL.
|
| 80 |
-
# No hardcoded keywords β the model decides.
|
| 81 |
-
# If both fail, defaults to ACTION.
|
| 82 |
# ============================================================
|
| 83 |
|
| 84 |
CLASSIFIER_SYSTEM_PROMPT = """
|
|
@@ -99,8 +95,8 @@ def classify_intent(question: str) -> str:
|
|
| 99 |
try:
|
| 100 |
result = m1_client.predict(
|
| 101 |
prompt=prompt,
|
| 102 |
-
max_tokens=64,
|
| 103 |
-
temperature=0.
|
| 104 |
api_name="/generate"
|
| 105 |
)
|
| 106 |
if result:
|
|
@@ -122,8 +118,8 @@ def classify_intent(question: str) -> str:
|
|
| 122 |
try:
|
| 123 |
result = m2_client.predict(
|
| 124 |
prompt=prompt,
|
| 125 |
-
max_tokens=64,
|
| 126 |
-
temperature=0.
|
| 127 |
api_name="/generate"
|
| 128 |
)
|
| 129 |
if result:
|
|
@@ -139,9 +135,15 @@ def classify_intent(question: str) -> str:
|
|
| 139 |
except Exception as e:
|
| 140 |
print(f"[Classifier] M2 call failed: {e}")
|
| 141 |
|
| 142 |
-
# Fallback:
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
|
| 147 |
# ============================================================
|
|
@@ -688,5 +690,4 @@ if __name__ == "__main__":
|
|
| 688 |
print("HF_TOKEN set β rate limits reduced.")
|
| 689 |
else:
|
| 690 |
print("HF_TOKEN not set β you may experience rate limits. Set it as a Secret in your Space.")
|
| 691 |
-
demo.launch(server_name="0.0.0.0", server_port=PORT, css=CSS, show_error=True)
|
| 692 |
-
|
|
|
|
| 32 |
# ============================================================
|
| 33 |
|
| 34 |
APP_NAME = "X-RUDRA"
|
| 35 |
+
VERSION = "3.8.3" # bumped
|
| 36 |
|
| 37 |
M1_REPO = os.getenv("M1_REPO", "Shrijanagain/M1")
|
| 38 |
M2_REPO = os.getenv("M2_REPO", "Shrijanagain/M2")
|
|
|
|
| 75 |
|
| 76 |
# ============================================================
|
| 77 |
# MODEL-BASED INTENT CLASSIFIER
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
# ============================================================
|
| 79 |
|
| 80 |
CLASSIFIER_SYSTEM_PROMPT = """
|
|
|
|
| 95 |
try:
|
| 96 |
result = m1_client.predict(
|
| 97 |
prompt=prompt,
|
| 98 |
+
max_tokens=64,
|
| 99 |
+
temperature=0.1, # FIXED: was 0.0 β now 0.1
|
| 100 |
api_name="/generate"
|
| 101 |
)
|
| 102 |
if result:
|
|
|
|
| 118 |
try:
|
| 119 |
result = m2_client.predict(
|
| 120 |
prompt=prompt,
|
| 121 |
+
max_tokens=64,
|
| 122 |
+
temperature=0.1, # FIXED
|
| 123 |
api_name="/generate"
|
| 124 |
)
|
| 125 |
if result:
|
|
|
|
| 135 |
except Exception as e:
|
| 136 |
print(f"[Classifier] M2 call failed: {e}")
|
| 137 |
|
| 138 |
+
# Fallback: if both fail, use simple heuristic (no keyword list)
|
| 139 |
+
# For very short messages (<=3 words), assume CASUAL to avoid unnecessary search.
|
| 140 |
+
word_count = len(question.split())
|
| 141 |
+
if word_count <= 3:
|
| 142 |
+
print("[Classifier] Fallback β CASUAL (short message)")
|
| 143 |
+
return "CASUAL"
|
| 144 |
+
else:
|
| 145 |
+
print("[Classifier] Fallback β ACTION (longer message)")
|
| 146 |
+
return "ACTION"
|
| 147 |
|
| 148 |
|
| 149 |
# ============================================================
|
|
|
|
| 690 |
print("HF_TOKEN set β rate limits reduced.")
|
| 691 |
else:
|
| 692 |
print("HF_TOKEN not set β you may experience rate limits. Set it as a Secret in your Space.")
|
| 693 |
+
demo.launch(server_name="0.0.0.0", server_port=PORT, css=CSS, show_error=True)
|
|
|