Royrotem100 commited on
Commit
64f89ac
1 Parent(s): 50b8788

Add DictaLM 2.0 instruct model 000

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -52,7 +52,7 @@ def predict():
52
  formatted_text = f"<s>[INST] {input_text} [/INST]"
53
 
54
  # Tokenize the input
55
- inputs = tokenizer(formatted_text, return_tensors='pt', padding=True, truncation=True)
56
 
57
  # Generate the output
58
  outputs = model.generate(
@@ -68,10 +68,10 @@ def predict():
68
  # Decode the output
69
  prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).replace(formatted_text, '').strip()
70
 
71
- # Remove user input part from the response
72
  if "[/INST]" in prediction:
73
  prediction = prediction.split("[/INST]", 1)[-1].strip()
74
-
75
  return jsonify({"prediction": prediction})
76
 
77
  def run_flask():
@@ -97,6 +97,9 @@ def model_chat(query: Optional[str], history: Optional[History]) -> Tuple[Histor
97
  else:
98
  return history, "Error: Unable to get a response from the model."
99
 
 
 
 
100
 
101
 
102
  with gr.Blocks(css='''
@@ -161,14 +164,10 @@ with gr.Blocks(css='''
161
  chatbot = gr.Chatbot()
162
  query = gr.Textbox(placeholder="讛讻谞住 砖讗诇讛 讘注讘专讬转 (讗讜 讘讗谞讙诇讬转!)", rtl=True)
163
  clear_btn = gr.Button("谞拽讛 砖讬讞讛")
164
-
165
- def respond(query: str, history: History) -> Tuple[History, str, History]:
166
- history, response = model_chat(query, history)
167
- return history, response, history # Return history, response, and state
168
 
169
  demo_state = gr.State([])
170
 
171
  query.submit(respond, [query, demo_state], [chatbot, query, demo_state])
172
- clear_btn.click(clear_session, [], [chatbot, demo_state])
173
 
174
  demo.queue(api_open=False).launch(max_threads=20, share=False, allowed_paths=['logo_am.png'])
 
52
  formatted_text = f"<s>[INST] {input_text} [/INST]"
53
 
54
  # Tokenize the input
55
+ inputs = tokenizer(formatted_text, return_tensors='pt', padding=True, truncation=True, max_length=1024)
56
 
57
  # Generate the output
58
  outputs = model.generate(
 
68
  # Decode the output
69
  prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).replace(formatted_text, '').strip()
70
 
71
+ # Remove the user input part from the response
72
  if "[/INST]" in prediction:
73
  prediction = prediction.split("[/INST]", 1)[-1].strip()
74
+
75
  return jsonify({"prediction": prediction})
76
 
77
  def run_flask():
 
97
  else:
98
  return history, "Error: Unable to get a response from the model."
99
 
100
+ def respond(query: str, history: History) -> Tuple[History, str]:
101
+ history, response = model_chat(query, history)
102
+ return history, response # Return history and response to show the model's response
103
 
104
 
105
  with gr.Blocks(css='''
 
164
  chatbot = gr.Chatbot()
165
  query = gr.Textbox(placeholder="讛讻谞住 砖讗诇讛 讘注讘专讬转 (讗讜 讘讗谞讙诇讬转!)", rtl=True)
166
  clear_btn = gr.Button("谞拽讛 砖讬讞讛")
 
 
 
 
167
 
168
  demo_state = gr.State([])
169
 
170
  query.submit(respond, [query, demo_state], [chatbot, query, demo_state])
171
+ clear_btn.click(clear_session, [], demo_state, chatbot)
172
 
173
  demo.queue(api_open=False).launch(max_threads=20, share=False, allowed_paths=['logo_am.png'])