thomasanto7001 commited on
Commit
8ccce0f
·
verified ·
1 Parent(s): e8813fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -36,7 +36,10 @@ def chat_with_audio(user_input, history):
36
  )
37
  }
38
 
39
- messages = [system_prompt] + [{"role": "user", "content": inp} if i % 2 == 0 else {"role": "assistant", "content": inp} for i, inp in enumerate(sum(history, []))]
 
 
 
40
  messages.append({"role": "user", "content": user_input})
41
 
42
  response_text = query_groq(messages)
@@ -46,7 +49,7 @@ def chat_with_audio(user_input, history):
46
  audio_file = f"/tmp/{uuid.uuid4()}.mp3"
47
  tts.save(audio_file)
48
 
49
- return response_text, history + [[user_input, response_text]], audio_file
50
 
51
  # Gradio ChatInterface with audio output
52
  with gr.Blocks(theme="soft") as demo:
@@ -57,10 +60,11 @@ with gr.Blocks(theme="soft") as demo:
57
  state = gr.State([])
58
 
59
  def user_message(user_input, history):
60
- reply, new_history, audio_path = chat_with_audio(user_input, history)
61
- return reply, new_history, audio_path
 
62
 
63
  msg.submit(user_message, [msg, state], [chatbot, state, audio])
64
 
65
  # Launch the app
66
- demo.launch(share=True)
 
36
  )
37
  }
38
 
39
+ messages = [system_prompt]
40
+ for user, assistant in history:
41
+ messages.append({"role": "user", "content": user})
42
+ messages.append({"role": "assistant", "content": assistant})
43
  messages.append({"role": "user", "content": user_input})
44
 
45
  response_text = query_groq(messages)
 
49
  audio_file = f"/tmp/{uuid.uuid4()}.mp3"
50
  tts.save(audio_file)
51
 
52
+ return response_text, audio_file
53
 
54
  # Gradio ChatInterface with audio output
55
  with gr.Blocks(theme="soft") as demo:
 
60
  state = gr.State([])
61
 
62
  def user_message(user_input, history):
63
+ reply, audio_path = chat_with_audio(user_input, history)
64
+ history.append([user_input, reply])
65
+ return history, history, audio_path
66
 
67
  msg.submit(user_message, [msg, state], [chatbot, state, audio])
68
 
69
  # Launch the app
70
+ demo.launch()