Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
+
|
| 4 |
+
# Set API Key
|
| 5 |
+
openai.api_key = "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"
|
| 6 |
+
|
| 7 |
+
# Define a function that will use OpenAI's API to transcribe an audio file
|
| 8 |
+
def transcribe_audio(inp):
|
| 9 |
+
with open(inp.name, 'rb') as file:
|
| 10 |
+
transcript = openai.Audio.transcribe("whisper-1", file)
|
| 11 |
+
return transcript["text"]
|
| 12 |
+
|
| 13 |
+
# Define the Gradio interface
|
| 14 |
+
iface = gr.Interface(fn=transcribe_audio,
|
| 15 |
+
inputs=gr.inputs.Audio(source="microphone", type="filepath", label="Record audio"),
|
| 16 |
+
outputs="text")
|
| 17 |
+
|
| 18 |
+
# Launch the interface
|
| 19 |
+
iface.launch(share=True)
|