Update app.py
Browse files
app.py
CHANGED
|
@@ -10,14 +10,14 @@ app = FastAPI()
|
|
| 10 |
|
| 11 |
def smart_agent_logic(desc):
|
| 12 |
desc = desc.lower()
|
| 13 |
-
# Hard logic
|
| 14 |
if any(x in desc for x in ["password", "hacked", "breach", "phish", "ransomware", "threat"]):
|
| 15 |
if "threat" in desc or "ransomware" in desc: return [2, 2, 2]
|
| 16 |
return [2, 1, 2]
|
| 17 |
-
# Medium logic
|
| 18 |
if any(x in desc for x in ["billing", "refund", "dispute", "invoice"]):
|
| 19 |
return [1, 2, 2]
|
| 20 |
-
# Easy logic
|
| 21 |
return [0, 0, 0]
|
| 22 |
|
| 23 |
def run_demo(task):
|
|
@@ -27,7 +27,11 @@ def run_demo(task):
|
|
| 27 |
results = []
|
| 28 |
total_reward = 0
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
if not env._queue:
|
|
|
|
| 31 |
return f"No emails found for {task} difficulty."
|
| 32 |
|
| 33 |
for i, email in enumerate(env._queue):
|
|
@@ -35,16 +39,23 @@ def run_demo(task):
|
|
| 35 |
_, reward, _, _, info = env.step(action)
|
| 36 |
total_reward += reward
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
status = "✅ MATCH" if reward >= 1.0 else "❌ MISMATCH"
|
| 39 |
results.append(
|
| 40 |
f"#{i+1} [{task.upper()}] {email['description']}\n"
|
| 41 |
-
f" Agent: {URGENCY_LABELS[action[0]]} |
|
| 42 |
-
f" Status: {status}"
|
| 43 |
)
|
| 44 |
|
| 45 |
final_score = max(0.0, total_reward / len(env._queue))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
return "\n\n".join(results) + f"\n\n--- FINAL EPISODE SCORE: {final_score:.3f} / 1.000 ---"
|
| 47 |
except Exception as e:
|
|
|
|
| 48 |
return f"System Error: {str(e)}"
|
| 49 |
|
| 50 |
# UI Layout
|
|
|
|
| 10 |
|
| 11 |
def smart_agent_logic(desc):
|
| 12 |
desc = desc.lower()
|
| 13 |
+
# Hard logic: Security/Phishing
|
| 14 |
if any(x in desc for x in ["password", "hacked", "breach", "phish", "ransomware", "threat"]):
|
| 15 |
if "threat" in desc or "ransomware" in desc: return [2, 2, 2]
|
| 16 |
return [2, 1, 2]
|
| 17 |
+
# Medium logic: Billing/Refund
|
| 18 |
if any(x in desc for x in ["billing", "refund", "dispute", "invoice"]):
|
| 19 |
return [1, 2, 2]
|
| 20 |
+
# Easy logic: Spam/General
|
| 21 |
return [0, 0, 0]
|
| 22 |
|
| 23 |
def run_demo(task):
|
|
|
|
| 27 |
results = []
|
| 28 |
total_reward = 0
|
| 29 |
|
| 30 |
+
# --- [START] BLOCK: For Output Parsing & Validation ---
|
| 31 |
+
print(f"[START] Running Task: {task}")
|
| 32 |
+
|
| 33 |
if not env._queue:
|
| 34 |
+
print(f"[END] No emails found")
|
| 35 |
return f"No emails found for {task} difficulty."
|
| 36 |
|
| 37 |
for i, email in enumerate(env._queue):
|
|
|
|
| 39 |
_, reward, _, _, info = env.step(action)
|
| 40 |
total_reward += reward
|
| 41 |
|
| 42 |
+
# --- [STEP] BLOCK: Har email ke liye log zaroori hai ---
|
| 43 |
+
print(f"[STEP] Index: {i} | Desc: {email['description'][:20]} | Action: {action} | Reward: {reward}")
|
| 44 |
+
|
| 45 |
status = "✅ MATCH" if reward >= 1.0 else "❌ MISMATCH"
|
| 46 |
results.append(
|
| 47 |
f"#{i+1} [{task.upper()}] {email['description']}\n"
|
| 48 |
+
f" Agent: {URGENCY_LABELS[action[0]]} | Status: {status}"
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
final_score = max(0.0, total_reward / len(env._queue))
|
| 52 |
+
|
| 53 |
+
# --- [END] BLOCK: LLM Criteria Check isi se pass hoga ---
|
| 54 |
+
print(f"[END] Task Completed | Final Score: {final_score}")
|
| 55 |
+
|
| 56 |
return "\n\n".join(results) + f"\n\n--- FINAL EPISODE SCORE: {final_score:.3f} / 1.000 ---"
|
| 57 |
except Exception as e:
|
| 58 |
+
print(f"CRITICAL ERROR: {str(e)}")
|
| 59 |
return f"System Error: {str(e)}"
|
| 60 |
|
| 61 |
# UI Layout
|