Spaces:
Sleeping
Sleeping
File size: 1,477 Bytes
9e2986a | 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 | import gradio as gr
from fastapi import FastAPI
from env import EmailEnv
from agent import llm_agent
from rl import update_q
app = FastAPI()
env = EmailEnv()
obs = None
total_score = 0
@app.post("/reset")
def reset_env():
global obs, total_score
obs = env.reset()
total_score = 0
return {"status": "success"}
@app.get("/")
def home():
return {"message": "running"}
def step_env(user_action):
global obs, total_score
if obs is None:
obs = env.reset()
total_score = 0
return obs, 0, total_score
obs_new, reward, done, info = env.step(user_action)
total_score += reward
if done:
obs = None
return "Finished Click again to restart", reward, total_score
return obs_new, reward, total_score
def auto_ai():
global obs, total_score
if obs is None:
obs = env.reset()
total_score = 0
return obs, 0, total_score
action = llm_agent(obs)
obs_new, reward, done, info = env.step(action)
total_score += reward
if done:
obs = None
return "AI Finished Click again to restart", reward, total_score
return f"AI chose: {action} | {obs_new}", reward, total_score
iface = gr.Interface(
fn=step_env,
inputs=gr.Radio(["important", "spam", "normal"]),
outputs=["text", "number", "number"],
title="Smart Email AI Trainer"
)
app = gr.mount_gradio_app(app, iface, path="/") |