krisha06 commited on
Commit
84376c0
·
verified ·
1 Parent(s): 8fcfedf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
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
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
51
 
52
- # Debugging optional:
53
- # print("🧠 Full output:", repr(response))
54
-
55
- # Split and return the assistant's answer
56
- if "### Answer:" in response:
57
- return response.split("### Answer:")[-1].strip()
58
  else:
59
- return response.strip()
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")