Spaces:
Running
Running
File size: 2,305 Bytes
8387f59 e139a31 b22ed7b 8387f59 5fbd44e 88c274c ae5b42b e139a31 d29766c b808ab6 8387f59 b808ab6 bcdc9c1 bc66078 b808ab6 dd11414 d29766c bc66078 dd11414 bcdc9c1 8387f59 5fbd44e f185e86 4117f61 d29766c 4117f61 d29766c 4117f61 d29766c b808ab6 d29766c 5fbd44e 8387f59 5fbd44e 8387f59 |
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
from fastapi import FastAPI, File, Form, UploadFile
import shutil
import os
from huggingface_hub import HfApi,HfFileSystem
app = FastAPI()
if not os.path.exists('./tarun_1234'):
os.mkdir('./tarun_1234')
hf_token = os.environ['HF_TOKEN']
api = HfApi(token = hf_token)
@app.post("/save_audio")
async def save_audio(audio: UploadFile = File(...), path: str = Form(...), script_name: str = Form(...)):
# print('PATH ************************ >>>>>', path)
folder_path = path.split('/')[1]
filename = path.split('/')[-1]
# script_name = script_name
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=path,
path_in_repo=f"{folder_path}/{script_name}/{filename}",
repo_id="hellojarvis/agent_data",
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)
|