Tanifh commited on
Commit
dd6665f
Β·
verified Β·
1 Parent(s): 79ed0a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -24,10 +24,10 @@ if not os.path.exists(MODEL_PATH):
24
  st.error(f"🚨 Model download failed: {e}")
25
  st.stop()
26
 
27
- # βœ… Load model
28
  try:
29
  if "model" not in st.session_state:
30
- st.session_state["model"] = Llama(model_path=MODEL_PATH, n_ctx=4096)
31
  st.write("βœ… Model loaded successfully!")
32
  except Exception as e:
33
  st.error(f"🚨 Error loading model: {e}")
@@ -58,9 +58,9 @@ if st.button("Send") and user_input:
58
 
59
  # βœ… Format messages using Phi-3 chat template
60
  formatted_messages = [
61
- {"role": "system", "content": "You are an AI assistant. Provide clear and concise answers."}
 
62
  ]
63
- formatted_messages += [{"role": "user", "content": user_input}]
64
 
65
  # Generate response
66
  try:
@@ -68,12 +68,15 @@ if st.button("Send") and user_input:
68
  messages=formatted_messages,
69
  max_tokens=1024, temperature=0.7, top_p=0.9
70
  )
 
 
 
 
71
  response_text = response["choices"][0]["message"]["content"].strip()
72
  st.session_state["messages"].append(("assistant", response_text))
73
  st.chat_message("assistant").write(response_text)
74
  except Exception as e:
75
  st.error(f"🚨 Error generating response: {e}")
76
- st.write("Raw Model Output:", response) # Debugging Output
77
 
78
  # Run the app with: streamlit run app.py
79
 
 
24
  st.error(f"🚨 Model download failed: {e}")
25
  st.stop()
26
 
27
+ # βœ… Load model with reduced context length to reduce memory usage
28
  try:
29
  if "model" not in st.session_state:
30
+ st.session_state["model"] = Llama(model_path=MODEL_PATH, n_ctx=2048) # Reduced from 4096
31
  st.write("βœ… Model loaded successfully!")
32
  except Exception as e:
33
  st.error(f"🚨 Error loading model: {e}")
 
58
 
59
  # βœ… Format messages using Phi-3 chat template
60
  formatted_messages = [
61
+ {"role": "system", "content": "You are an AI assistant. Provide clear and concise answers."},
62
+ {"role": "user", "content": user_input}
63
  ]
 
64
 
65
  # Generate response
66
  try:
 
68
  messages=formatted_messages,
69
  max_tokens=1024, temperature=0.7, top_p=0.9
70
  )
71
+
72
+ # βœ… Debugging output
73
+ st.write("πŸ” Debug: Raw Model Response:", response)
74
+
75
  response_text = response["choices"][0]["message"]["content"].strip()
76
  st.session_state["messages"].append(("assistant", response_text))
77
  st.chat_message("assistant").write(response_text)
78
  except Exception as e:
79
  st.error(f"🚨 Error generating response: {e}")
 
80
 
81
  # Run the app with: streamlit run app.py
82