File size: 1,727 Bytes
f5efb42
3527ca9
f5efb42
c8a3816
 
 
f5efb42
 
c8a3816
 
 
f5efb42
 
 
 
3527ca9
 
 
 
 
c8a3816
 
 
3527ca9
c8a3816
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3527ca9
c8a3816
 
 
3527ca9
 
c8a3816
 
 
 
3527ca9
f5efb42
c8a3816
 
 
3527ca9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from fastapi import FastAPI
import gradio as gr

from env import EmailTriageEnv
from app import smart_agent_logic

app = FastAPI()

# -------------------------
# REQUIRED API ENDPOINTS (DO NOT REMOVE)
# -------------------------
@app.post("/reset")
async def reset():
    return {"status": "ok"}

@app.get("/status")
async def status():
    return {"status": "online"}


# -------------------------
# GRADIO FUNCTION (THIS SHOWS REWARD + SCORE)
# -------------------------
def demo_fn(task):
    env = EmailTriageEnv(task=task)
    state = env.reset()

    results = []
    total_reward = 0.0
    steps = 0

    while True:
        if state.get("done"):
            break

        desc = state["description"]
        action = smart_agent_logic(desc)

        state, reward, done, _, _ = env.step(action)

        total_reward += reward
        steps += 1

        results.append(
            f"### Step {steps}\n"
            f"- πŸ“§ Email: {desc}\n"
            f"- πŸ€– Action: {action}\n"
            f"- ⭐ Reward: {reward:.2f}\n"
            f"---\n"
        )

        if done:
            break

    score = total_reward / steps if steps > 0 else 0.0

    return f"""
# πŸ“Š Email Triage Results

{''.join(results)}

## 🏁 Final Score: **{score:.3f} / 1.000**
"""


# -------------------------
# GRADIO UI
# -------------------------
demo = gr.Interface(
    fn=demo_fn,
    inputs=gr.Dropdown(["easy", "medium", "hard"], label="Select Difficulty"),
    outputs=gr.Markdown(label="Results"),
    title="πŸ“§ Email Gatekeeper",
    description="AI Agent for Email Triage using Reinforcement Learning"
)

# -------------------------
# MOUNT UI
# -------------------------
app = gr.mount_gradio_app(app, demo, path="/")