Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,54 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
st.set_page_config(page_title="
|
| 6 |
|
| 7 |
-
st.
|
| 8 |
-
|
| 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_html=True)
|
| 13 |
|
| 14 |
@st.cache_resource
|
| 15 |
def load_engine():
|
| 16 |
-
#
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
pipe = load_engine()
|
| 20 |
|
| 21 |
-
|
| 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
|
| 28 |
-
"
|
| 29 |
-
"
|
|
|
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
-
user_query = st.chat_input("Enter your
|
| 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("
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
result = pipe(
|
| 44 |
-
response = result[0]['generated_text']
|
| 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.
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Professional Academic Layout
|
| 6 |
+
st.set_page_config(page_title="B.Sc. Math Engine", page_icon="π", layout="centered")
|
| 7 |
|
| 8 |
+
st.title("π B.Sc. Mathematics Engine")
|
| 9 |
+
st.write("Advanced Proof & Logic Solver | SUST Dept. of Mathematics")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
@st.cache_resource
|
| 12 |
def load_engine():
|
| 13 |
+
# Switching to Llama-1B: Much smarter logic for Group Theory/Analysis
|
| 14 |
+
model_id = "meta-llama/Llama-3.2-1B-Instruct"
|
| 15 |
+
return pipeline(
|
| 16 |
+
"text-generation",
|
| 17 |
+
model=model_id,
|
| 18 |
+
device_map="auto",
|
| 19 |
+
torch_dtype=torch.float32
|
| 20 |
+
)
|
| 21 |
|
| 22 |
pipe = load_engine()
|
| 23 |
|
| 24 |
+
# Strict Academic System Prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
system_instruction = (
|
| 26 |
+
"You are a rigorous Mathematics Professor. "
|
| 27 |
+
"1. Always use LaTeX for equations. "
|
| 28 |
+
"2. A homomorphism must satisfy f(ab) = f(a)f(b). "
|
| 29 |
+
"3. The kernel is the set {x in G : f(x) = e}, where e is the identity. "
|
| 30 |
+
"4. Verify every logical step before outputting."
|
| 31 |
)
|
| 32 |
|
| 33 |
+
user_query = st.chat_input("Enter your problem (e.g., Prove the kernel of z^2 is {1, -1})")
|
| 34 |
|
| 35 |
if user_query:
|
| 36 |
with st.chat_message("user"):
|
| 37 |
st.write(user_query)
|
| 38 |
|
| 39 |
with st.chat_message("assistant"):
|
| 40 |
+
with st.spinner("Calculating logic... (May take 30-60s on Free Tier)"):
|
| 41 |
+
# Formatting for Llama-3.2
|
| 42 |
+
messages = [
|
| 43 |
+
{"role": "system", "content": system_instruction},
|
| 44 |
+
{"role": "user", "content": user_query}
|
| 45 |
+
]
|
| 46 |
|
| 47 |
+
# do_sample=False (Temperature 0) for mathematical consistency
|
| 48 |
+
result = pipe(messages, max_new_tokens=512, do_sample=False)
|
| 49 |
+
response = result[0]['generated_text'][-1]['content']
|
| 50 |
|
| 51 |
st.markdown(response)
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
st.sidebar.markdown("### SUST Math Module")
|
| 54 |
+
st.sidebar.info("This engine uses a 1-Billion parameter logic model optimized for CPU execution.")
|