Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,20 +19,34 @@ def transcribe(audio, text):
|
|
| 19 |
language = 'en'
|
| 20 |
|
| 21 |
transcript = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
if audio:
|
| 23 |
audio_filename_with_extension = audio + '.wav'
|
| 24 |
os.rename(audio, audio_filename_with_extension)
|
| 25 |
audio_file = open(audio_filename_with_extension, "rb")
|
| 26 |
# Transcribe the audio file using the whisper-1 model
|
| 27 |
transcript = openai.audio.transcriptions.create(model="whisper-1", file=audio_file)
|
| 28 |
-
print("Transcription:", transcript)
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
else
|
| 35 |
-
user_input = text
|
| 36 |
|
| 37 |
conversation_tokens = sum(len(message['content'].split()) for message in all_messages)
|
| 38 |
|
|
|
|
| 19 |
language = 'en'
|
| 20 |
|
| 21 |
transcript = {}
|
| 22 |
+
# if audio:
|
| 23 |
+
# audio_filename_with_extension = audio + '.wav'
|
| 24 |
+
# os.rename(audio, audio_filename_with_extension)
|
| 25 |
+
# audio_file = open(audio_filename_with_extension, "rb")
|
| 26 |
+
# # Transcribe the audio file using the whisper-1 model
|
| 27 |
+
# transcript = openai.audio.transcriptions.create(model="whisper-1", file=audio_file)
|
| 28 |
+
# print("Transcription:", transcript)
|
| 29 |
+
# # user_input = transcript("text") if isinstance(transcript, dict) else ""
|
| 30 |
+
# # user_input = transcript.text if isinstance(transcript, dict) else ""
|
| 31 |
+
# user_input = transcript.get("text", "") if isinstance(transcript, dict) else ""
|
| 32 |
+
# user_input = transcript.text
|
| 33 |
+
# print("Transcription:", user_input)
|
| 34 |
+
# else :
|
| 35 |
+
# user_input = text
|
| 36 |
if audio:
|
| 37 |
audio_filename_with_extension = audio + '.wav'
|
| 38 |
os.rename(audio, audio_filename_with_extension)
|
| 39 |
audio_file = open(audio_filename_with_extension, "rb")
|
| 40 |
# Transcribe the audio file using the whisper-1 model
|
| 41 |
transcript = openai.audio.transcriptions.create(model="whisper-1", file=audio_file)
|
| 42 |
+
print("Transcription:", transcript)
|
| 43 |
+
# user_input = transcript("text") if isinstance(transcript, dict) else ""
|
| 44 |
+
# user_input = transcript.text if isinstance(transcript, dict) else ""
|
| 45 |
+
user_input = transcript.get("text", "") if isinstance(transcript, dict) else ""
|
| 46 |
+
user_input = transcript.text
|
| 47 |
+
print("Transcription:", user_input)
|
| 48 |
+
else:
|
| 49 |
+
user_input = text
|
| 50 |
|
| 51 |
conversation_tokens = sum(len(message['content'].split()) for message in all_messages)
|
| 52 |
|