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") temp = open("model/t.txt","w") temp.write("aaaaaaaaaaaaa") temp.close() temp = open("model/t.txt","r") app = FastAPI() @app.get("/") def read_root(): output = pipe_flan("hi") return {"message": str(output[0]["generated_text"])} @app.post("/uploadfile/") async def create_upload_file(file: UploadFile = File(...)): try: # Save the file with a specific name file_path = "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)}"}