Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,6 @@ PLACEHOLDER = """
|
|
17 |
<p>Hi! I'm MisMath. A Math advisor. My model is based on mathstral-7B-v0.1. Feel free to ask your questions</p>
|
18 |
<p>Mathstral 7B is a model specializing in mathematical and scientific tasks, based on Mistral 7B.</p>
|
19 |
<p>mathstral-7B-v0.1 is the first Mathstral model</p>
|
20 |
-
<img src="Mistral.png" alt="MathStral Model" style="width:300px;height:200px;">
|
21 |
</center>
|
22 |
"""
|
23 |
|
@@ -68,15 +67,12 @@ def stream_chat(
|
|
68 |
top_k: int = 20,
|
69 |
penalty: float = 1.2,
|
70 |
):
|
71 |
-
print(f'message: {message}')
|
72 |
-
print(f'history: {history}')
|
73 |
-
|
74 |
# Prepare the conversation context
|
75 |
conversation_text = system_prompt + "\n"
|
76 |
for prompt, answer in history:
|
77 |
-
conversation_text += f"User: {prompt}\
|
78 |
|
79 |
-
conversation_text += f"User: {message}\
|
80 |
|
81 |
# Tokenize the conversation text
|
82 |
input_ids = tokenizer(conversation_text, return_tensors="pt").input_ids.to(model.device)
|
@@ -102,8 +98,11 @@ def stream_chat(
|
|
102 |
for new_text in streamer:
|
103 |
buffer += new_text
|
104 |
# Clean the buffer to remove unwanted prefixes
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
107 |
|
108 |
# Define the Gradio chatbot component
|
109 |
chatbot = gr.Chatbot(height=500, placeholder=PLACEHOLDER)
|
|
|
17 |
<p>Hi! I'm MisMath. A Math advisor. My model is based on mathstral-7B-v0.1. Feel free to ask your questions</p>
|
18 |
<p>Mathstral 7B is a model specializing in mathematical and scientific tasks, based on Mistral 7B.</p>
|
19 |
<p>mathstral-7B-v0.1 is the first Mathstral model</p>
|
|
|
20 |
</center>
|
21 |
"""
|
22 |
|
|
|
67 |
top_k: int = 20,
|
68 |
penalty: float = 1.2,
|
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 |
|
77 |
# Tokenize the conversation text
|
78 |
input_ids = tokenizer(conversation_text, return_tensors="pt").input_ids.to(model.device)
|
|
|
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)
|