| import gradio as gr | |
| import openai | |
| # Set API Key | |
| openai.api_key = "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" | |
| # Define a function that will use OpenAI's API to transcribe an audio file | |
| def transcribe_audio(inp): | |
| with open(inp.name, 'rb') as file: | |
| transcript = openai.Audio.transcribe("whisper-1", file) | |
| return transcript["text"] | |
| # Define the Gradio interface | |
| iface = gr.Interface(fn=transcribe_audio, | |
| inputs=gr.inputs.Audio(source="microphone", type="filepath", label="Record audio"), | |
| outputs="text") | |
| # Launch the interface | |
| iface.launch(share=True) |