Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,51 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
# This loads the model directly on Hugging Face's server
|
| 7 |
@st.cache_resource
|
| 8 |
-
def
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
user_query = st.chat_input("
|
| 17 |
|
| 18 |
if user_query:
|
| 19 |
with st.chat_message("user"):
|
| 20 |
st.write(user_query)
|
| 21 |
|
| 22 |
with st.chat_message("assistant"):
|
| 23 |
-
with st.spinner("
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# 1. Page Configuration for a high-end UI
|
| 5 |
+
st.set_page_config(page_title="SAAD AI ACADEMY | Math Engine", page_icon="π", layout="centered")
|
| 6 |
+
|
| 7 |
+
st.markdown("""
|
| 8 |
+
<style>
|
| 9 |
+
.stApp { background: linear-gradient(to bottom, #0f172a, #000000); color: white; }
|
| 10 |
+
.stButton>button { width: 100%; border-radius: 20px; background: #3b82f6; color: white; }
|
| 11 |
+
</style>
|
| 12 |
+
""", unsafe_allow_safe=True)
|
| 13 |
|
|
|
|
| 14 |
@st.cache_resource
|
| 15 |
+
def load_engine():
|
| 16 |
+
# Fast 360M model optimized for CPU
|
| 17 |
+
return pipeline("text-generation", model="HuggingFaceTB/SmolLM2-360M-Instruct", device=-1)
|
| 18 |
+
|
| 19 |
+
pipe = load_engine()
|
| 20 |
|
| 21 |
+
st.title("π SAAD AI ACADEMY")
|
| 22 |
+
st.subheader("B.Sc. Mathematics Engine V4")
|
| 23 |
+
st.caption("Optimized for Number Theory, Calculus & Linear Algebra")
|
| 24 |
|
| 25 |
+
# 2. Professor Mode Instructions
|
| 26 |
+
system_instruction = (
|
| 27 |
+
"You are a Senior Mathematics Professor. Solve the problem with extreme rigor. "
|
| 28 |
+
"Use LaTeX for all mathematical notation. If it's a divisibility problem, "
|
| 29 |
+
"always consider Fermat's Little Theorem or Induction."
|
| 30 |
+
)
|
| 31 |
|
| 32 |
+
user_query = st.chat_input("Enter your SUST Math problem...")
|
| 33 |
|
| 34 |
if user_query:
|
| 35 |
with st.chat_message("user"):
|
| 36 |
st.write(user_query)
|
| 37 |
|
| 38 |
with st.chat_message("assistant"):
|
| 39 |
+
with st.spinner("β³ Analyzing mathematical structures..."):
|
| 40 |
+
prompt = f"<|im_start|>system\n{system_instruction}<|im_end|>\n<|im_start|>user\n{user_query}<|im_end|>\n<|im_start|>assistant\n"
|
| 41 |
+
|
| 42 |
+
# Increased tokens for longer proofs
|
| 43 |
+
result = pipe(prompt, max_new_tokens=800, temperature=0.1, do_sample=False)
|
| 44 |
+
response = result[0]['generated_text'].split("<|im_start|>assistant\n")[-1]
|
| 45 |
+
|
| 46 |
+
st.markdown(response)
|
| 47 |
+
|
| 48 |
+
# 3. Add a simple Copy/Download button
|
| 49 |
+
st.download_button("Download Solution", response, file_name="solution.txt")
|
| 50 |
+
|
| 51 |
+
st.sidebar.info("Tip: Use standard notation like x^2, integrals, or matrices.")
|