|
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("S2S_USER"), os.environ.get("S2S_PW")), (os.environ.get("POSOS_USER"), os.environ.get("POSOS_PW"))] |
|
|
|
def update_message(request: gr.Request): |
|
return f"Welcome, {request.username}" |
|
|
|
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 |
|
|
|
return raw_text |
|
|
|
with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as iface: |
|
m = gr.Markdown() |
|
iface.load(update_message, None, m) |
|
logout_button = gr.Button("Logout", link="/logout") |
|
with gr.Tab("Speech2text prescription"): |
|
with gr.Row(): |
|
with gr.Column(): |
|
audio_file = gr.Audio(sources=["upload", "microphone"], type="numpy", label="Audio") |
|
submit_btn = gr.Button("Submit", variant="primary") |
|
with gr.Column(): |
|
raw_transcript = gr.Textbox(label="Transcription") |
|
submit_btn.click(process_transcribe, inputs=[audio_file], outputs=[raw_transcript]) |
|
iface.launch(auth=auth) |