Spaces:
Sleeping
Sleeping
File size: 1,346 Bytes
e058caf feca41c 0b8107d 9b752bf ff9efc0 feca41c d385323 61224f5 0e3d371 d385323 7224b31 d385323 61224f5 e058caf 0e3d371 9b752bf e058caf d385323 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
from fastapi import FastAPI, File, UploadFile
from fastapi.responses import StreamingResponse
import os
import io
from transformers import pipeline
pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
output = pipe_flan("hi")
print(output[0]["generated_text"])
temp = open("model/t.txt","r")
app = FastAPI()
# Define the directory to store uploaded files
UPLOAD_DIR = "/data"
@app.on_event("startup")
def startup_event():
# Check and create the directory if it doesn't exist
os.makedirs(UPLOAD_DIR, exist_ok=True)
print("created")
@app.get("/")
def read_root():
return {"message": temp.read()}
@app.post("/uploadfile/")
async def create_upload_file(file: UploadFile = File(...)):
try:
# Save the file with a specific name
file_path = os.path.join(UPLOAD_DIR, "inputvoice.mp3")
with open(file_path, "wb") as f:
f.write(file.file.read())
# Read the content of the saved file
with open(file_path, "rb") as f:
file_content = f.read()
# Return the content as a streaming response
return StreamingResponse(io.BytesIO(file_content), media_type="audio/mpeg", headers={"Content-Disposition": "inline; filename=inputvoice.mp3"})
except PermissionError as e:
return {"error": f"PermissionError: {str(e)}"}
|