Zeeshan265 commited on
Commit
7d896b3
·
verified ·
1 Parent(s): cf84968

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +280 -0
app.py ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import time
4
+ from groq import Groq
5
+
6
+ st.markdown(
7
+ """
8
+ <style>
9
+ /* General background and text styles */
10
+ html, body, [data-testid="stAppViewContainer"] {
11
+ background-image: linear-gradient(to bottom right,
12
+ rgba(135, 206, 250, 0.8), /* Light Sky Blue */
13
+ rgba(255, 223, 186, 0.8), /* Soft Peach */
14
+ rgba(192, 192, 192, 0.8), /* Bright Silver */
15
+ rgba(169, 169, 169, 0.8), /* Gray */
16
+ rgba(240, 248, 255, 0.8), /* Alice Blue */
17
+ rgba(173, 216, 230, 0.8) /* Light Blue */
18
+ );
19
+
20
+
21
+ background-size: cover;
22
+ font-family: 'Arial', sans-serif;
23
+ }
24
+
25
+ /* Header slide-right animation */
26
+ @keyframes slide-right {
27
+ 0% {
28
+ transform: translateX(-100%); /* Start off-screen to the left */
29
+ }
30
+ 100% {
31
+ transform: translateX(0); /* End at the normal position */
32
+ }
33
+ }
34
+
35
+ /* Header slide-left animation */
36
+ @keyframes slide-left {
37
+ 0% {
38
+ transform: translateX(100%); /* Start off-screen to the right */
39
+ }
40
+ 100% {
41
+ transform: translateX(0); /* End at the normal position */
42
+ }
43
+ }
44
+
45
+ /* Header slide-right animation for the title */
46
+ .header-slide-right {
47
+ display: inline-block;
48
+ animation: slide-right 2s ease-out;
49
+ }
50
+
51
+ /* Subtitle slide-left animation */
52
+ .header_description {
53
+ display: inline-block;
54
+ animation: slide-left 2s ease-out;
55
+ }
56
+
57
+ /* Button styles */
58
+ .stButton button {
59
+ background-color: #333333;
60
+ color: white;
61
+ border: 2px solid black;
62
+ padding: 10px 20px;
63
+ font-size: 16px;
64
+ cursor: pointer;
65
+ }
66
+
67
+ .stButton button:hover {
68
+ background-color: #333;
69
+ }
70
+ .stSelectbox select {
71
+ background-color: #333333;
72
+ color: white;
73
+ border: 2px solid black;
74
+ padding: 10px 20px;
75
+ font-size: 16px;
76
+ cursor: pointer;
77
+ }
78
+
79
+ .stSelectbox select:hover {
80
+ background-color: #555555;
81
+ }
82
+ </style>
83
+ """,
84
+ unsafe_allow_html=True
85
+ )
86
+
87
+
88
+ client = Groq(api_key=("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"))
89
+ ss = st.session_state
90
+ session_vars = ["area", "subject", "subtopic", "level" , "tone", "language", "explanation", "mcqs", "answers", "feedback", "topic"]
91
+
92
+ for var in session_vars:
93
+ ss.setdefault(var, None)
94
+
95
+ def get_response(prompt):
96
+ chat_completion = client.chat.completions.create(
97
+ messages=[{"role": "user", "content": prompt}],
98
+ model="llama-3.2-90b-vision-preview",
99
+ )
100
+ return chat_completion.choices[0].message.content
101
+
102
+ def main_interface():
103
+ st.markdown('<h1 class="header-slide-right">Studify</h1>', unsafe_allow_html=True)
104
+ st.markdown('<h6 class="header_description">Learn the way you like!</h6>', unsafe_allow_html=True)
105
+ time.sleep(2)
106
+
107
+ if not ss.topic:
108
+ area = st.radio(
109
+ "Options:",("Select a Subject", "Search Manually"), horizontal = True)
110
+ if area == "Select a Subject":
111
+ st.write("Choose a subject from the list to explore specific topics and exercises.")
112
+ elif area == "Search Manually":
113
+ st.write("Use the search bar to manually find specific content or topics.")
114
+
115
+ ss.area = area
116
+
117
+ if ss.area == "Search Manually":
118
+ topic = st.text_input("Type any kind of subject or topic you want to learn about:")
119
+
120
+ elif ss.area == "Select a Subject":
121
+ topics = {
122
+ "English": {
123
+ "Grammar": ["Grammar", "Tenses", "Parts of Speech", "Sentence Structure", "Active Passive Voice", "Direct Indirect"],
124
+ "Vocabulary": ["Vocabulary", "Synonyms", "Antonyms", "Prefixes/ Suffixes", "Homophones"],
125
+ "Reading Comprehension": ["Reading Comprehension", "Essay Reading", "Story Reading", "New Article Reading"],
126
+ "Essay Writing": ["Essay Writing", "Introduction", "Body Paragraphs", "Conclusion"],
127
+ "Literature Analysis": ["Literature Analysis", "Poetry", "Non-fiction", "Novels", "Dramas"],
128
+ "Creative Writing": ["Creative Writing", "Story Writing", "Dialogue Writing", "Script Writing"],
129
+ "Speaking": ["Speaking", "Conversational", "Interviews", "Debate", "Public Speaking"],
130
+ "Poetry Analysis": ["Poetry Analysis", "Rhythm", "Meter", "Imagery"]
131
+ },
132
+ "Maths": {
133
+ "Word Problems": ["Word Problems", "Distance-Speed-Time", "Age Problems", "Work and Time", "Probability Problems"],
134
+ "Algebra": ["Algebra", "Linear Equations", "Quadratic Equations", "Polynomials", "Exponents", "Factoring"],
135
+ "Geometry": ["Geometry", "Lines and Angles", "Triangles", "Circles", "Surface Area and Volume", "Coordinate Geometry"],
136
+ "Trigonometry": ["Trigonometry", "Trigonometric Ratios", "Sine, Cosine, Tangent", "Trigonometric Identities", "Height and Distance"],
137
+ "Fractions": ["Fractions", "Simplifying Fractions", "Adding/Subtracting Fractions", "Multiplying/Dividing Fractions", "Mixed Numbers"],
138
+ "Percentages": ["Percentages", "Percentage Increase/Decrease", "Discounts", "Profit and Loss", "Interest Calculation"],
139
+ "Arithmetic Operations": ["Arithmetic Operations", "Addition", "Subtraction", "Multiplication", "Division", "Order of Operations (BODMAS)"]
140
+ },
141
+ "Science": {
142
+ "Human Body Systems": ["Human Body Systems", "Circulatory System", "Respiratory System", "Nervous System", "Muscular System", "Digestive System"],
143
+ "Atomic structure": ["Atomic structure", "Atoms", "Protons, Neutrons, Electrons", "Electron Configurations", "Periodic Table"],
144
+ "Ecosystems": ["Ecosystems", "Food Chains", "Energy Flow", "Ecological Pyramids", "Biomes", "Environmental Factors"],
145
+ "Forces and Motion": ["Forces and Motion", "Newton's Laws", "Friction", "Work and Energy", "Acceleration"],
146
+ "States of Matter": ["States of Matter", "Solids", "Liquids", "Gases", "Plasma", "Changes in State"],
147
+ "Energy and Work": ["Energy and Work", "Kinetic Energy", "Potential Energy", "Work-Energy Theorem", "Power"],
148
+ "Plants": ["Plants", "Photosynthesis", "Plant Reproduction", "Plant Anatomy", "Types of Plants"],
149
+ "Solar System": ["Solar System", "Planets", "Moons", "Asteroids", "Comets", "The Sun"]
150
+ },
151
+ "Social Studies": {
152
+ "International Organizations": ["International Organizations", "United Nations", "World Health Organization", "World Bank", "International Monetary Fund"],
153
+ "Climate Change": ["Climate Change", "Global Warming", "Carbon Footprint", "Effects of Climate Change", "Mitigation Strategies"],
154
+ "Government and Democracy": ["Government and Democracy", "Types of Governments", "Democratic Systems", "Elections", "Political Rights"],
155
+ "Human Rights and Responsibilities": ["Human Rights and Responsibilities", "Rights of Citizens", "International Human Rights", "Social Justice"],
156
+ "Population Studies": ["Population Studies", "Population Growth", "Demographic Transition", "Urbanization", "Migration"],
157
+ "World Cultures": ["World Cultures", "Cultural Diversity", "Globalization", "Cultural Identity", "Traditions and Customs"],
158
+ "Religions": ["Religions", "Christianity", "Islam", "Hinduism", "Buddhism", "Judaism"],
159
+ "Globalization and Trade": ["Globalization and Trade", "International Trade", "Economic Interdependence", "Trade Agreements", "Global Markets"]
160
+ },
161
+ "History": {
162
+ "Islamic History": ["Islamic History", "The Origin of Humanity", "Early Islamic Civilization", "Golden Age of Islam", "Islamic Empires"],
163
+ "Sub-Continent History": ["Sub-Continent History", "Ancient India", "Mughal Empire", "British India", "Partition of India"],
164
+ "European History": ["European History", "Ancient Greece", "Roman Empire", "Middle Ages", "World Wars"],
165
+ "American History": ["American History", "Colonial America", "American Revolution", "Civil War", "Modern America"],
166
+ "Ancient Civilizations": ["Ancient Civilizations", "Mesopotamia", "Ancient Egypt", "Indus Valley Civilization", "Ancient China"],
167
+ "Turkish (Ottoman) History": ["Turkish History", "Ottoman Empire", "Suleiman the Magnificent", "Decline of the Ottoman Empire"],
168
+ "World Wars": ["World Wars", "World War I", "World War II", "Causes of War", "Aftermath and Consequences"]
169
+ },
170
+ "Islamiat": {
171
+ "Life of Prophet Muhammad (PBUH)": ["Life of Prophet Muhammad (PBUH)", "Birth and Early Life", "Prophethood", "Migration to Medina", "The Farewell Sermon"],
172
+ "Five Pillars of Islam": ["Five Pillars of Islam", "Shahada", "Salah", "Zakat", "Sawm", "Hajj"],
173
+ "The Quran": ["The Quran", "Revelation", "Surahs", "Ayahs", "Exegesis of the Quran"],
174
+ "Hadith": ["Hadith", "Types of Hadith", "Sahih Hadith", "Prophet's Sayings"],
175
+ "Major Prophets": ["Major Prophets", "Prophet Adam (AS)", "Prophet Nuh (AS)" "Prophet Ibrahim (AS)", "Prophet Musa (AS)", "Prophet Isa (AS)", "Prophet Yusuf (AS)", "Prophet Muhammad (PBUH)"],
176
+ "Shariah Law": ["Shariah Law", "Islamic Jurisprudence", "Rights and Duties", "Islamic Criminal Law"],
177
+ "Jihad": ["Jihad", "Types of Jihad", "Jihad in Islam", "Jihad and Peace","The reality of Jihad"],
178
+ "Islamic Ethics": ["Islamic Ethics", "Moral Teachings", "Rights of Others", "Social Justice in Islam"]
179
+ },
180
+ "Physics": {
181
+ "Mechanics (Force, Motion)": ["Mechanics", "Newton's Laws", "Force", "Momentum", "Circular Motion"],
182
+ "Electricity": ["Electricity", "Ohm's Law", "Circuits", "Electric Current", "Electromagnetic Fields"],
183
+ "Magnetism": ["Magnetism", "Magnetic Fields", "Electromagnetic Induction", "Magnets", "Magnetic Force"],
184
+ "Thermodynamics": ["Thermodynamics", "Laws of Thermodynamics", "Heat Transfer", "Entropy", "Internal Energy"],
185
+ "Optics (Light and Mirrors)": ["Optics", "Reflection", "Refraction", "Lenses", "Optical Instruments"],
186
+ "Waves and Sound": ["Waves and Sound", "Wave Properties", "Sound Waves", "Wave Interference", "Doppler Effect"],
187
+ "Kinematics": ["Kinematics", "Velocity", "Acceleration", "Free Fall", "Projectile Motion"]
188
+ },
189
+ "Chemistry": {
190
+ "Atomic Structure": ["Atomic Structure", "Atoms", "Protons, Neutrons, Electrons", "Electron Configuration", "Periodic Table"],
191
+ "Periodic Table": ["Periodic Table", "Elements", "Groups and Periods", "Metals and Nonmetals", "Periodic Trends"],
192
+ "Chemical Bonding": ["Chemical Bonding", "Ionic Bonds", "Covalent Bonds", "Metallic Bonds", "Molecular Geometry"],
193
+ "Acids, Bases, and Salts": ["Acids, Bases, and Salts", "Properties of Acids and Bases", "Neutralization", "pH Scale"],
194
+ "Chemical Reactions": ["Chemical Reactions", "Types of Reactions", "Balancing Equations", "Reaction Rates"],
195
+ "Organic Chemistry": ["Organic Chemistry", "Hydrocarbons", "Alcohols", "Aldehydes and Ketones", "Polymerization"],
196
+ "Biochiometry": ["Biochemistry", "Proteins", "Carbohydrates", "Lipids", "Nucleic Acids"],
197
+ "Solutions and Mixtures": ["Solutions and Mixtures", "Solubility", "Concentration", "Types of Solutions"]
198
+ },
199
+ "Biology": {
200
+ "Human Systems": ["Human Systems", "Circulatory System", "Digestive System", "Respiratory System", "Excretory System"],
201
+ "Cell Structure and Function": ["Cell Structure and Function", "Prokaryotic Cells", "Eukaryotic Cells", "Cell Organelles", "Cell Membrane"],
202
+ "Genetics and Heredity": ["Genetics", "DNA", "Gene Expression", "Inheritance", "Genetic Disorders"],
203
+ "Human Anatomy and Physiology": ["Human Anatomy and Physiology", "Musculoskeletal System", "Nervous System", "Endocrine System"],
204
+ "Plant Biology": ["Plant Biology", "Photosynthesis", "Plant Cells", "Plant Reproduction", "Plant Growth"],
205
+ "Microorganisms": ["Microorganisms", "Bacteria", "Viruses", "Fungi", "Algae"],
206
+ "Animal Kingdom": ["Animal Kingdom", "Vertebrates", "Invertebrates", "Mammals", "Amphibians"]
207
+ },
208
+ "Computer Studies": {
209
+ "Programming Languages": ["Programming Languages", "Python", "Java", "C++", "JavaScript", "Ruby", "Swift"],
210
+ "Programming Fundamentals": ["Programming Fundamentals", "Variables", "Loops", "Conditionals", "Functions"],
211
+ "Algorithms and Data Structures": ["Algorithms", "Sorting", "Searching", "Arrays", "Linked Lists"],
212
+ "Basics of Databases": ["Databases", "SQL", "Relational Databases", "Normalization", "Database Management"],
213
+ "Computer Hardware and Software": ["Computer Hardware", "CPU", "RAM", "Motherboard", "Operating Systems"],
214
+ "Networking Basics": ["Networking Basics", "IP Addressing", "Subnetting", "Routing", "Switching"],
215
+ "Cybersecurity Essentials": ["Cybersecurity", "Encryption", "Firewall", "Malware", "Ethical Hacking"],
216
+ "Artificial Intelligence Basics": ["AI Basics", "Machine Learning", "Neural Networks", "Natural Language Processing", "Computer Vision"],
217
+ "Operating Systems": ["Operating Systems", "Linux", "Windows", "MacOS", "File Systems", "Process Management"]
218
+ }
219
+ }
220
+
221
+ subject = st.selectbox("Choose a subject:", list(topics.keys()))
222
+ topic = st.radio(f"Choose a topic for {subject}:", list(topics[subject].keys()))
223
+ subtopic = st.selectbox(f"Choose a subtopic for {topic}:", topics[subject][topic])
224
+
225
+ if ss.area:
226
+ level = st.radio("Please select your proficiency level in the selected topic:", ("Beginner", "Intermediate", "Advanced"), horizontal=True)
227
+
228
+ if st.button("Continue"):
229
+ if ss.area == "Select a Subject":
230
+ ss.subject = subject
231
+ ss.subtopic = subtopic
232
+ ss.level = level
233
+ ss.topic = topic
234
+ st.rerun()
235
+
236
+ if ss.topic:
237
+ if st.button("⬅️ Go Back", key="back", help="Go back"):
238
+ for var in session_vars:
239
+ if var != "area":
240
+ setattr(ss, var, None)
241
+ st.rerun()
242
+
243
+ tone = st.radio("Kindly select the way you want to learn the selected topic:",("Simple and easy", "Interesting and Engaging", "Detailed", "Storytelling"),horizontal = True)
244
+
245
+ language = st.radio("Kindly select the Language you want to learn the selected topic:",("English", "Roman Urdu", "Hindi", "Urdu"),horizontal = True)
246
+
247
+ if st.button("Let's Learn"):
248
+ ss.tone = tone
249
+ ss.language = language
250
+ ss.explanation = None
251
+ ss.answers = None
252
+ ss.feedback = None
253
+ ss.mcqs = None
254
+
255
+ if ss.tone:
256
+ if ss.area == "Select a Subject":
257
+ explanation_prompt = f"Provide an explanation on '{ss.subtopic}' related to '{ss.topic}', in a '{ss.tone}' tone, suitable for a '{ss.level}' level learner, strictly in '{ss.language}'. Avoid introductory phrases."
258
+ elif ss.area == "Search Manually":
259
+ explanation_prompt = f"Explain the topic {ss.topic}' in a '{ss.tone}' manner at the '{ss.level} level strictly in '{ss.language}'.\nDon't add any intro"
260
+
261
+ ss.explanation = get_response(explanation_prompt)
262
+ st.write(ss.explanation)
263
+
264
+ if ss.explanation:
265
+ if st.button("Take a test"):
266
+ mcq_prompt = f"Generate 5 'SHORT' multiple-choice questions related to the topic '{ss.topic}', strictly at the '{ss.level}' level.\nThe explanation used to explain the topic is:\n '{ss.explanation}'.\nPlease ensure each answer option is on a new line, and do not specify the correct answers."
267
+ ss.mcqs = get_response(mcq_prompt)
268
+ if ss.mcqs:
269
+ st.subheader("Test: Answer the following questions")
270
+ st.write(ss.mcqs)
271
+ answer = st.text_area("Write your answers here:", height=120, placeholder="Please attempt the answers like:\n1. A\n2. C\n3. B..." )
272
+ if st.button("Submit Answers"):
273
+ ss.answers = answer
274
+ feedback_prompt = f"Evaluate and provide concise feedback in simple words on the following answers to the questions related to '{ss.topic}.'\nThe explanation used to explain the topic is: '{ss.explanation}.'\nThe mcqs are: '{ss.mcqs}.'\nThe answers given by me are: '{ss.answers}.'\nSpecify how many ansers are correct strictly accurately, if the answers are none or irrelevant say something like: 'Kindly give the answers correctly', and if there are some answers missing then specify which ones and request that they be done."
275
+ ss.feedback = get_response(feedback_prompt)
276
+ st.subheader("Feedback")
277
+ st.write(ss.feedback)
278
+
279
+
280
+ main_interface()