arad1367 commited on
Commit
c9f2880
1 Parent(s): ecd62fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -61,18 +61,15 @@ def stream_chat(
61
  print(f'message: {message}')
62
  print(f'history: {history}')
63
 
64
- # Prepare the conversation list
65
- conversation = [
66
- {"role": "system", "content": system_prompt}
67
- ]
68
  for prompt, answer in history:
69
- conversation.append({"role": "user", "content": prompt})
70
- conversation.append({"role": "assistant", "content": answer})
71
 
72
- conversation.append({"role": "user", "content": message})
73
 
74
- # Tokenize the conversation
75
- input_ids = tokenizer(conversation, padding=True, truncation=True, return_tensors="pt").input_ids.to(model.device)
76
 
77
  streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
78
 
@@ -95,10 +92,8 @@ def stream_chat(
95
  for new_text in streamer:
96
  buffer += new_text
97
  yield buffer
98
-
99
-
100
 
101
- chatbot = gr.Chatbot(height=600, placeholder=PLACEHOLDER)
102
 
103
  footer = """
104
  <div style="text-align: center; margin-top: 20px;">
 
61
  print(f'message: {message}')
62
  print(f'history: {history}')
63
 
64
+ # Prepare the conversation as plain text
65
+ conversation_text = system_prompt + "\n"
 
 
66
  for prompt, answer in history:
67
+ conversation_text += f"User: {prompt}\nAssistant: {answer}\n"
 
68
 
69
+ conversation_text += f"User: {message}\n"
70
 
71
+ # Tokenize the conversation text
72
+ input_ids = tokenizer(conversation_text, return_tensors="pt").input_ids.to(model.device)
73
 
74
  streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
75
 
 
92
  for new_text in streamer:
93
  buffer += new_text
94
  yield buffer
 
 
95
 
96
+ chatbot = gr.Chatbot(height=500, placeholder=PLACEHOLDER)
97
 
98
  footer = """
99
  <div style="text-align: center; margin-top: 20px;">