import requests import gradio as gr import os import urllib.request from gradio_client import Client hf_link = os.environ['link'] client = Client(hf_link) local_link = os.environ['local_link'] local_api = os.environ['local_api'] local_code = requests.head(local_link).status_code print(local_code) def s2t_hf(source, mic, fi, lang): if source == 'file': in_file = fi else: in_file = mic result = client.predict( in_file, # str (filepath or URL to file) in 'inputs' Audio component "transcribe", # str in 'Task' Radio component True, # bool in 'Return timestamps' Checkbox component api_name="/predict" ) print(result) return result def s2t_local(source, mic, fi, lang): if source == 'file': in_file = fi else: in_file = mic form_data = {"language": lang} files = {'input_file': open(in_file, 'rb')} print(files) response = requests.post(local_api, files=files, data=form_data, timeout=10000) return response.json() def s2t(source, mic, fi, lang): if local_code==200: return s2t_local(source, mic, fi, lang) else: return s2t_hf(source, mic, fi, lang) def update_audio_ui(audio_source: str, input_audio_mic, input_audio_file): mic = audio_source == "microphone" # input_audio_mic.visible = mic # print(type(gr.update(visible=mic, value=None))) return gr.update(visible=mic, value=None), gr.update(visible=not mic, value=None) with gr.Blocks() as demo: gr.Markdown('