Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,6 @@ If the question is unrelated to Python, say:
|
|
| 32 |
### ASSISTANT:
|
| 33 |
"""
|
| 34 |
|
| 35 |
-
# Chat function
|
| 36 |
def chat(instruction):
|
| 37 |
prompt = format_prompt(instruction)
|
| 38 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
|
@@ -47,16 +46,15 @@ def chat(instruction):
|
|
| 47 |
repetition_penalty=1.1
|
| 48 |
)
|
| 49 |
|
| 50 |
-
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
#
|
| 56 |
-
|
| 57 |
-
return response.split("### Answer:")[-1].strip()
|
| 58 |
else:
|
| 59 |
-
return
|
| 60 |
|
| 61 |
# Streamlit UI
|
| 62 |
st.set_page_config(page_title="🐍 Python Tutor Chatbot")
|
|
|
|
| 32 |
### ASSISTANT:
|
| 33 |
"""
|
| 34 |
|
|
|
|
| 35 |
def chat(instruction):
|
| 36 |
prompt = format_prompt(instruction)
|
| 37 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
|
|
|
| 46 |
repetition_penalty=1.1
|
| 47 |
)
|
| 48 |
|
| 49 |
+
full_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 50 |
|
| 51 |
+
# Extract only the final answer
|
| 52 |
+
if "### Answer:" in full_output:
|
| 53 |
+
return full_output.split("### Answer:")[-1].strip()
|
| 54 |
+
elif "### ASSISTANT:" in full_output:
|
| 55 |
+
return full_output.split("### ASSISTANT:")[-1].strip()
|
|
|
|
| 56 |
else:
|
| 57 |
+
return full_output.strip()
|
| 58 |
|
| 59 |
# Streamlit UI
|
| 60 |
st.set_page_config(page_title="🐍 Python Tutor Chatbot")
|