Eriberto commited on
Commit
cd87708
·
1 Parent(s): 786bfcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -18
app.py CHANGED
@@ -1,33 +1,49 @@
1
- from pyChatGPT import ChatGPT
2
  import os
3
- session_token = os.environ.get('SessionToken')
 
 
4
 
5
- print("------------Aqui----------------", session_token)
 
6
 
7
- import whisper
8
  whisper_model = whisper.load_model("small")
9
-
 
 
 
10
 
11
  def chat_hf(audio, custom_token):
12
  try:
13
  whisper_text = translate(audio)
 
 
 
 
 
14
  api = ChatGPT(session_token)
15
  resp = api.send_message(whisper_text)
 
 
 
 
 
16
 
 
 
17
 
18
- api.refresh_auth() # refresh the authorization token
19
- api.reset_conversation() # reset the conversation
20
- gpt_response = resp['message']
21
 
22
  except:
23
- whisper_text = translate(audio)
24
- api = ChatGPT(custom_token)
25
- resp = api.send_message(whisper_text)
26
 
27
 
28
- api.refresh_auth() # refresh the authorization token
29
- api.reset_conversation() # reset the conversation
30
- gpt_response = resp['message']
31
 
32
  return whisper_text, gpt_response
33
 
@@ -46,11 +62,8 @@ def translate(audio):
46
 
47
  _, probs = whisper_model.detect_language(mel)
48
 
49
- transcript_options = whisper.DecodingOptions(task="transcribe", fp16 = False)
50
- #translate_options = whisper.DecodingOptions(task="translate", fp16 = False)
51
-
52
  transcription = whisper.decode(whisper_model, mel, transcript_options)
53
- #translation = whisper.decode(whisper_model, mel, translate_options)
54
 
55
  print("language spoken: " + transcription.language)
56
  print("transcript: " + transcription.text)
 
 
1
  import os
2
+ import openai
3
+ import whisper
4
+ from pyChatGPT import ChatGPT
5
 
6
+ from api_key import API_KEY
7
+ openai.api_key = os.environ.get('SessionToken')
8
 
 
9
  whisper_model = whisper.load_model("small")
10
+
11
+ conversation = ""
12
+ user_name = "MH"
13
+ bot_name = "bbDemo"
14
 
15
  def chat_hf(audio, custom_token):
16
  try:
17
  whisper_text = translate(audio)
18
+
19
+ # Conversation rout
20
+ prompt = user_name + ": " + user_input + "\n" + bot_name+ ": "
21
+ conversation += prompt # allows for context
22
+
23
  api = ChatGPT(session_token)
24
  resp = api.send_message(whisper_text)
25
+
26
+ # fetch the response from open AI api
27
+ response = openai.Completion.create(engine='text-davinci-003', prompt=conversation, max_tokens=100)
28
+ response_str = response["choices"][0]["text"].replace("\n", "")
29
+ response_str = response_str.split(user_name + ": ", 1)[0].split(bot_name + ": ", 1)[0]
30
 
31
+ conversation += response_str + "\n"
32
+
33
 
34
+ #api.refresh_auth() # refresh the authorization token
35
+ #api.reset_conversation() # reset the conversation
36
+ gpt_response = response_str #resp['message']
37
 
38
  except:
39
+ #whisper_text = translate(audio)
40
+ #api = ChatGPT(custom_token)
41
+ #resp = api.send_message(whisper_text)
42
 
43
 
44
+ #api.refresh_auth() # refresh the authorization token
45
+ #api.reset_conversation() # reset the conversation
46
+ #gpt_response = resp['message']
47
 
48
  return whisper_text, gpt_response
49
 
 
62
 
63
  _, probs = whisper_model.detect_language(mel)
64
 
65
+ transcript_options = whisper.DecodingOptions(task="transcribe", fp16 = False)
 
 
66
  transcription = whisper.decode(whisper_model, mel, transcript_options)
 
67
 
68
  print("language spoken: " + transcription.language)
69
  print("transcript: " + transcription.text)