futurespyhi commited on
Commit
6cfc4a3
·
1 Parent(s): 921388c

updata gradio logic: trying to solve generation error of current lyrics

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -550,12 +550,10 @@ def respond(message, state):
550
  if any(marker in response.lower() for marker in ["[verse", "[chorus", "[bridge"]):
551
  state.lyrics = response
552
 
553
- # Return conversation for display
554
  conversation_display = []
555
  for msg in state.conversation:
556
- role = "User" if msg["role"] == "user" else "Assistant"
557
- conversation_display.append([msg["content"] if msg["role"] == "user" else None,
558
- msg["content"] if msg["role"] == "assistant" else None])
559
 
560
  return "", conversation_display, state
561
 
@@ -563,11 +561,10 @@ def respond(message, state):
563
  error_response = f"Sorry, I encountered an error: {str(e)}"
564
  state.conversation.append({"role": "assistant", "content": error_response})
565
 
566
- # Format conversation for display
567
  conversation_display = []
568
  for msg in state.conversation:
569
- conversation_display.append([msg["content"] if msg["role"] == "user" else None,
570
- msg["content"] if msg["role"] == "assistant" else None])
571
 
572
  return "", conversation_display, state
573
 
@@ -633,7 +630,7 @@ def build_interface():
633
  # Chat interface
634
  with gr.Group():
635
  gr.Markdown("### 💬 Lyrics Creation Chat")
636
- chatbot = gr.Chatbot(height=400, label="AI Lyrics Assistant", show_copy_button=True)
637
 
638
  with gr.Row():
639
  text_input = gr.Textbox(
@@ -868,11 +865,10 @@ def response_audio(state: AppState, audio: tuple, genre_value, mood_value, theme
868
 
869
  os.remove(file_name)
870
 
871
- # Format conversation for display
872
  conversation_display = []
873
  for msg in state.conversation:
874
- conversation_display.append([msg["content"] if msg["role"] == "user" else None,
875
- msg["content"] if msg["role"] == "assistant" else None])
876
 
877
  return state, conversation_display
878
 
 
550
  if any(marker in response.lower() for marker in ["[verse", "[chorus", "[bridge"]):
551
  state.lyrics = response
552
 
553
+ # Return conversation for display in messages format
554
  conversation_display = []
555
  for msg in state.conversation:
556
+ conversation_display.append({"role": msg["role"], "content": msg["content"]})
 
 
557
 
558
  return "", conversation_display, state
559
 
 
561
  error_response = f"Sorry, I encountered an error: {str(e)}"
562
  state.conversation.append({"role": "assistant", "content": error_response})
563
 
564
+ # Format conversation for display in messages format
565
  conversation_display = []
566
  for msg in state.conversation:
567
+ conversation_display.append({"role": msg["role"], "content": msg["content"]})
 
568
 
569
  return "", conversation_display, state
570
 
 
630
  # Chat interface
631
  with gr.Group():
632
  gr.Markdown("### 💬 Lyrics Creation Chat")
633
+ chatbot = gr.Chatbot(height=400, label="AI Lyrics Assistant", show_copy_button=True, type="messages")
634
 
635
  with gr.Row():
636
  text_input = gr.Textbox(
 
865
 
866
  os.remove(file_name)
867
 
868
+ # Format conversation for display in messages format
869
  conversation_display = []
870
  for msg in state.conversation:
871
+ conversation_display.append({"role": msg["role"], "content": msg["content"]})
 
872
 
873
  return state, conversation_display
874