Spaces:
Sleeping
Sleeping
Commit ·
6853edd
1
Parent(s): 3127699
final-version
Browse files
app.py
CHANGED
|
@@ -1,68 +1,36 @@
|
|
| 1 |
import os
|
| 2 |
import shutil
|
| 3 |
-
|
| 4 |
-
from routers import objective_route, outliner_route, outcome_route, introduction_route
|
| 5 |
-
|
| 6 |
-
# ---------------------------------
|
| 7 |
-
# 🧹 إعداد البيئة ومسارات الكاش
|
| 8 |
-
# ---------------------------------
|
| 9 |
os.environ["HOME"] = "/tmp"
|
| 10 |
os.environ["XDG_DATA_HOME"] = "/tmp/.local/share"
|
| 11 |
os.environ["CREWAI_STORAGE_PATH"] = "/tmp/crewai_data"
|
| 12 |
os.environ["CREWAI_HOME"] = "/tmp/crewai_home"
|
| 13 |
|
| 14 |
-
#
|
| 15 |
os.makedirs("/tmp/.local/share", exist_ok=True)
|
| 16 |
os.makedirs("/tmp/crewai_data", exist_ok=True)
|
| 17 |
os.makedirs("/tmp/crewai_home", exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
# ---------------------------------
|
| 20 |
-
# 🧽 تنظيف الكاش عند بدء التشغيل
|
| 21 |
-
# ---------------------------------
|
| 22 |
-
CACHE_PATHS = [
|
| 23 |
-
"/tmp/crewai_data",
|
| 24 |
-
"/tmp/crewai_home",
|
| 25 |
-
"/tmp/.local/share/crewai_data",
|
| 26 |
-
]
|
| 27 |
-
|
| 28 |
-
for path in CACHE_PATHS:
|
| 29 |
-
if os.path.exists(path):
|
| 30 |
-
shutil.rmtree(path, ignore_errors=True)
|
| 31 |
-
print(f"🧹 Cleared cache folder: {path}")
|
| 32 |
-
|
| 33 |
-
# ---------------------------------
|
| 34 |
-
# 🚀 إعداد التطبيق
|
| 35 |
-
# ---------------------------------
|
| 36 |
app = FastAPI(title="AI Agent Project", version="1.0.0")
|
| 37 |
|
| 38 |
-
# Routers
|
| 39 |
app.include_router(outliner_route.router)
|
| 40 |
app.include_router(objective_route.router)
|
| 41 |
app.include_router(outcome_route.router)
|
| 42 |
app.include_router(introduction_route.router)
|
| 43 |
|
| 44 |
|
| 45 |
-
|
| 46 |
-
# ✅ Root endpoint
|
| 47 |
-
# ---------------------------------
|
| 48 |
-
@app.get("/")
|
| 49 |
-
def read_root():
|
| 50 |
-
return {"message": "Welcome to AI Agent Project API 🚀"}
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
# ---------------------------------
|
| 54 |
-
# 🧹 Endpoint لمسح الكاش يدويًا
|
| 55 |
-
# ---------------------------------
|
| 56 |
-
ADMIN_TOKEN = "ziad_secret_123" # غيّره لأي قيمة سرية
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
@app.get("/reset-cache")
|
| 60 |
def reset_cache():
|
| 61 |
-
|
| 62 |
paths = [
|
| 63 |
"/tmp/crewai_data",
|
| 64 |
"/tmp/crewai_home",
|
| 65 |
-
"/tmp/.local/share
|
| 66 |
]
|
| 67 |
|
| 68 |
for path in paths:
|
|
@@ -71,14 +39,22 @@ def reset_cache():
|
|
| 71 |
|
| 72 |
os.makedirs("/tmp/crewai_data", exist_ok=True)
|
| 73 |
os.makedirs("/tmp/crewai_home", exist_ok=True)
|
| 74 |
-
os.makedirs("/tmp/.local/share
|
| 75 |
|
| 76 |
return {"message": "✅ Cache cleared successfully."}
|
| 77 |
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
# if __name__ == "__main__":
|
| 83 |
# import uvicorn
|
|
|
|
| 84 |
# uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
|
|
|
|
| 1 |
import os
|
| 2 |
import shutil
|
| 3 |
+
# Force HOME to /tmp so CrewAI doesn't try writing to /.local
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
os.environ["HOME"] = "/tmp"
|
| 5 |
os.environ["XDG_DATA_HOME"] = "/tmp/.local/share"
|
| 6 |
os.environ["CREWAI_STORAGE_PATH"] = "/tmp/crewai_data"
|
| 7 |
os.environ["CREWAI_HOME"] = "/tmp/crewai_home"
|
| 8 |
|
| 9 |
+
# Create safe directories
|
| 10 |
os.makedirs("/tmp/.local/share", exist_ok=True)
|
| 11 |
os.makedirs("/tmp/crewai_data", exist_ok=True)
|
| 12 |
os.makedirs("/tmp/crewai_home", exist_ok=True)
|
| 13 |
+
from crewai import Crew, Process
|
| 14 |
+
import json
|
| 15 |
+
from fastapi import FastAPI
|
| 16 |
+
from routers import objective_route, outliner_route, outcome_route,introduction_route
|
| 17 |
+
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
app = FastAPI(title="AI Agent Project", version="1.0.0")
|
| 20 |
|
|
|
|
| 21 |
app.include_router(outliner_route.router)
|
| 22 |
app.include_router(objective_route.router)
|
| 23 |
app.include_router(outcome_route.router)
|
| 24 |
app.include_router(introduction_route.router)
|
| 25 |
|
| 26 |
|
| 27 |
+
@app.post("/reset-cache")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
def reset_cache():
|
| 29 |
+
|
| 30 |
paths = [
|
| 31 |
"/tmp/crewai_data",
|
| 32 |
"/tmp/crewai_home",
|
| 33 |
+
"/tmp/.local/share",
|
| 34 |
]
|
| 35 |
|
| 36 |
for path in paths:
|
|
|
|
| 39 |
|
| 40 |
os.makedirs("/tmp/crewai_data", exist_ok=True)
|
| 41 |
os.makedirs("/tmp/crewai_home", exist_ok=True)
|
| 42 |
+
os.makedirs("/tmp/.local/share", exist_ok=True)
|
| 43 |
|
| 44 |
return {"message": "✅ Cache cleared successfully."}
|
| 45 |
|
| 46 |
|
| 47 |
+
# Example root endpoint
|
| 48 |
+
@app.get("/")
|
| 49 |
+
def read_root():
|
| 50 |
+
return {"message": "Welcome to AI Agent Project API 🚀"}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
# ------------------------
|
| 54 |
+
# ✅ نقطة تشغيل السيرفر
|
| 55 |
+
# ------------------------
|
| 56 |
+
|
| 57 |
# if __name__ == "__main__":
|
| 58 |
# import uvicorn
|
| 59 |
+
|
| 60 |
# uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
|