Ci-Dave commited on
Commit
a288b14
·
1 Parent(s): 8b9c98d

Added Files

Browse files
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .venv/
.streamlit/secrets.toml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [gemini]
2
+ api_key = "AIzaSyBavKv_J522lZkirjVMx5WH-cXvPylddMY"
app.py ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from fpdf import FPDF
3
+ import google.generativeai as genai
4
+ import fitz
5
+ import os
6
+ import pandas as pd
7
+
8
+ # Configure Gemini API
9
+ try:
10
+ api_key = st.secrets["gemini"]["api_key"]
11
+ genai.configure(api_key=api_key)
12
+ except KeyError:
13
+ st.error("API key not found. Please check your Streamlit secrets configuration.")
14
+
15
+ MODEL_ID = "gemini-1.5-flash"
16
+ gen_model = genai.GenerativeModel(MODEL_ID)
17
+
18
+ # Ensure 'static' directory exists
19
+ os.makedirs("static", exist_ok=True)
20
+
21
+ # Custom CSS for larger font and sidebar adjustments
22
+ st.markdown("""
23
+ <style>
24
+ body, h1, h2, h3, h4, h5, h6 {
25
+ font-size: 20px;
26
+ }
27
+ .stSidebar {
28
+ font-size: 20px;
29
+ width: 400px;
30
+ }
31
+ .css-1d391kg {
32
+ padding-top: 10px;
33
+ padding-left: 10px;
34
+ padding-right: 10px;
35
+ }
36
+ .sidebar-title {
37
+ font-size: 50px;
38
+ font-weight: bold;
39
+ padding-bottom: 20px;
40
+ }
41
+ </style>
42
+ """, unsafe_allow_html=True)
43
+
44
+ # Page Navigation with Enlarged Sidebar
45
+ def main():
46
+ st.sidebar.markdown('<div class="sidebar-title">Enginuity CE</div>', unsafe_allow_html=True)
47
+ st.sidebar.header("Navigation Menu")
48
+ page = st.sidebar.radio("Go to", ["Home", "Calculator Guides", "Course Subject Selector", "PDF Analysis (Summary, Quiz, Glossary)", "Schedule Planner"])
49
+
50
+ if page == "Home":
51
+ home_page()
52
+ elif page == "Calculator Guides":
53
+ calculator_guides_page()
54
+ elif page == "Course Subject Selector":
55
+ course_subject_page()
56
+ elif page == "PDF Analysis (Summary, Quiz, Glossary)":
57
+ pdf_analysis_page()
58
+ elif page == "Schedule Planner":
59
+ schedule_planner_page()
60
+
61
+ # Home Page
62
+ def home_page():
63
+ st.title("Welcome to Enginuity CE")
64
+ st.write("This app offers AI-powered solutions for civil engineering students in the Philippines.")
65
+
66
+ st.header("📘 Page Descriptions")
67
+
68
+ st.subheader("1. Calculator Guides")
69
+ st.write(
70
+ "Access a variety of calculator techniques and formulas for different Civil Engineering subjects. "
71
+ "You can also input specific questions to receive AI-generated explanations and guides tailored to your needs."
72
+ )
73
+
74
+ st.subheader("2. Course Subject Selector")
75
+ st.write(
76
+ "Easily generate AI-powered study materials in PDF format. Select your year level and subject to receive detailed content "
77
+ "that covers key concepts and essential topics for your studies."
78
+ )
79
+
80
+ st.subheader("3. PDF Analysis (Summary, Quiz, Glossary)")
81
+ st.write(
82
+ "Upload a PDF file containing study material or notes, and let the AI summarize its contents, generate quizzes for practice, "
83
+ "or extract important terms for a glossary. Download the results as a PDF for easy offline access."
84
+ )
85
+
86
+ st.subheader("4. Schedule Planner")
87
+ st.write(
88
+ "Effortlessly plan your weekly schedule by selecting subjects and specifying your availability. "
89
+ "This tool is designed for both students and teachers to create organized study or teaching schedules. "
90
+ "AI can help optimize your schedule based on your preferences and requirements."
91
+ )
92
+
93
+ # Calculator Guides Page
94
+ def calculator_guides_page():
95
+ st.title("Calculator Guides")
96
+ st.write("Choose your course subject to view calculator techniques and formulas.")
97
+
98
+ year = st.selectbox("Select Year:", ["1st Year", "2nd Year", "3rd Year"])
99
+
100
+ subjects = {
101
+ "1st Year": ["Algebra", "Trigonometry", "General Chemistry", "Physics I"],
102
+ "2nd Year": ["Calculus II", "Differential Equations", "Statics and Dynamics", "Surveying"],
103
+ "3rd Year": ["Structural Engineering", "Hydraulics", "Soil Mechanics", "Construction Management"]
104
+ }
105
+
106
+ subject = st.selectbox("Select Subject:", subjects[year])
107
+ user_prompt = st.text_area("Enter your specific question or request about this subject:")
108
+
109
+ st.write("""
110
+ ### Instructions:
111
+ 1. Select your year level and subject.
112
+ 2. Enter a specific question or request if you have one.
113
+ 3. Click the **Show Calculator Guides** button to view AI-generated content.
114
+ """)
115
+
116
+ if st.button("Show Calculator Guides"):
117
+ try:
118
+ response = gen_model.generate_content(f"Provide calculator techniques and formulas for {subject} in Civil Engineering. Additionally, answer the user's question: {user_prompt}")
119
+ st.write(response.text if hasattr(response, 'text') else "Error generating content.")
120
+ except Exception as e:
121
+ st.error(f"Error during content generation: {e}")
122
+
123
+ # Schedule Planner Page
124
+ def schedule_planner_page():
125
+ st.title("Schedule Planner")
126
+ st.write("Follow the steps below to plan your schedule:")
127
+ st.write("1. Select your role (Student or Teacher).")
128
+ st.write("2. If you're a student, choose your year level.")
129
+ st.write("3. Select your subjects and assign a day and time slot for each.")
130
+ st.write("4. Optionally, add important dates and additional preferences.")
131
+ st.write("5. Click 'Generate Schedule Plan' to get an AI-optimized schedule.")
132
+
133
+ role = st.radio("Select your role:", ["Student", "Teacher"])
134
+ year = st.selectbox("Select Year (for Students):", ["1st Year", "2nd Year", "3rd Year"], disabled=(role == "Teacher"))
135
+ subjects = {
136
+ "1st Year": ["Algebra", "Trigonometry", "General Chemistry", "Physics I"],
137
+ "2nd Year": ["Calculus II", "Differential Equations", "Statics and Dynamics", "Surveying"],
138
+ "3rd Year": ["Structural Engineering", "Hydraulics", "Soil Mechanics", "Construction Management"]
139
+ }
140
+ selected_subjects = st.multiselect("Select Subjects:", subjects.get(year, []))
141
+ schedule = {}
142
+ for subj in selected_subjects:
143
+ day = st.selectbox(f"Select Day for {subj}", ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"])
144
+ time_range = st.slider(f"Select time for {subj} ({day})", 6, 22, (8, 10))
145
+ schedule[subj] = {"day": day, "time": time_range}
146
+ st.write("## Mark Your Calendar")
147
+ st.date_input("Select Important Dates:", [])
148
+ user_prompt = st.text_area("Enter additional preferences or requirements for your schedule:")
149
+ if st.button("Generate Schedule Plan"):
150
+ try:
151
+ response = gen_model.generate_content(
152
+ f"Generate a precise weekly schedule for a {role} in Civil Engineering. Subjects: {selected_subjects}, Schedule: {schedule}, Additional Requirements: {user_prompt}"
153
+ )
154
+ st.write(response.text if hasattr(response, 'text') else "Error generating schedule.")
155
+ except Exception as e:
156
+ st.error(f"Error generating schedule: {e}")
157
+
158
+ # PDF Analysis Page
159
+ def pdf_analysis_page():
160
+ st.title("PDF Analysis: Summary, Quiz, or Glossary")
161
+ st.write("Follow the steps below to analyze your PDF:")
162
+ st.write("1. Upload your PDF file.")
163
+ st.write("2. Select the action: summarize, generate a quiz, or create a glossary.")
164
+ st.write("3. Click 'Generate Result' to see the output and download it as a PDF.")
165
+
166
+ uploaded_file = st.file_uploader("Upload PDF File", type=["pdf"])
167
+ if uploaded_file is not None:
168
+ try:
169
+ pdf_data = uploaded_file.read()
170
+ doc = fitz.Document(stream=pdf_data, filetype="pdf")
171
+ pdf_text = "".join(page.get_text() for page in doc)
172
+ st.text_area("Extracted PDF Content", pdf_text[:3000])
173
+ action = st.selectbox("Choose Action:", ["Summary", "Quiz Generation", "Glossary Generation"])
174
+ if st.button("Generate Result"):
175
+ response = gen_model.generate_content(f"{action} this text: {pdf_text}")
176
+ content = response.text if hasattr(response, 'text') else "Error generating content."
177
+ rows = content.split('\n')
178
+ data = [row.split('|') for row in rows if '|' in row]
179
+ if data:
180
+ df = pd.DataFrame(data)
181
+ st.dataframe(df)
182
+ else:
183
+ st.write(content)
184
+ pdf = FPDF()
185
+ pdf.add_page()
186
+ pdf.set_font("Arial", size=12)
187
+ pdf.cell(200, 10, txt=f"{action} Result", ln=True, align='C')
188
+ for line in rows:
189
+ pdf.multi_cell(0, 10, line)
190
+ pdf_file = os.path.join("static", f"{action}_result.pdf")
191
+ pdf.output(pdf_file)
192
+ with open(pdf_file, "rb") as f:
193
+ st.download_button(label="Download PDF", data=f, file_name=f"{action}_result.pdf")
194
+ st.success(f"{action} result generated and available for download.")
195
+ except Exception as e:
196
+ st.error(f"Error reading PDF: {e}")
197
+
198
+ # Course Subject Page
199
+ def course_subject_page():
200
+ st.title("Course Subject Selector")
201
+ st.write("Follow the steps below to generate study materials:")
202
+ st.write("1. Select your year level and subject.")
203
+ st.write("2. Click 'Generate PDF Study Material' to create and download a PDF.")
204
+
205
+ year = st.selectbox("Select Year:", ["1st Year", "2nd Year", "3rd Year"])
206
+ subjects = {
207
+ "1st Year": ["Algebra", "Trigonometry", "General Chemistry", "Physics I"],
208
+ "2nd Year": ["Calculus II", "Differential Equations", "Statics and Dynamics", "Surveying"],
209
+ "3rd Year": ["Structural Engineering", "Hydraulics", "Soil Mechanics", "Construction Management"]
210
+ }
211
+ subject = st.selectbox("Select Subject:", subjects[year])
212
+ if st.button("Generate PDF Study Material"):
213
+ generate_pdf(subject)
214
+
215
+ # Function to generate PDF study material
216
+ def generate_pdf(subject):
217
+ pdf = FPDF()
218
+ pdf.add_page()
219
+ pdf.set_font("Arial", size=12)
220
+ pdf.cell(200, 10, txt=f"Study Material for {subject}", ln=True, align='C')
221
+ pdf.output(f"static/{subject}_study_material.pdf")
222
+ st.success(f"PDF for {subject} generated successfully!")
223
+
224
+ if __name__ == "__main__":
225
+ main()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ fpdf
3
+ google-generativeai
4
+ pymupdf
5
+ fitz
static/Algebra_study_material.pdf ADDED
Binary file (4.64 kB). View file
 
static/Quiz Generation_result.pdf ADDED
Binary file (3.79 kB). View file