Spaces:
Sleeping
Sleeping
fredcaixeta commited on
Commit ·
deb0d9d
1
Parent(s): cff45a2
go
Browse files- Dockerfile +4 -1
- app.py +6 -23
Dockerfile
CHANGED
|
@@ -12,4 +12,7 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 12 |
|
| 13 |
COPY . .
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
COPY . .
|
| 14 |
|
| 15 |
+
RUN --mount=type=secret,id=WORKING_PY_CONTENT \
|
| 16 |
+
cat /run/secrets/WORKING_PY_CONTENT > working.py
|
| 17 |
+
|
| 18 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -1,28 +1,11 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import importlib.util
|
| 3 |
-
import sys
|
| 4 |
from fastapi import FastAPI, HTTPException
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from fastapi.responses import FileResponse
|
| 7 |
from fastapi.staticfiles import StaticFiles
|
| 8 |
from pydantic import BaseModel
|
|
|
|
| 9 |
|
| 10 |
-
# --- 1.
|
| 11 |
-
working_py_content = os.getenv("WORKING_PY_CONTENT")
|
| 12 |
-
if not working_py_content:
|
| 13 |
-
raise RuntimeError("A variável de ambiente WORKING_PY_CONTENT não está definida.")
|
| 14 |
-
|
| 15 |
-
with open("working.py", "w") as f:
|
| 16 |
-
f.write(working_py_content)
|
| 17 |
-
|
| 18 |
-
# --- 2. IMPORTAR DINAMICAMENTE O MÓDULO ---
|
| 19 |
-
spec = importlib.util.spec_from_file_location("working", "working.py")
|
| 20 |
-
working = importlib.util.module_from_spec(spec)
|
| 21 |
-
sys.modules["working"] = working
|
| 22 |
-
spec.loader.exec_module(working)
|
| 23 |
-
main = working.main
|
| 24 |
-
|
| 25 |
-
# --- 3. SETUP DO FASTAPI ---
|
| 26 |
app = FastAPI(
|
| 27 |
title="Audio Classifier API",
|
| 28 |
description="Uma API para classificar áudios como 'REAL' ou 'IA'."
|
|
@@ -38,11 +21,11 @@ app.add_middleware(
|
|
| 38 |
|
| 39 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 40 |
|
| 41 |
-
# ---
|
| 42 |
class URLPayload(BaseModel):
|
| 43 |
url: str
|
| 44 |
|
| 45 |
-
# ---
|
| 46 |
@app.post("/api/classify")
|
| 47 |
def classify_audio(payload: URLPayload):
|
| 48 |
try:
|
|
@@ -53,7 +36,7 @@ def classify_audio(payload: URLPayload):
|
|
| 53 |
except Exception as e:
|
| 54 |
raise HTTPException(status_code=500, detail=f"Erro interno: {e}")
|
| 55 |
|
| 56 |
-
# ---
|
| 57 |
@app.get("/", response_class=FileResponse)
|
| 58 |
def home():
|
| 59 |
-
return "./static/index.html"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from fastapi.responses import FileResponse
|
| 4 |
from fastapi.staticfiles import StaticFiles
|
| 5 |
from pydantic import BaseModel
|
| 6 |
+
from working import main
|
| 7 |
|
| 8 |
+
# --- 1. SETUP DO FASTAPI ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
app = FastAPI(
|
| 10 |
title="Audio Classifier API",
|
| 11 |
description="Uma API para classificar áudios como 'REAL' ou 'IA'."
|
|
|
|
| 21 |
|
| 22 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 23 |
|
| 24 |
+
# --- 2. MODELO DE DADOS ---
|
| 25 |
class URLPayload(BaseModel):
|
| 26 |
url: str
|
| 27 |
|
| 28 |
+
# --- 3. ROTA DE CLASSIFICAÇÃO ---
|
| 29 |
@app.post("/api/classify")
|
| 30 |
def classify_audio(payload: URLPayload):
|
| 31 |
try:
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
raise HTTPException(status_code=500, detail=f"Erro interno: {e}")
|
| 38 |
|
| 39 |
+
# --- 4. ROTA DE SAÚDE ---
|
| 40 |
@app.get("/", response_class=FileResponse)
|
| 41 |
def home():
|
| 42 |
+
return "./static/index.html"
|