whisper / app.py
yosuke-i's picture
Update app.py
cfb9347 verified
raw
history blame contribute delete
No virus
1.47 kB
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()