Spaces:
Runtime error
Runtime error
Commit ·
93bb375
1
Parent(s): eb29d87
Update all backend files cleanly without secrets
Browse files- .env +1 -1
- main.py +9 -20
- requirements.txt +8 -10
- routers/converter_tools.py +3 -3
- routers/image_tools.py +1 -1
- routers/pdf.py +1 -1
- routers/video.py +1 -1
- services/ads_service.py +1 -1
- status.sh +0 -2
.env
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
SECRET_KEY=12345
|
| 2 |
DATABASE_URL=postgresql+psycopg2://gpr3:gpr3.admin@localhost:5432/gpr3db
|
| 3 |
-
BASE_URL=https://
|
| 4 |
|
| 5 |
ADMIN_SECRET=superadmin123
|
| 6 |
# .env file
|
|
|
|
| 1 |
SECRET_KEY=12345
|
| 2 |
DATABASE_URL=postgresql+psycopg2://gpr3:gpr3.admin@localhost:5432/gpr3db
|
| 3 |
+
BASE_URL=https://cloudairambo-cloudairambo.hf.space
|
| 4 |
|
| 5 |
ADMIN_SECRET=superadmin123
|
| 6 |
# .env file
|
main.py
CHANGED
|
@@ -5,13 +5,13 @@ from starlette.middleware.sessions import SessionMiddleware
|
|
| 5 |
from starlette.middleware.base import BaseHTTPMiddleware
|
| 6 |
from fastapi.staticfiles import StaticFiles
|
| 7 |
|
| 8 |
-
# 🚀 1. ENSURE DIRECTORIES EXIST
|
| 9 |
os.makedirs("static/output", exist_ok=True)
|
| 10 |
os.makedirs("uploads", exist_ok=True)
|
| 11 |
os.makedirs("tmp", exist_ok=True)
|
| 12 |
os.makedirs("temp", exist_ok=True)
|
| 13 |
|
| 14 |
-
# 🚀 2. INITIALIZE RAM DATABASE TABLES
|
| 15 |
from core.database import Base, engine
|
| 16 |
Base.metadata.create_all(bind=engine)
|
| 17 |
|
|
@@ -53,9 +53,6 @@ class LargeUploadMiddleware(BaseHTTPMiddleware):
|
|
| 53 |
|
| 54 |
app.add_middleware(LargeUploadMiddleware)
|
| 55 |
|
| 56 |
-
# -------------------------------------------------------
|
| 57 |
-
# 🌍 CORS (Includes Hugging Face & Production)
|
| 58 |
-
# -------------------------------------------------------
|
| 59 |
LOCAL_ORIGINS = [
|
| 60 |
"http://localhost:3000",
|
| 61 |
"http://127.0.0.1:3000",
|
|
@@ -63,6 +60,8 @@ LOCAL_ORIGINS = [
|
|
| 63 |
]
|
| 64 |
|
| 65 |
PRODUCTION_ORIGINS = [
|
|
|
|
|
|
|
| 66 |
"https://cloudaipdf.com",
|
| 67 |
"https://www.cloudaipdf.com",
|
| 68 |
"https://api.cloudaipdf.com",
|
|
@@ -72,15 +71,12 @@ PRODUCTION_ORIGINS = [
|
|
| 72 |
app.add_middleware(
|
| 73 |
CORSMiddleware,
|
| 74 |
allow_origins=LOCAL_ORIGINS + PRODUCTION_ORIGINS,
|
| 75 |
-
allow_origin_regex=r"https://.*\.hf\.space",
|
| 76 |
allow_credentials=True,
|
| 77 |
allow_methods=["*"],
|
| 78 |
allow_headers=["*"],
|
| 79 |
)
|
| 80 |
|
| 81 |
-
# -------------------------------------------------------
|
| 82 |
-
# 🍪 SESSIONS
|
| 83 |
-
# -------------------------------------------------------
|
| 84 |
app.add_middleware(
|
| 85 |
SessionMiddleware,
|
| 86 |
secret_key=getattr(settings, "SECRET_KEY", "default-fallback-secret-key-32chars"),
|
|
@@ -88,20 +84,13 @@ app.add_middleware(
|
|
| 88 |
https_only=True,
|
| 89 |
)
|
| 90 |
|
| 91 |
-
# -------------------------------------------------------
|
| 92 |
-
# 📁 STATIC FILES
|
| 93 |
-
# -------------------------------------------------------
|
| 94 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 95 |
app.mount("/uploads", StaticFiles(directory="uploads"), name="uploads")
|
| 96 |
|
| 97 |
-
#
|
| 98 |
-
# 🛡️ ADMIN (LOAD FIRST)
|
| 99 |
-
# -------------------------------------------------------
|
| 100 |
setup_admin(app)
|
| 101 |
|
| 102 |
-
# -------------------------------------------------------
|
| 103 |
# 🔌 ROUTERS
|
| 104 |
-
# -------------------------------------------------------
|
| 105 |
app.include_router(pdf.router, prefix="/pdf")
|
| 106 |
app.include_router(image.router, prefix="/image")
|
| 107 |
app.include_router(image_tools.router, prefix="/image-tools")
|
|
@@ -122,12 +111,12 @@ app.include_router(ratings_router)
|
|
| 122 |
app.include_router(admin_auth.router, prefix="/admin-auth")
|
| 123 |
|
| 124 |
# -------------------------------------------------------
|
| 125 |
-
# 🏠
|
| 126 |
# -------------------------------------------------------
|
| 127 |
-
@app.get("/")
|
| 128 |
def home():
|
| 129 |
return {"message": "Tools Backend Running Successfully!"}
|
| 130 |
|
| 131 |
@app.get("/health", include_in_schema=False)
|
| 132 |
def health():
|
| 133 |
-
return {"status": "ok"}
|
|
|
|
| 5 |
from starlette.middleware.base import BaseHTTPMiddleware
|
| 6 |
from fastapi.staticfiles import StaticFiles
|
| 7 |
|
| 8 |
+
# 🚀 1. ENSURE DIRECTORIES EXIST
|
| 9 |
os.makedirs("static/output", exist_ok=True)
|
| 10 |
os.makedirs("uploads", exist_ok=True)
|
| 11 |
os.makedirs("tmp", exist_ok=True)
|
| 12 |
os.makedirs("temp", exist_ok=True)
|
| 13 |
|
| 14 |
+
# 🚀 2. INITIALIZE RAM DATABASE TABLES
|
| 15 |
from core.database import Base, engine
|
| 16 |
Base.metadata.create_all(bind=engine)
|
| 17 |
|
|
|
|
| 53 |
|
| 54 |
app.add_middleware(LargeUploadMiddleware)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
| 56 |
LOCAL_ORIGINS = [
|
| 57 |
"http://localhost:3000",
|
| 58 |
"http://127.0.0.1:3000",
|
|
|
|
| 60 |
]
|
| 61 |
|
| 62 |
PRODUCTION_ORIGINS = [
|
| 63 |
+
"https://freetoolshub.cloudairambo.com",
|
| 64 |
+
"https://www.freetoolshub.cloudairambo.com",
|
| 65 |
"https://cloudaipdf.com",
|
| 66 |
"https://www.cloudaipdf.com",
|
| 67 |
"https://api.cloudaipdf.com",
|
|
|
|
| 71 |
app.add_middleware(
|
| 72 |
CORSMiddleware,
|
| 73 |
allow_origins=LOCAL_ORIGINS + PRODUCTION_ORIGINS,
|
| 74 |
+
allow_origin_regex=r"https://.*\.hf\.space",
|
| 75 |
allow_credentials=True,
|
| 76 |
allow_methods=["*"],
|
| 77 |
allow_headers=["*"],
|
| 78 |
)
|
| 79 |
|
|
|
|
|
|
|
|
|
|
| 80 |
app.add_middleware(
|
| 81 |
SessionMiddleware,
|
| 82 |
secret_key=getattr(settings, "SECRET_KEY", "default-fallback-secret-key-32chars"),
|
|
|
|
| 84 |
https_only=True,
|
| 85 |
)
|
| 86 |
|
|
|
|
|
|
|
|
|
|
| 87 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 88 |
app.mount("/uploads", StaticFiles(directory="uploads"), name="uploads")
|
| 89 |
|
| 90 |
+
# 🛡️ ADMIN
|
|
|
|
|
|
|
| 91 |
setup_admin(app)
|
| 92 |
|
|
|
|
| 93 |
# 🔌 ROUTERS
|
|
|
|
| 94 |
app.include_router(pdf.router, prefix="/pdf")
|
| 95 |
app.include_router(image.router, prefix="/image")
|
| 96 |
app.include_router(image_tools.router, prefix="/image-tools")
|
|
|
|
| 111 |
app.include_router(admin_auth.router, prefix="/admin-auth")
|
| 112 |
|
| 113 |
# -------------------------------------------------------
|
| 114 |
+
# 🏠 API STATUS (Changed from / to /api-status to prevent conflict with Gradio)
|
| 115 |
# -------------------------------------------------------
|
| 116 |
+
@app.get("/api-status")
|
| 117 |
def home():
|
| 118 |
return {"message": "Tools Backend Running Successfully!"}
|
| 119 |
|
| 120 |
@app.get("/health", include_in_schema=False)
|
| 121 |
def health():
|
| 122 |
+
return {"status": "ok"}
|
requirements.txt
CHANGED
|
@@ -15,6 +15,7 @@ orjson==3.10.3
|
|
| 15 |
SQLAlchemy==2.0.30
|
| 16 |
alembic
|
| 17 |
sqladmin==0.15.2
|
|
|
|
| 18 |
|
| 19 |
# --- Universal Document Converters ---
|
| 20 |
python-docx
|
|
@@ -37,6 +38,7 @@ pikepdf
|
|
| 37 |
pdf2image
|
| 38 |
ocrmypdf
|
| 39 |
reportlab>=3.6.0
|
|
|
|
| 40 |
|
| 41 |
# --- Image Processing & Formats ---
|
| 42 |
Pillow==10.3.0
|
|
@@ -50,6 +52,9 @@ ExifRead==3.0.0
|
|
| 50 |
defusedxml==0.7.1
|
| 51 |
scikit-image==0.22.0
|
| 52 |
opencv-python-headless==4.9.0.80
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# --- Audio & Speech Processing ---
|
| 55 |
ffmpeg-python==0.2.0
|
|
@@ -57,27 +62,20 @@ pydub
|
|
| 57 |
soundfile
|
| 58 |
librosa
|
| 59 |
matplotlib
|
|
|
|
| 60 |
|
| 61 |
# --- Machine Learning & AI Tools ---
|
| 62 |
rembg
|
| 63 |
onnxruntime
|
| 64 |
faster-whisper
|
| 65 |
openai-whisper
|
| 66 |
-
whisper==1.1.10
|
| 67 |
demucs
|
| 68 |
numpy==1.26.4
|
| 69 |
six==1.17.0
|
| 70 |
dnspython
|
| 71 |
-
dnspython
|
| 72 |
mac-vendor-lookup
|
| 73 |
-
pypdf
|
| 74 |
setuptools
|
| 75 |
python-magic
|
| 76 |
-
|
| 77 |
-
python-barcode
|
| 78 |
-
setuptools
|
| 79 |
celery
|
| 80 |
-
|
| 81 |
-
sqlparse
|
| 82 |
-
xmltodict
|
| 83 |
-
pyloudnorm
|
|
|
|
| 15 |
SQLAlchemy==2.0.30
|
| 16 |
alembic
|
| 17 |
sqladmin==0.15.2
|
| 18 |
+
sqlparse
|
| 19 |
|
| 20 |
# --- Universal Document Converters ---
|
| 21 |
python-docx
|
|
|
|
| 38 |
pdf2image
|
| 39 |
ocrmypdf
|
| 40 |
reportlab>=3.6.0
|
| 41 |
+
pypdf
|
| 42 |
|
| 43 |
# --- Image Processing & Formats ---
|
| 44 |
Pillow==10.3.0
|
|
|
|
| 52 |
defusedxml==0.7.1
|
| 53 |
scikit-image==0.22.0
|
| 54 |
opencv-python-headless==4.9.0.80
|
| 55 |
+
qrcode
|
| 56 |
+
python-barcode
|
| 57 |
+
pytesseract
|
| 58 |
|
| 59 |
# --- Audio & Speech Processing ---
|
| 60 |
ffmpeg-python==0.2.0
|
|
|
|
| 62 |
soundfile
|
| 63 |
librosa
|
| 64 |
matplotlib
|
| 65 |
+
pyloudnorm
|
| 66 |
|
| 67 |
# --- Machine Learning & AI Tools ---
|
| 68 |
rembg
|
| 69 |
onnxruntime
|
| 70 |
faster-whisper
|
| 71 |
openai-whisper
|
|
|
|
| 72 |
demucs
|
| 73 |
numpy==1.26.4
|
| 74 |
six==1.17.0
|
| 75 |
dnspython
|
|
|
|
| 76 |
mac-vendor-lookup
|
|
|
|
| 77 |
setuptools
|
| 78 |
python-magic
|
| 79 |
+
pyjwt
|
|
|
|
|
|
|
| 80 |
celery
|
| 81 |
+
xmltodict
|
|
|
|
|
|
|
|
|
routers/converter_tools.py
CHANGED
|
@@ -72,7 +72,7 @@ async def api_image_to_webp(
|
|
| 72 |
os.replace(output_path, final_path)
|
| 73 |
|
| 74 |
size = os.path.getsize(final_path)
|
| 75 |
-
file_url = f"https://
|
| 76 |
|
| 77 |
return {
|
| 78 |
"url": file_url,
|
|
@@ -136,7 +136,7 @@ async def api_image_to_svg_embed(
|
|
| 136 |
# ---------------------------------------------------
|
| 137 |
# 4️⃣ RETURN URL + SIZE
|
| 138 |
# ---------------------------------------------------
|
| 139 |
-
file_url = f"https://
|
| 140 |
|
| 141 |
return JSONResponse({
|
| 142 |
"url": file_url,
|
|
@@ -199,7 +199,7 @@ async def api_pdf_to_text(
|
|
| 199 |
with open(output_path, "w", encoding="utf-8") as f:
|
| 200 |
f.write(text)
|
| 201 |
|
| 202 |
-
file_url = f"https://
|
| 203 |
|
| 204 |
print("📤 Extracted text saved:", output_path)
|
| 205 |
|
|
|
|
| 72 |
os.replace(output_path, final_path)
|
| 73 |
|
| 74 |
size = os.path.getsize(final_path)
|
| 75 |
+
file_url = f"https://cloudairambo-cloudairambo.hf.space/static/output/{filename}"
|
| 76 |
|
| 77 |
return {
|
| 78 |
"url": file_url,
|
|
|
|
| 136 |
# ---------------------------------------------------
|
| 137 |
# 4️⃣ RETURN URL + SIZE
|
| 138 |
# ---------------------------------------------------
|
| 139 |
+
file_url = f"https://cloudairambo-cloudairambo.hf.space/static/output/{filename}"
|
| 140 |
|
| 141 |
return JSONResponse({
|
| 142 |
"url": file_url,
|
|
|
|
| 199 |
with open(output_path, "w", encoding="utf-8") as f:
|
| 200 |
f.write(text)
|
| 201 |
|
| 202 |
+
file_url = f"https://cloudairambo-cloudairambo.hf.space/static/output/{output_filename}"
|
| 203 |
|
| 204 |
print("📤 Extracted text saved:", output_path)
|
| 205 |
|
routers/image_tools.py
CHANGED
|
@@ -19,7 +19,7 @@ from math import cos, sin, radians
|
|
| 19 |
|
| 20 |
router = APIRouter()
|
| 21 |
|
| 22 |
-
BASE_URL = "https://
|
| 23 |
OUTPUT_DIR = "static/output"
|
| 24 |
UPLOAD_DIR = "static/uploads"
|
| 25 |
TMP_DIR = "/tmp"
|
|
|
|
| 19 |
|
| 20 |
router = APIRouter()
|
| 21 |
|
| 22 |
+
BASE_URL = "https://cloudairambo-cloudairambo.hf.space"
|
| 23 |
OUTPUT_DIR = "static/output"
|
| 24 |
UPLOAD_DIR = "static/uploads"
|
| 25 |
TMP_DIR = "/tmp"
|
routers/pdf.py
CHANGED
|
@@ -864,7 +864,7 @@ async def add_pdf_bookmarks(
|
|
| 864 |
|
| 865 |
# 6️⃣ Return downloadable URL
|
| 866 |
return {
|
| 867 |
-
"url": f"https://
|
| 868 |
}
|
| 869 |
|
| 870 |
|
|
|
|
| 864 |
|
| 865 |
# 6️⃣ Return downloadable URL
|
| 866 |
return {
|
| 867 |
+
"url": f"https://cloudairambo-cloudairambo.hf.space/static/pdf/{output_name}"
|
| 868 |
}
|
| 869 |
|
| 870 |
|
routers/video.py
CHANGED
|
@@ -11,7 +11,7 @@ import asyncio
|
|
| 11 |
|
| 12 |
router = APIRouter()
|
| 13 |
|
| 14 |
-
BASE_URL = "https://
|
| 15 |
UPLOAD_DIR = Path("static/uploads")
|
| 16 |
OUTPUT_DIR = Path("static/output")
|
| 17 |
|
|
|
|
| 11 |
|
| 12 |
router = APIRouter()
|
| 13 |
|
| 14 |
+
BASE_URL = "https://cloudairambo-cloudairambo.hf.space"
|
| 15 |
UPLOAD_DIR = Path("static/uploads")
|
| 16 |
OUTPUT_DIR = Path("static/output")
|
| 17 |
|
services/ads_service.py
CHANGED
|
@@ -9,7 +9,7 @@ from sqlalchemy import func
|
|
| 9 |
|
| 10 |
from core.models import AdUnit, AdPlacement, AdStat, AdImpression, AdGlobalSettings
|
| 11 |
|
| 12 |
-
BASE_URL = "https://
|
| 13 |
|
| 14 |
def whisper_stt(input_path: str, language: str = "en-US") -> str:
|
| 15 |
"""
|
|
|
|
| 9 |
|
| 10 |
from core.models import AdUnit, AdPlacement, AdStat, AdImpression, AdGlobalSettings
|
| 11 |
|
| 12 |
+
BASE_URL = "https://cloudairambo-cloudairambo.hf.space"
|
| 13 |
|
| 14 |
def whisper_stt(input_path: str, language: str = "en-US") -> str:
|
| 15 |
"""
|
status.sh
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
sudo systemctl status backend
|
| 2 |
-
sudo systemctl status celery
|
|
|
|
|
|
|
|
|