|
import json |
|
import whisper |
|
import requests |
|
large_v3 = whisper.load_model("large-v3") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_audio(params): |
|
try: |
|
params = json.loads(params) |
|
except json.JSONDecodeError as e: |
|
return {"error": f"Invalid JSON input: {e.msg} at line {e.lineno} column {e.colno}"} |
|
|
|
audio_files = params.get("urls", []) |
|
|
|
|
|
|
|
solutions=[] |
|
|
|
for audio in audio_files: |
|
result_large = large_v3.transcribe(audio) |
|
text = result_large['text'] |
|
|
|
answer_dict = {} |
|
answer_dict.update({'url':audio, 'answer':text}) |
|
solutions.append(answer_dict) |
|
|
|
|
|
|
|
|
|
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="Hindi 2 Hindi Audio transcription with API Intergration") |
|
application.launch() |