Spaces:
Runtime error
Runtime error
Commit 路
db01461
1
Parent(s): 9347b88
Add DictaLM 2.0 instruct model
Browse files
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')
|
| 56 |
|
| 57 |
# Generate the output
|
| 58 |
outputs = model.generate(
|
|
@@ -83,6 +83,8 @@ def is_hebrew(text: str) -> bool:
|
|
| 83 |
|
| 84 |
# Run Flask in a separate thread
|
| 85 |
threading.Thread(target=run_flask).start()
|
|
|
|
|
|
|
| 86 |
def model_chat(query: Optional[str], history: Optional[History]) -> Generator[Tuple[str, History], None, None]:
|
| 87 |
if query is None:
|
| 88 |
query = ''
|
|
@@ -95,9 +97,9 @@ def model_chat(query: Optional[str], history: Optional[History]) -> Generator[Tu
|
|
| 95 |
if response.status_code == 200:
|
| 96 |
prediction = response.json().get("prediction", "")
|
| 97 |
history.append((query, prediction))
|
| 98 |
-
yield query, prediction
|
| 99 |
else:
|
| 100 |
-
yield "Error: Unable to get a response from the model.", history
|
| 101 |
|
| 102 |
|
| 103 |
with gr.Blocks(css='''
|
|
@@ -159,11 +161,17 @@ with gr.Blocks(css='''
|
|
| 159 |
</div>
|
| 160 |
""")
|
| 161 |
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
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)
|
| 56 |
|
| 57 |
# Generate the output
|
| 58 |
outputs = model.generate(
|
|
|
|
| 83 |
|
| 84 |
# Run Flask in a separate thread
|
| 85 |
threading.Thread(target=run_flask).start()
|
| 86 |
+
|
| 87 |
+
|
| 88 |
def model_chat(query: Optional[str], history: Optional[History]) -> Generator[Tuple[str, History], None, None]:
|
| 89 |
if query is None:
|
| 90 |
query = ''
|
|
|
|
| 97 |
if response.status_code == 200:
|
| 98 |
prediction = response.json().get("prediction", "")
|
| 99 |
history.append((query, prediction))
|
| 100 |
+
yield query, prediction # Return individual strings and history
|
| 101 |
else:
|
| 102 |
+
yield history, "Error: Unable to get a response from the model.", history
|
| 103 |
|
| 104 |
|
| 105 |
with gr.Blocks(css='''
|
|
|
|
| 161 |
</div>
|
| 162 |
""")
|
| 163 |
|
| 164 |
+
chatbot = gr.Chatbot()
|
| 165 |
+
query = gr.Textbox(placeholder="讛讻谞住 砖讗诇讛 讘注讘专讬转 (讗讜 讘讗谞讙诇讬转!)", rtl=True)
|
| 166 |
+
clear_btn = gr.Button("谞拽讛 砖讬讞讛")
|
| 167 |
+
|
| 168 |
+
def respond(query: str, history: History) -> Tuple[History, str]:
|
| 169 |
+
history, response = model_chat(query, history)
|
| 170 |
+
return history, ""
|
| 171 |
+
|
| 172 |
+
demo_state = gr.State([])
|
| 173 |
+
|
| 174 |
+
query.submit(respond, [query, demo_state], [chatbot, query, demo_state])
|
| 175 |
+
clear_btn.click(clear_session, [], demo_state, chatbot)
|
| 176 |
|
| 177 |
demo.queue(api_open=False).launch(max_threads=20, share=False, allowed_paths=['logo_am.png'])
|