File size: 1,580 Bytes
6900907
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f84c80
e7c9bcd
9f84c80
fbd2da5
6900907
 
 
5a5e9e5
6900907
 
 
 
5a5e9e5
6900907
 
 
 
 
 
 
 
 
 
6329b09
6900907
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
import json
import whisper
import requests

large_multi = whisper.load_model("large-v3")

# def send_results_to_api(data, result_url):
#     headers = {"Content-Type":"application/json"}
#     response = requests.post(result_url, json= data, headers=headers)

#     if response.status_code == 200:
#         return response.json()
#     else:
#         return {"error": f"Failed to send results to API: {response.status_code}"}

def process_audio(params):
    solutions=[]

    params = json.loads(params)

    audio_files = params.get("urls",[])
    if not params.get("normalfileID",[]):
        file_ids = [None]*len(audio_files)
    else:
        file_ids = params.get("normalfileID",[])
    # api = params.get("api", "")
    # job_id = params.get("job_id", "")

    for audio, file_id in zip(audio_files,file_ids):
        result_multi = large_multi.transcribe(audio)
        text = result_multi['text']

        answer_dict = {}
        answer_dict.update({'url':audio, 'answer':text, "qcUser": None, "normalfileID": file_id})
        solutions.append(answer_dict)

    # result_url = f"{api}/{job_id}"
    # send_results_to_api(solutions, result_url)
    return json.dumps({"solutions":solutions})

import gradio as gr
inputt = gr.Textbox(label = "Parameter in json format   Eg. {'audio_files':['file1.mp3','file2.wav'], 'api':'https://api.example.com', 'job_id':'1001'}")
outputt = gr.JSON()

application = gr.Interface(fn=process_audio, inputs = inputt, outputs= outputt, title="Multilingual (Hindi/English) Audio transcription with API Intergration")
application.launch()