JaweriaGenAI commited on
Commit
188e69e
·
verified ·
1 Parent(s): 19ae010

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -12
app.py CHANGED
@@ -24,23 +24,20 @@ def chat_with_bot(message, history):
24
  global chat_history
25
  chat_history = history or []
26
 
27
- # Append user message to chat history
28
  chat_history.append({"role": "user", "content": message})
29
 
30
- # Call Groq LLM
31
  response = client.chat.completions.create(
32
  model="llama3-8b-8192",
33
  messages=chat_history
34
  )
35
-
36
  reply = response.choices[0].message.content
37
 
38
- # Append assistant reply to chat history
39
  chat_history.append({"role": "assistant", "content": reply})
40
 
41
- # Prepare output format for Gradio (list of tuples)
42
- formatted_history = [(m['content'], chat_history[i+1]['content']) for i, m in enumerate(chat_history[:-1]) if m['role'] == 'user']
43
- return formatted_history, chat_history
44
 
45
  def transcribe_audio(audio_file):
46
  if audio_file is None:
@@ -55,7 +52,7 @@ def transcribe_audio(audio_file):
55
  with gr.Blocks() as demo:
56
  gr.Markdown("# 🤖 Neobot - Chat with Voice, File & Text")
57
 
58
- chatbot = gr.Chatbot()
59
  state = gr.State([])
60
 
61
  with gr.Row():
@@ -63,13 +60,10 @@ with gr.Blocks() as demo:
63
  send_btn = gr.Button("Send")
64
 
65
  with gr.Row():
66
- audio_upload = gr.Audio(source="upload", type="filepath", label="Upload Audio")
67
  transcribe_btn = gr.Button("Transcribe Audio")
68
 
69
- # Chat event
70
  send_btn.click(chat_with_bot, inputs=[txt, state], outputs=[chatbot, state])
71
-
72
- # Audio transcription event
73
  transcribe_btn.click(transcribe_audio, inputs=audio_upload, outputs=txt)
74
 
75
  demo.launch()
 
24
  global chat_history
25
  chat_history = history or []
26
 
27
+ # Append user message
28
  chat_history.append({"role": "user", "content": message})
29
 
30
+ # Get model response
31
  response = client.chat.completions.create(
32
  model="llama3-8b-8192",
33
  messages=chat_history
34
  )
 
35
  reply = response.choices[0].message.content
36
 
37
+ # Append assistant reply
38
  chat_history.append({"role": "assistant", "content": reply})
39
 
40
+ return chat_history, chat_history
 
 
41
 
42
  def transcribe_audio(audio_file):
43
  if audio_file is None:
 
52
  with gr.Blocks() as demo:
53
  gr.Markdown("# 🤖 Neobot - Chat with Voice, File & Text")
54
 
55
+ chatbot = gr.Chatbot(type="messages", label="Chat")
56
  state = gr.State([])
57
 
58
  with gr.Row():
 
60
  send_btn = gr.Button("Send")
61
 
62
  with gr.Row():
63
+ audio_upload = gr.Audio(type="filepath", label="Upload Audio") # Removed `source=`
64
  transcribe_btn = gr.Button("Transcribe Audio")
65
 
 
66
  send_btn.click(chat_with_bot, inputs=[txt, state], outputs=[chatbot, state])
 
 
67
  transcribe_btn.click(transcribe_audio, inputs=audio_upload, outputs=txt)
68
 
69
  demo.launch()