Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
|
|
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
|
|
@@ -8,10 +11,21 @@ app.add_middleware(
|
|
| 8 |
allow_origins=['*']
|
| 9 |
)
|
| 10 |
|
|
|
|
| 11 |
@app.get("/")
|
| 12 |
def read_root():
|
| 13 |
return {"message": "Hello World"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
return {"message": "Hello Python"}
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile
|
| 2 |
+
from fastapi.responses import StreamingResponse
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
import os
|
| 5 |
+
import io
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
|
|
| 11 |
allow_origins=['*']
|
| 12 |
)
|
| 13 |
|
| 14 |
+
|
| 15 |
@app.get("/")
|
| 16 |
def read_root():
|
| 17 |
return {"message": "Hello World"}
|
| 18 |
+
|
| 19 |
+
@app.post("/uploadfile/")
|
| 20 |
+
async def create_upload_file(file: UploadFile = File(...)):
|
| 21 |
+
# Save the file with a specific name
|
| 22 |
+
file_path = "inputvoice.mp3"
|
| 23 |
+
with open(file_path, "wb") as f:
|
| 24 |
+
f.write(file.file.read())
|
| 25 |
+
|
| 26 |
+
# Read the content of the saved file
|
| 27 |
+
with open(file_path, "rb") as f:
|
| 28 |
+
file_content = f.read()
|
| 29 |
|
| 30 |
+
# Return the content as a streaming response
|
| 31 |
+
return StreamingResponse(io.BytesIO(file_content), media_type="audio/mpeg", headers={"Content-Disposition": "inline; filename=inputvoice.mp3"})
|
|
|