from fastapi import FastAPI, File, Form, UploadFile import shutil import os app = FastAPI() if not os.path.exists('./tarun_1234'): os.mkdir('./tarun_1234') hf_token = os.environ['HF_TOKEN'] @app.post("/save_audio") async def save_audio(audio: UploadFile = File(...), path: str = Form(...)): # print('PATH ************************ >>>>>', path) folder_path = path.split('/')[1] count = path.split('/')[-1].split('.')[0] # print('FOLDER PATH ----------->>>>>>>>>>>>>>', folder_path) if not os.path.exists(folder_path): os.mkdir(folder_path) print("Received Audio !!!!!") # Save the audio to the specified path with open(path, "wb") as buffer: shutil.copyfileobj(audio.file, buffer) # url = 'https://hellojarvis-asr-hindi.hf.space/transcribe' # headers = { # 'Authorization': f'Bearer {hf_token}', # 'accept': 'application/json' # } # with open(path, 'rb') as file: # files = {'file': file} # print('*********** Reached Here *******************') # response = requests.post(SERVER_URL, headers=headers, files=files) # if response.status_code == 200: # transcription = response.json() # # return transcription # else: # # return "Failed to transcribe audio", None # if os.path.exists(f'{folder_path}.csv'): # df = pd.read_csv(f'{folder_path}.csv') # else: # df = pd.DataFrame(columns = ['script','response','transcription']) # df1 = pd.DataFrame(l,columns = ['script','response','transcription']) # api.upload_file( # path_or_fileobj=f'{folder_path}/transcription/{folder_path}.csv', # path_in_repo=f"{folder_path}.csv", # repo_id="hellojarvis/agent_test", # repo_type="dataset",) # api.upload_file( # path_or_fileobj=f'{folder_path}/transcription/state_wise_duplicates.csv', # path_in_repo=f"{folder_path}.csv", # repo_id="hellojarvis/agent_test", # repo_type="dataset",) return {"message": "Audio saved successfully"} if __name__ == '__main__': import uvicorn uvicorn.run(app, host="0.0.0.0", port=7860)