Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
|