mrolando commited on
Commit
56cf024
1 Parent(s): 17295b2

added state

Browse files
Files changed (2) hide show
  1. __pycache__/tts.cpython-310.pyc +0 -0
  2. app.py +25 -11
__pycache__/tts.cpython-310.pyc CHANGED
Binary files a/__pycache__/tts.cpython-310.pyc and b/__pycache__/tts.cpython-310.pyc differ
 
app.py CHANGED
@@ -28,17 +28,24 @@ def transcribe_speech(filepath):
28
  load_dotenv()
29
  openai.api_key = os.environ['OPENAI_API_KEY']
30
 
31
- def query_chatgpt(text):
32
- messages = []
33
- messages.append({'role': 'user', 'content': '{}'.format(text)})
34
- print("Preguntando "+text)
 
 
 
 
 
 
35
  response = openai.ChatCompletion.create(
36
  model="gpt-3.5-turbo",
37
- messages= messages,
38
  temperature=0.5,
39
  max_tokens=256
40
  ).choices[0].message.content
41
- return response
 
42
 
43
 
44
 
@@ -65,22 +72,29 @@ from tts import synthesize
65
  # wav,rate = TTSHubInterface.get_prediction(task, model, generator, sample)
66
  # return wav,rate
67
 
68
- def answer_question(filepath):
69
  transcription = transcribe_speech(filepath)
70
- response = query_chatgpt(transcription)
 
71
  # audio = synthesise(response)
72
- print(response)
73
  # audio, rate = syn_facebookmms(response)
74
  rate,audio = synthesize(response,1,"spa")
75
  print(audio)
76
  return rate,audio
77
 
 
 
 
 
78
 
79
  import gradio as gr
80
  with gr.Blocks() as demo:
 
81
  entrada = gr.Audio(source="microphone",type="filepath")
82
  boton = gr.Button("Responder")
83
-
84
  salida = gr.Audio()
85
- boton.click(answer_question,entrada,salida)
 
 
86
  demo.launch(debug=True)
 
28
  load_dotenv()
29
  openai.api_key = os.environ['OPENAI_API_KEY']
30
 
31
+
32
+ def clear_chat():
33
+ global chat_history
34
+ chat_history=[]
35
+
36
+
37
+ def query_chatgpt(message,chat_history):
38
+ chat_history.append({'role': 'user', 'content': '{}'.format(message)})
39
+ print("Preguntando "+message)
40
+ print("historial", chat_history)
41
  response = openai.ChatCompletion.create(
42
  model="gpt-3.5-turbo",
43
+ messages= chat_history,
44
  temperature=0.5,
45
  max_tokens=256
46
  ).choices[0].message.content
47
+ chat_history.append({'role': 'assistant', 'content': '{}'.format(response)})
48
+ return response, chat_history
49
 
50
 
51
 
 
72
  # wav,rate = TTSHubInterface.get_prediction(task, model, generator, sample)
73
  # return wav,rate
74
 
75
+ def answer_question(filepath,chat_history):
76
  transcription = transcribe_speech(filepath)
77
+ response,chat_history = query_chatgpt(transcription,chat_history)
78
+ print("historial",chat_history)
79
  # audio = synthesise(response)
 
80
  # audio, rate = syn_facebookmms(response)
81
  rate,audio = synthesize(response,1,"spa")
82
  print(audio)
83
  return rate,audio
84
 
85
+ def reset_state(chat_history):
86
+ chat_history = []
87
+ return chat_history
88
+
89
 
90
  import gradio as gr
91
  with gr.Blocks() as demo:
92
+ chat_history = gr.State([])
93
  entrada = gr.Audio(source="microphone",type="filepath")
94
  boton = gr.Button("Responder")
95
+ button = gr.Button("Reset State")
96
  salida = gr.Audio()
97
+ boton.click(answer_question,[entrada,chat_history],salida)
98
+ button.click(reset_state,chat_history,chat_history)
99
+
100
  demo.launch(debug=True)