Adityadn commited on
Commit
a98d34a
·
verified ·
1 Parent(s): aabd712

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -73,35 +73,35 @@
73
 
74
  import requests
75
  import gradio as gr
 
76
 
77
  def recognize_audio(url, file):
78
  api_url = os.environ.get('API_URL')
79
  api_token = os.environ.get('API_TOKEN')
80
  data = os.environ.get('DATA')
81
-
82
  if url:
83
  data['url'] = url
84
- elif file:
85
- files = {'file': (file.name, open(file.name, 'rb'))}
86
- result = requests.post(api_url, data=data, files=files)
87
  return result.text
 
 
 
 
 
88
  else:
89
- return "Silakan masukkan URL atau unggah file audio."
90
-
91
- result = requests.post(api_url, data=data)
92
- return result.text
93
 
94
  interface = gr.Interface(
95
  fn=recognize_audio,
96
  inputs=[
97
- gr.Textbox(label="Masukkan URL Audio", placeholder="https://example.com/audio.mp3"),
98
- gr.File(label="Unggah File Audio")
99
  ],
100
- outputs=gr.Textbox(label="Hasil Pengenalan"),
101
  title="Audio Recognition",
102
- description="Upload audio/video or enter a URL to identify."
103
  )
104
 
105
  if __name__ == "__main__":
106
  interface.launch()
107
-
 
73
 
74
  import requests
75
  import gradio as gr
76
+ import os
77
 
78
  def recognize_audio(url, file):
79
  api_url = os.environ.get('API_URL')
80
  api_token = os.environ.get('API_TOKEN')
81
  data = os.environ.get('DATA')
82
+
83
  if url:
84
  data['url'] = url
85
+ result = requests.post(api_url, data=data)
 
 
86
  return result.text
87
+ elif file:
88
+ with open(file.name, 'rb') as f:
89
+ files = {'file': (file.name, f)}
90
+ result = requests.post(api_url, data=data, files=files)
91
+ return result.text
92
  else:
93
+ return "Please enter a URL or upload an audio file."
 
 
 
94
 
95
  interface = gr.Interface(
96
  fn=recognize_audio,
97
  inputs=[
98
+ gr.Textbox(label="Enter Audio URL", placeholder="https://example.com/audio.mp3"),
99
+ gr.File(label="Upload Audio File")
100
  ],
101
+ outputs=gr.Textbox(label="Recognition Result"),
102
  title="Audio Recognition",
103
+ description="Upload an audio/video file or enter a URL to identify it."
104
  )
105
 
106
  if __name__ == "__main__":
107
  interface.launch()