Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- __init__.py +4 -0
- server/app.py +8 -73
__init__.py
CHANGED
|
@@ -11,8 +11,12 @@ from .models import (
|
|
| 11 |
GradeResult,
|
| 12 |
)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
__all__ = [
|
| 15 |
"DataCleaningEnv",
|
|
|
|
| 16 |
"DataCleaningClient",
|
| 17 |
"DataCleaningAction",
|
| 18 |
"DataCleaningObservation",
|
|
|
|
| 11 |
GradeResult,
|
| 12 |
)
|
| 13 |
|
| 14 |
+
# Backward-compatible alias for legacy modules that still import AutoCleanEnv.
|
| 15 |
+
AutoCleanEnv = DataCleaningEnv
|
| 16 |
+
|
| 17 |
__all__ = [
|
| 18 |
"DataCleaningEnv",
|
| 19 |
+
"AutoCleanEnv",
|
| 20 |
"DataCleaningClient",
|
| 21 |
"DataCleaningAction",
|
| 22 |
"DataCleaningObservation",
|
server/app.py
CHANGED
|
@@ -1,81 +1,16 @@
|
|
| 1 |
-
|
| 2 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
-
from fastapi.staticfiles import StaticFiles
|
| 4 |
-
from fastapi.responses import FileResponse
|
| 5 |
-
import pandas as pd
|
| 6 |
-
import io
|
| 7 |
-
import json
|
| 8 |
-
from inference import AutoCleanAgent
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
app.add_middleware(
|
| 13 |
-
CORSMiddleware,
|
| 14 |
-
allow_origins=["*"],
|
| 15 |
-
allow_credentials=True,
|
| 16 |
-
allow_methods=["*"],
|
| 17 |
-
allow_headers=["*"],
|
| 18 |
-
)
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
# Lazy initialized agent - created only on first request
|
| 23 |
-
agent = None
|
| 24 |
-
|
| 25 |
-
def get_agent():
|
| 26 |
-
global agent
|
| 27 |
-
if agent is None:
|
| 28 |
-
agent = AutoCleanAgent()
|
| 29 |
-
return agent
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
@app.get("/")
|
| 33 |
-
async def root():
|
| 34 |
-
return FileResponse('static/index.html')
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
@app.post("/api/clean")
|
| 38 |
-
async def clean_dataset(file: UploadFile = File(...)):
|
| 39 |
-
try:
|
| 40 |
-
contents = await file.read()
|
| 41 |
-
|
| 42 |
-
if file.filename.endswith('.csv'):
|
| 43 |
-
df = pd.read_csv(io.BytesIO(contents))
|
| 44 |
-
elif file.filename.endswith('.xlsx'):
|
| 45 |
-
df = pd.read_excel(io.BytesIO(contents))
|
| 46 |
-
else:
|
| 47 |
-
raise HTTPException(status_code=400, detail="Unsupported file format")
|
| 48 |
-
|
| 49 |
-
report = get_agent().run(df)
|
| 50 |
-
|
| 51 |
-
return {
|
| 52 |
-
"success": True,
|
| 53 |
-
"filename": file.filename,
|
| 54 |
-
"initial_score": report['initial_score'],
|
| 55 |
-
"final_score": report['final_score'],
|
| 56 |
-
"improvement": report['improvement'],
|
| 57 |
-
"steps": report['steps_taken'],
|
| 58 |
-
"history": report['history'],
|
| 59 |
-
"metrics": report['final_metrics'],
|
| 60 |
-
"cleaned_data": json.loads(report['cleaned_dataset'].to_json(orient='records'))
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
except Exception as e:
|
| 64 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
@app.get("/api/status")
|
| 68 |
-
async def status():
|
| 69 |
-
return {
|
| 70 |
-
"status": "online",
|
| 71 |
-
"version": "2.0.0",
|
| 72 |
-
"name": "AutoClean AI PRO"
|
| 73 |
-
}
|
| 74 |
|
|
|
|
| 75 |
|
| 76 |
-
def main():
|
| 77 |
-
import uvicorn
|
| 78 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 79 |
|
| 80 |
if __name__ == "__main__":
|
| 81 |
main()
|
|
|
|
| 1 |
+
"""Compatibility shim for the canonical OpenEnv FastAPI app."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
try:
|
| 4 |
+
from ..app import app, startup_event
|
| 5 |
+
except ImportError: # pragma: no cover - direct execution fallback
|
| 6 |
+
from env.app import app, startup_event
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
def main() -> None:
|
| 10 |
+
import uvicorn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
uvicorn.run("env.app:app", host="0.0.0.0", port=8000)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
if __name__ == "__main__":
|
| 16 |
main()
|