davila7 commited on
Commit
7ceb8a6
1 Parent(s): 42c5809
Files changed (2) hide show
  1. app.py +43 -43
  2. audio.mp3 +0 -0
app.py CHANGED
@@ -67,59 +67,59 @@ if user_secret:
67
 
68
  # Whisper
69
  output = model.transcribe("audio.mp3")
70
- if(output):
71
  user_audio = output['text']
72
  user_input = st.text_area("Message (You can edit the text if you want)", user_audio)
73
  button_run = st.button("Run")
74
 
75
- if(button_run):
76
- openai.api_key = user_secret
77
- response = openai.ChatCompletion.create(
78
- model="gpt-3.5-turbo-0613",
79
- messages=[
80
- {"role": "user", "content": user_input}],
81
- functions=[
82
- {
83
- "name": "send_email",
84
- "description": "Sends an email to a person",
85
- "parameters": {
86
- "type": "object",
87
- "properties": {
88
- "email": {
89
- "type": "string",
90
- "description": "A person to send the email",
91
- },
92
- "body": {"type": "string"},
93
- "subject": {"type": "string"},
94
  },
 
 
95
  },
96
- }
97
- ],
98
- function_call="auto",
99
- )
100
- message = response["choices"][0]["message"]
101
- st.write('GPT: ', message)
 
102
 
103
- if message.get("function_call"):
104
- function_name = message["function_call"]["name"]
105
- st.write('function_name: ', function_name)
106
 
107
- if(function_name == 'send_email'):
108
- # Access the arguments
109
- arguments = json.loads(message['function_call']['arguments'])
110
- email_arg = arguments['email']
111
- body_arg = arguments['body']
112
 
113
- if(arguments['subject']):
114
- arguments['subject'] = 'GPT Email'
115
 
116
- subject_arg = arguments['subject']
117
 
118
- # Step 3, call the function
119
- function_response = send_email(
120
- email_arg, subject_arg, body_arg
121
- )
122
- st.write('Function Send Email:')
123
- st.write(function_response)
124
  else:
125
  st.warning('Paste your OpenAI API Key to continue')
 
67
 
68
  # Whisper
69
  output = model.transcribe("audio.mp3")
70
+ with st.spinner('Wait for it...'):
71
  user_audio = output['text']
72
  user_input = st.text_area("Message (You can edit the text if you want)", user_audio)
73
  button_run = st.button("Run")
74
 
75
+ if(button_run):
76
+ openai.api_key = user_secret
77
+ response = openai.ChatCompletion.create(
78
+ model="gpt-3.5-turbo-0613",
79
+ messages=[
80
+ {"role": "user", "content": user_input}],
81
+ functions=[
82
+ {
83
+ "name": "send_email",
84
+ "description": "Sends an email to a person",
85
+ "parameters": {
86
+ "type": "object",
87
+ "properties": {
88
+ "email": {
89
+ "type": "string",
90
+ "description": "A person to send the email",
 
 
 
91
  },
92
+ "body": {"type": "string"},
93
+ "subject": {"type": "string"},
94
  },
95
+ },
96
+ }
97
+ ],
98
+ function_call="auto",
99
+ )
100
+ message = response["choices"][0]["message"]
101
+ st.write('GPT: ', message)
102
 
103
+ if message.get("function_call"):
104
+ function_name = message["function_call"]["name"]
105
+ st.write('function_name: ', function_name)
106
 
107
+ if(function_name == 'send_email'):
108
+ # Access the arguments
109
+ arguments = json.loads(message['function_call']['arguments'])
110
+ email_arg = arguments['email']
111
+ body_arg = arguments['body']
112
 
113
+ if(arguments['subject']):
114
+ arguments['subject'] = 'GPT Email'
115
 
116
+ subject_arg = arguments['subject']
117
 
118
+ # Step 3, call the function
119
+ function_response = send_email(
120
+ email_arg, subject_arg, body_arg
121
+ )
122
+ st.write('Function Send Email:')
123
+ st.write(function_response)
124
  else:
125
  st.warning('Paste your OpenAI API Key to continue')
audio.mp3 CHANGED
Binary files a/audio.mp3 and b/audio.mp3 differ