File size: 1,466 Bytes
cf39e54 05708b6 cf39e54 cfb9347 cf39e54 05708b6 84f3509 b44f068 84f3509 05708b6 cfb9347 05708b6 cfb9347 cf39e54 a7a191f 84f3509 a7a191f cf39e54 a7a191f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import gradio as gr
import requests
def extract_first_text(json_data):
return json_data.get('text', '')
def transcribe_audio(file):
api_key = "sk-proj-6J4EfDKmIduACsB38LXlT3BlbkFJSVTYDzfbVeAvbKHp1l1z"
url = "https://api.openai.com/v1/audio/transcriptions"
headers = {
"Authorization": f"Bearer {api_key}"
}
# γγ‘γ€γ«γγγ€γγͺγ’γΌγγ§θͺγΏεγ
with open(file.name, 'rb') as f:
files = {
"file": (file.name, f, 'audio/wav'),
"model": (None, "whisper-1"),
"language": (None, "ja"),
"response_format": (None, "verbose_json"),
"timestamp_granularities": (None, "word")
}
response = requests.post(url, headers=headers, files=files)
print(response)
response_json = response.json()
extract_first_text(response_json)
return extract_first_text(response_json)
with gr.Blocks() as demo:
gr.Markdown("# ι³ε£°ζεθ΅·γγ")
gr.Markdown("ι³ε£°γγ‘γ€γ«γγ’γγγγΌγγγ¦γζεθ΅·γγγ葨瀺γγΎγ")
with gr.Row():
audio_input = gr.File(label="wavγγ‘γ€γ«γγ’γγγγΌγ")
text_output = gr.Textbox(label="ζεθ΅·γγη΅ζ")
transcribe_button = gr.Button("ζεθ΅·γγ")
transcribe_button.click(
fn=transcribe_audio,
inputs=audio_input,
outputs=text_output
)
demo.launch()
|