asescodes commited on
Commit
83ef9c1
1 Parent(s): ef38aee

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ from gradio.components import Textbox,Audio,Radio
4
+
5
+ def transcribe_or_translate(api_key, audio_file, task):
6
+ openai.api_key = api_key
7
+ with open(audio_file, 'rb') as f:
8
+ if task == 'Transcription':
9
+ text = openai.Audio.transcribe("whisper-1", f)
10
+ elif task == 'Translation':
11
+ text = openai.Audio.translate("whisper-1", f)
12
+ return text.text
13
+
14
+ # Input interface
15
+ api_key = Textbox(label='Enter your OpenAI API key')
16
+ audio_file = Audio(label='Upload audio file', type='filepath')
17
+ task = Radio(['Transcription', 'Translation'], label='Choose a task')
18
+
19
+ # Output interface
20
+ output_text = Textbox(label='Transcribed/Translated text')
21
+
22
+ # Define the Gradio app
23
+ app = gr.Interface(fn=transcribe_or_translate,
24
+ inputs=[api_key, audio_file, task],
25
+ outputs=output_text,
26
+ title='OpenAI Audio Transcription and Translation',
27
+ description='Upload an audio file and choose a task to get started.')
28
+
29
+ # Run the app
30
+ app.launch()