Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,7 @@ from dotenv import load_dotenv
|
|
12 |
|
13 |
from fastapi import FastAPI, File, UploadFile, Form
|
14 |
from fastapi.responses import JSONResponse
|
|
|
15 |
import uvicorn
|
16 |
|
17 |
# Load environment variables
|
@@ -168,6 +169,9 @@ def predict(audio_file_pth, agree):
|
|
168 |
|
169 |
app = FastAPI()
|
170 |
|
|
|
|
|
|
|
171 |
@app.post("/predict")
|
172 |
async def predict_endpoint(agree: bool = Form(...), audio_file: UploadFile = File(...)):
|
173 |
temp_dir = "temp"
|
@@ -178,9 +182,10 @@ async def predict_endpoint(agree: bool = Form(...), audio_file: UploadFile = Fil
|
|
178 |
|
179 |
info, audio_output_path = predict(audio_path, agree)
|
180 |
if audio_output_path:
|
181 |
-
|
|
|
182 |
else:
|
183 |
-
return
|
184 |
|
185 |
if __name__ == "__main__":
|
186 |
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
|
|
|
12 |
|
13 |
from fastapi import FastAPI, File, UploadFile, Form
|
14 |
from fastapi.responses import JSONResponse
|
15 |
+
from fastapi.staticfiles import StaticFiles
|
16 |
import uvicorn
|
17 |
|
18 |
# Load environment variables
|
|
|
169 |
|
170 |
app = FastAPI()
|
171 |
|
172 |
+
# Mount the 'outputs' directory to serve static files
|
173 |
+
app.mount("/outputs", StaticFiles(directory="outputs"), name="outputs")
|
174 |
+
|
175 |
@app.post("/predict")
|
176 |
async def predict_endpoint(agree: bool = Form(...), audio_file: UploadFile = File(...)):
|
177 |
temp_dir = "temp"
|
|
|
182 |
|
183 |
info, audio_output_path = predict(audio_path, agree)
|
184 |
if audio_output_path:
|
185 |
+
audio_url = f"/outputs/{os.path.basename(audio_output_path)}"
|
186 |
+
return {"info": info, "audio_path": audio_url}
|
187 |
else:
|
188 |
+
return {"info": info, "audio_path": None}, 400
|
189 |
|
190 |
if __name__ == "__main__":
|
191 |
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
|