saad-sust commited on
Commit
3b43b98
·
verified ·
1 Parent(s): 477e62c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ st.set_page_config(page_title="SUST Math AI", page_icon="🎓")
5
+
6
+ # This loads the model directly on Hugging Face's server
7
+ @st.cache_resource
8
+ def load_solver():
9
+ return pipeline("text-generation", model="HuggingFaceTB/SmolLM2-1.7B-Instruct")
10
+
11
+ pipe = load_solver()
12
+
13
+ st.title("🎓 SUST B.Sc. Math Solver")
14
+ st.markdown("Enter your problem below to get a step-by-step solution.")
15
+
16
+ user_query = st.chat_input("Ex: Find the derivative of (x^2 + 1)^3")
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("Thinking..."):
24
+ messages = [
25
+ {"role": "system", "content": "You are a professional Mathematics Professor. Solve the problem step-by-step with clear logic."},
26
+ {"role": "user", "content": user_query},
27
+ ]
28
+ result = pipe(messages, max_new_tokens=500, do_sample=False)
29
+ st.markdown(result[0]['generated_text'][-1]['content'])