Akki0404 commited on
Commit
bd8ac82
·
1 Parent(s): cf997a9

fix openenv validate issues

Browse files
Files changed (4) hide show
  1. pyproject.toml +4 -0
  2. requirements.txt +1 -1
  3. server/app.py +74 -0
  4. uv.lock +0 -0
pyproject.toml CHANGED
@@ -18,8 +18,12 @@ dependencies = [
18
  "soundfile",
19
  "fastapi",
20
  "uvicorn",
 
21
  ]
22
 
 
 
 
23
  [tool.openenv]
24
  name = "voice-authenticity"
25
  version = "1.0.0"
 
18
  "soundfile",
19
  "fastapi",
20
  "uvicorn",
21
+ "openenv-core>=0.2.0",
22
  ]
23
 
24
+ [project.scripts]
25
+ server = "app:app"
26
+
27
  [tool.openenv]
28
  name = "voice-authenticity"
29
  version = "1.0.0"
requirements.txt CHANGED
@@ -7,4 +7,4 @@ pydantic
7
  python-dotenv
8
  soundfile
9
  fastapi
10
- uvicorn
 
7
  python-dotenv
8
  soundfile
9
  fastapi
10
+ openenv-core>=0.2.0
server/app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.responses import JSONResponse
3
+ from pydantic import BaseModel
4
+ from typing import Optional
5
+ import uvicorn
6
+ import os
7
+
8
+ from environment.env import VoiceAuthenticityEnv
9
+
10
+ app = FastAPI(title="Voice Authenticity OpenEnv")
11
+
12
+ # Global env instances per task
13
+ envs = {
14
+ "clean_detection": VoiceAuthenticityEnv("clean_detection"),
15
+ "compressed_detection": VoiceAuthenticityEnv("compressed_detection"),
16
+ "adversarial_detection":VoiceAuthenticityEnv("adversarial_detection"),
17
+ }
18
+
19
+ current_task = "clean_detection"
20
+
21
+ class ActionRequest(BaseModel):
22
+ label: Optional[int] = 0
23
+ confidence: Optional[float] = 0.5
24
+ reasoning: Optional[str] = ""
25
+ task_name: Optional[str] = None
26
+
27
+ @app.post("/reset")
28
+ def reset(request: dict = {}):
29
+ global current_task
30
+ task = request.get("task_name", current_task) if request else current_task
31
+ if task not in envs:
32
+ task = "clean_detection"
33
+ current_task = task
34
+ obs = envs[current_task].reset()
35
+ return JSONResponse({
36
+ "observation": obs.dict(),
37
+ "done": False,
38
+ "reward": 0.0,
39
+ "info": {}
40
+ })
41
+
42
+ @app.post("/step")
43
+ def step(action: ActionRequest):
44
+ global current_task
45
+ task = action.task_name or current_task
46
+ if task not in envs:
47
+ task = current_task
48
+ action_dict = {
49
+ "label": action.label,
50
+ "confidence": action.confidence,
51
+ "reasoning": action.reasoning
52
+ }
53
+ obs, reward, done, info = envs[task].step(action_dict)
54
+ return JSONResponse({
55
+ "observation": obs.dict(),
56
+ "reward": reward,
57
+ "done": done,
58
+ "info": info
59
+ })
60
+
61
+ @app.get("/state")
62
+ def state():
63
+ return JSONResponse(envs[current_task].state())
64
+
65
+ @app.get("/health")
66
+ def health():
67
+ return {"status": "ok"}
68
+
69
+ @app.get("/")
70
+ def root():
71
+ return {"name": "voice-authenticity-openenv", "status": "running"}
72
+
73
+ if __name__ == "__main__":
74
+ uvicorn.run(app, host="0.0.0.0", port=7860)
uv.lock ADDED
The diff for this file is too large to render. See raw diff