arad1367 commited on
Commit
45685cc
1 Parent(s): c2743f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -69,8 +69,8 @@ def stream_chat(
69
  ):
70
  # Prepare the conversation context
71
  conversation_text = system_prompt + "\n"
72
- for prompt, answer in history:
73
- conversation_text += f"User: {prompt}\nMisMath: {answer}\n"
74
 
75
  conversation_text += f"User: {message}\nMisMath:"
76
 
@@ -95,14 +95,13 @@ def stream_chat(
95
  thread.start()
96
 
97
  buffer = ""
 
98
  for new_text in streamer:
99
  buffer += new_text
100
- # Clean the buffer to remove unwanted prefixes
101
  if "MisMath:" in buffer:
102
- cleaned_text = buffer.split("MisMath:")[-1].strip()
103
- yield cleaned_text
104
- else:
105
- yield buffer.strip()
106
 
107
  # Define the Gradio chatbot component
108
  chatbot = gr.Chatbot(height=500, placeholder=PLACEHOLDER)
 
69
  ):
70
  # Prepare the conversation context
71
  conversation_text = system_prompt + "\n"
72
+ for _, answer in history:
73
+ conversation_text += f"MisMath: {answer}\n"
74
 
75
  conversation_text += f"User: {message}\nMisMath:"
76
 
 
95
  thread.start()
96
 
97
  buffer = ""
98
+ final_output = ""
99
  for new_text in streamer:
100
  buffer += new_text
101
+ # Extract only the final response after the last "MisMath:"
102
  if "MisMath:" in buffer:
103
+ final_output = buffer.split("MisMath:")[-1].strip()
104
+ yield final_output
 
 
105
 
106
  # Define the Gradio chatbot component
107
  chatbot = gr.Chatbot(height=500, placeholder=PLACEHOLDER)