Spaces:
Sleeping
Sleeping
File size: 3,128 Bytes
27158b3 | 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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | """
app.py β Interactive entrypoint for MediRoute OpenEnv.
Run this script for a quick interactive session with the environment:
python app.py --difficulty easy
python app.py --difficulty medium
python app.py --difficulty hard
The script drives a simple REPL loop so you can manually test the environment
without running the full AI inference pipeline.
"""
from __future__ import annotations
import argparse
import json
import sys
from environment import MediRouteEnv
from models import Action
from tasks import list_tasks
def print_obs(obs) -> None:
sep = "β" * 60
print(sep)
print(f" π Location : {obs.location}")
print(f" π€ Symptoms : {obs.symptoms}")
print(f" π¬ Labs : {json.dumps(obs.lab_report_summary, indent=4)}")
print(f" β‘ Severity score : {obs.severity_score:.2f}")
print(f" π₯ Hospitals : {obs.nearby_hospitals}")
print(f" π¨ββοΈ Specialists : {obs.available_specialists}")
print(f" π Past actions : {obs.previous_actions or '(none)'}")
print(sep)
def repl(difficulty: str) -> None:
env = MediRouteEnv()
obs = env.reset(difficulty=difficulty)
print(f"\nπ₯ MediRoute OpenEnv β difficulty: {difficulty.upper()}")
print_obs(obs)
valid_types = [
"analyze_symptoms",
"request_more_info",
"recommend_specialist",
"select_hospital",
"book_appointment",
"call_ambulance",
"provide_temp_guidance",
]
print("Valid action types:", ", ".join(valid_types))
print("Type 'quit' to exit.\n")
while True:
raw = input("action_type [target]: ").strip()
if raw.lower() in {"quit", "exit", "q"}:
break
parts = raw.split(maxsplit=1)
action_type = parts[0]
target = parts[1] if len(parts) > 1 else None
action = Action(action_type=action_type, target=target)
result = env.step(action)
reward_sign = "+" if result.reward >= 0 else ""
print(f"\n Reward : {reward_sign}{result.reward:.2f}")
print(f" Done : {result.done}")
print(f" Total : {result.info.get('total_reward', 0):.2f}")
if result.done:
summary = result.info.get("episode_summary", {})
print("\nπ― Episode complete!")
print(json.dumps(summary, indent=4))
break
else:
print_obs(result.observation)
def main() -> None:
parser = argparse.ArgumentParser(description="MediRoute OpenEnv interactive REPL")
parser.add_argument(
"--difficulty",
choices=["easy", "medium", "hard"],
default="easy",
help="Task difficulty level (default: easy)",
)
parser.add_argument("--list-tasks", action="store_true", help="List available tasks and exit")
args = parser.parse_args()
if args.list_tasks:
print("\nAvailable Tasks:\n")
for diff, desc in list_tasks().items():
print(f" [{diff.upper():6}] {desc}")
sys.exit(0)
repl(args.difficulty)
if __name__ == "__main__":
main()
|