Siddiqui Qamar
commited on
Commit
•
eea8826
1
Parent(s):
e6cb8e8
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ client = OpenAI(
|
|
9 |
api_key=ACCESS_TOKEN,
|
10 |
)
|
11 |
|
12 |
-
|
13 |
topic,
|
14 |
difficulty,
|
15 |
question_type,
|
@@ -63,7 +63,7 @@ client = OpenAI(
|
|
63 |
- End with a positive reinforcement message
|
64 |
"""
|
65 |
|
66 |
-
|
67 |
messages = [
|
68 |
{"role": "system", "content": "You are an expert educational content generator."},
|
69 |
{"role": "user", "content": base_prompt}
|
@@ -77,13 +77,13 @@ client = OpenAI(
|
|
77 |
top_p=0.9
|
78 |
)
|
79 |
|
80 |
-
|
81 |
|
82 |
-
|
83 |
-
|
84 |
|
85 |
-
|
86 |
-
|
87 |
gr.Markdown("""
|
88 |
# <div align="center"><strong>📚 Exam Preparation Assistant</strong></div>
|
89 |
|
@@ -95,8 +95,8 @@ client = OpenAI(
|
|
95 |
Remember: Every practice session brings you closer to mastery! 🌟
|
96 |
""")
|
97 |
|
98 |
-
|
99 |
-
|
100 |
topic = gr.Textbox(
|
101 |
label="Topic or Subject",
|
102 |
placeholder="Enter the topic you want to study (e.g., 'Python Lists and Tuples', 'Chemical Bonding')",
|
@@ -149,16 +149,77 @@ client = OpenAI(
|
|
149 |
variant="primary"
|
150 |
)
|
151 |
|
152 |
-
|
153 |
output = gr.Textbox(
|
154 |
label="Your Personalized Study Material",
|
155 |
lines=20,
|
156 |
show_copy_button=True
|
157 |
)
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
submit_btn.click(
|
161 |
-
|
162 |
inputs=[
|
163 |
topic,
|
164 |
difficulty,
|
@@ -170,8 +231,8 @@ client = OpenAI(
|
|
170 |
outputs=output
|
171 |
)
|
172 |
|
173 |
-
|
174 |
|
175 |
-
|
176 |
iface = create_interface()
|
177 |
iface.launch()
|
|
|
9 |
api_key=ACCESS_TOKEN,
|
10 |
)
|
11 |
|
12 |
+
def generate_study_material(
|
13 |
topic,
|
14 |
difficulty,
|
15 |
question_type,
|
|
|
63 |
- End with a positive reinforcement message
|
64 |
"""
|
65 |
|
66 |
+
try:
|
67 |
messages = [
|
68 |
{"role": "system", "content": "You are an expert educational content generator."},
|
69 |
{"role": "user", "content": base_prompt}
|
|
|
77 |
top_p=0.9
|
78 |
)
|
79 |
|
80 |
+
return response.choices[0].message.content
|
81 |
|
82 |
+
except Exception as e:
|
83 |
+
return f"An error occurred: {str(e)}\nPlease try again with different parameters."
|
84 |
|
85 |
+
def create_interface():
|
86 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as iface:
|
87 |
gr.Markdown("""
|
88 |
# <div align="center"><strong>📚 Exam Preparation Assistant</strong></div>
|
89 |
|
|
|
95 |
Remember: Every practice session brings you closer to mastery! 🌟
|
96 |
""")
|
97 |
|
98 |
+
with gr.Row():
|
99 |
+
with gr.Column():
|
100 |
topic = gr.Textbox(
|
101 |
label="Topic or Subject",
|
102 |
placeholder="Enter the topic you want to study (e.g., 'Python Lists and Tuples', 'Chemical Bonding')",
|
|
|
149 |
variant="primary"
|
150 |
)
|
151 |
|
152 |
+
with gr.Column():
|
153 |
output = gr.Textbox(
|
154 |
label="Your Personalized Study Material",
|
155 |
lines=20,
|
156 |
show_copy_button=True
|
157 |
)
|
158 |
|
159 |
+
# Example scenarios
|
160 |
+
gr.Examples(
|
161 |
+
examples=[
|
162 |
+
[
|
163 |
+
"Python Functions and Basic Programming",
|
164 |
+
"Beginner",
|
165 |
+
"Multiple Choice",
|
166 |
+
"concept_understanding",
|
167 |
+
"High",
|
168 |
+
5
|
169 |
+
],
|
170 |
+
[
|
171 |
+
"Data Structures - Arrays and Linked Lists",
|
172 |
+
"Intermediate",
|
173 |
+
"Short Answer",
|
174 |
+
"problem_solving",
|
175 |
+
"Medium",
|
176 |
+
5
|
177 |
+
],
|
178 |
+
[
|
179 |
+
"Advanced Algorithms - Dynamic Programming",
|
180 |
+
"Advanced",
|
181 |
+
"Descriptive",
|
182 |
+
"practical_application",
|
183 |
+
"Low",
|
184 |
+
3
|
185 |
+
]
|
186 |
+
],
|
187 |
+
inputs=[
|
188 |
+
topic,
|
189 |
+
difficulty,
|
190 |
+
question_type,
|
191 |
+
focus_areas,
|
192 |
+
anxiety_level,
|
193 |
+
num_questions
|
194 |
+
],
|
195 |
+
outputs=output,
|
196 |
+
fn=generate_study_material,
|
197 |
+
cache_examples=True
|
198 |
+
)
|
199 |
+
|
200 |
+
# Usage tips
|
201 |
+
gr.Markdown("""
|
202 |
+
### 💡 Tips for Best Results
|
203 |
+
1. **Be Specific** with your topic - instead of "Math", try "Quadratic Equations"
|
204 |
+
2. **Match the Difficulty** to your current understanding
|
205 |
+
3. **Vary Question Types** to improve overall understanding
|
206 |
+
4. **Be Honest** about your anxiety level - it helps us provide better support
|
207 |
+
|
208 |
+
### 🎯 Learning Focus Options
|
209 |
+
- **Concept Understanding**: Deep grasp of fundamental principles
|
210 |
+
- **Problem Solving**: Analytical and application skills
|
211 |
+
- **Quick Recall**: Key definitions and core concepts
|
212 |
+
- **Practical Application**: Real-world usage and examples
|
213 |
+
|
214 |
+
### 🌟 Remember
|
215 |
+
- Take regular breaks
|
216 |
+
- Practice consistently
|
217 |
+
- Focus on understanding, not just memorizing
|
218 |
+
- Each practice session improves your knowledge!
|
219 |
+
""")
|
220 |
|
221 |
submit_btn.click(
|
222 |
+
fn=generate_study_material,
|
223 |
inputs=[
|
224 |
topic,
|
225 |
difficulty,
|
|
|
231 |
outputs=output
|
232 |
)
|
233 |
|
234 |
+
return iface
|
235 |
|
236 |
+
if __name__ == "__main__":
|
237 |
iface = create_interface()
|
238 |
iface.launch()
|