janasumit2911 commited on
Commit
4bcca58
·
verified ·
1 Parent(s): 6ca66c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -4,39 +4,39 @@ import requests
4
 
5
  large_multi = whisper.load_model("large-v3")
6
 
7
- def send_results_to_api(data, result_url):
8
- headers = {"Content-Type":"application/json"}
9
- response = requests.post(result_url, json= data, headers=headers)
10
 
11
- if response.status_code == 200:
12
- return response.json()
13
- else:
14
- return {"error": f"Failed to send results to API: {response.status_code}"}
15
 
16
  def process_audio(params):
17
  solutions=[]
18
 
19
  params = json.loads(params)
20
 
21
- audio_files = params.get("audio_files",[])
22
- api = params.get("api", "")
23
- job_id = params.get("job_id", "")
24
 
25
  for audio in audio_files:
26
  result_multi = large_multi.transcribe(audio)
27
  text = result_multi['text']
28
 
29
  answer_dict = {}
30
- answer_dict.update({'file_name':audio, 'text':text})
31
  solutions.append(answer_dict)
32
 
33
- result_url = f"{api}/{job_id}"
34
  # send_results_to_api(solutions, result_url)
35
- return json.dumps({"solutions":solutions}, indent=4)
36
 
37
  import gradio as gr
38
  inputt = gr.Textbox(label = "Parameter in json format Eg. {'audio_files':['file1.mp3','file2.wav'], 'api':'https://api.example.com', 'job_id':'1001'}")
39
  outputt = gr.JSON()
40
 
41
  application = gr.Interface(fn=process_audio, inputs = inputt, outputs= outputt, title="Hindi 2 Hindi Audio transcription with API Intergration")
42
- application.launch(share=True)
 
4
 
5
  large_multi = whisper.load_model("large-v3")
6
 
7
+ # def send_results_to_api(data, result_url):
8
+ # headers = {"Content-Type":"application/json"}
9
+ # response = requests.post(result_url, json= data, headers=headers)
10
 
11
+ # if response.status_code == 200:
12
+ # return response.json()
13
+ # else:
14
+ # return {"error": f"Failed to send results to API: {response.status_code}"}
15
 
16
  def process_audio(params):
17
  solutions=[]
18
 
19
  params = json.loads(params)
20
 
21
+ audio_files = params.get("urls",[])
22
+ # api = params.get("api", "")
23
+ # job_id = params.get("job_id", "")
24
 
25
  for audio in audio_files:
26
  result_multi = large_multi.transcribe(audio)
27
  text = result_multi['text']
28
 
29
  answer_dict = {}
30
+ answer_dict.update({'url':audio, 'answer':text})
31
  solutions.append(answer_dict)
32
 
33
+ # result_url = f"{api}/{job_id}"
34
  # send_results_to_api(solutions, result_url)
35
+ return json.dumps({"solutions":solutions})
36
 
37
  import gradio as gr
38
  inputt = gr.Textbox(label = "Parameter in json format Eg. {'audio_files':['file1.mp3','file2.wav'], 'api':'https://api.example.com', 'job_id':'1001'}")
39
  outputt = gr.JSON()
40
 
41
  application = gr.Interface(fn=process_audio, inputs = inputt, outputs= outputt, title="Hindi 2 Hindi Audio transcription with API Intergration")
42
+ application.launch()