Omkar1806 commited on
Commit
c8a3816
Β·
verified Β·
1 Parent(s): 342eeb9

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +59 -7
server.py CHANGED
@@ -1,9 +1,14 @@
1
  from fastapi import FastAPI
2
  import gradio as gr
3
 
 
 
 
4
  app = FastAPI()
5
 
6
- # --- API endpoints (required) ---
 
 
7
  @app.post("/reset")
8
  async def reset():
9
  return {"status": "ok"}
@@ -13,16 +18,63 @@ async def status():
13
  return {"status": "online"}
14
 
15
 
16
- # --- Gradio UI ---
 
 
17
  def demo_fn(task):
18
- return f"Running task: {task} (UI restored πŸš€)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
 
 
 
20
  demo = gr.Interface(
21
  fn=demo_fn,
22
- inputs=gr.Dropdown(["easy", "medium", "hard"]),
23
- outputs="text",
24
- title="Email Gatekeeper"
 
25
  )
26
 
27
- # βœ… Mount UI at root
 
 
28
  app = gr.mount_gradio_app(app, demo, path="/")
 
1
  from fastapi import FastAPI
2
  import gradio as gr
3
 
4
+ from env import EmailTriageEnv
5
+ from app import smart_agent_logic
6
+
7
  app = FastAPI()
8
 
9
+ # -------------------------
10
+ # REQUIRED API ENDPOINTS (DO NOT REMOVE)
11
+ # -------------------------
12
  @app.post("/reset")
13
  async def reset():
14
  return {"status": "ok"}
 
18
  return {"status": "online"}
19
 
20
 
21
+ # -------------------------
22
+ # GRADIO FUNCTION (THIS SHOWS REWARD + SCORE)
23
+ # -------------------------
24
  def demo_fn(task):
25
+ env = EmailTriageEnv(task=task)
26
+ state = env.reset()
27
+
28
+ results = []
29
+ total_reward = 0.0
30
+ steps = 0
31
+
32
+ while True:
33
+ if state.get("done"):
34
+ break
35
+
36
+ desc = state["description"]
37
+ action = smart_agent_logic(desc)
38
+
39
+ state, reward, done, _, _ = env.step(action)
40
+
41
+ total_reward += reward
42
+ steps += 1
43
+
44
+ results.append(
45
+ f"### Step {steps}\n"
46
+ f"- πŸ“§ Email: {desc}\n"
47
+ f"- πŸ€– Action: {action}\n"
48
+ f"- ⭐ Reward: {reward:.2f}\n"
49
+ f"---\n"
50
+ )
51
+
52
+ if done:
53
+ break
54
+
55
+ score = total_reward / steps if steps > 0 else 0.0
56
+
57
+ return f"""
58
+ # πŸ“Š Email Triage Results
59
+
60
+ {''.join(results)}
61
+
62
+ ## 🏁 Final Score: **{score:.3f} / 1.000**
63
+ """
64
+
65
 
66
+ # -------------------------
67
+ # GRADIO UI
68
+ # -------------------------
69
  demo = gr.Interface(
70
  fn=demo_fn,
71
+ inputs=gr.Dropdown(["easy", "medium", "hard"], label="Select Difficulty"),
72
+ outputs=gr.Markdown(label="Results"),
73
+ title="πŸ“§ Email Gatekeeper",
74
+ description="AI Agent for Email Triage using Reinforcement Learning"
75
  )
76
 
77
+ # -------------------------
78
+ # MOUNT UI
79
+ # -------------------------
80
  app = gr.mount_gradio_app(app, demo, path="/")