|
import gradio as gr |
|
import numpy as np |
|
import runpod |
|
import os |
|
|
|
RUNPOD_API = os.environ.get("RUNPOD_API") |
|
RUNPOD_ENDPOINT = os.environ.get("RUNPOD_ENDPOINT") |
|
auth = [(os.environ.get("ADMIN"), os.environ.get("ADMIN_PW")), (os.environ.get("USER"), os.environ.get("USER_PW"))] |
|
|
|
|
|
def welcome_user(request: gr.Request): |
|
return f"Bienvenue {request.username}" |
|
|
|
def doDebug(request: gr.Request): |
|
if request.username == os.environ.get("ADMIN"): |
|
return gr.Textbox(label="Debug Transcription", visible=True) |
|
return gr.Textbox(label="Debug Transcription", visible=False) |
|
|
|
def process_transcribe(file): |
|
audio_nparray = file[1] |
|
audio_list = audio_nparray.tolist() |
|
|
|
runpod.api_key = RUNPOD_API |
|
endpoint = runpod.Endpoint(RUNPOD_ENDPOINT) |
|
|
|
run_request = endpoint.run_sync( |
|
{"audio_list": audio_list} |
|
) |
|
raw_text = run_request |
|
text_corrected = raw_text["text_corrected"] |
|
return raw_text,text_corrected |
|
|
|
with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as iface: |
|
m = gr.Markdown(value="bienvenue") |
|
iface.load(welcome_user, None, m) |
|
with gr.Tab("Speech2text prescription"): |
|
with gr.Row(): |
|
with gr.Column(): |
|
audio_file = gr.Audio(sources=["upload"], type="numpy", label="Audio") |
|
submit_btn = gr.Button("Submit", variant="primary") |
|
with gr.Column(): |
|
debug_transcript = gr.Textbox() |
|
iface.load(doDebug, None, debug_transcript) |
|
transcript = gr.Textbox(label="Transcription") |
|
submit_btn.click(process_transcribe, inputs=[audio_file], outputs=[debug_transcript,transcript]) |
|
logout_button = gr.Button("Logout", link="/logout") |
|
iface.launch(auth=auth) |