shukdevdatta123 commited on
Commit
ca71860
Β·
verified Β·
1 Parent(s): d4a7201

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +564 -199
app.py CHANGED
@@ -169,7 +169,7 @@ def generate_content(prompt: str, max_tokens: int = 2000) -> str:
169
  messages=[
170
  {
171
  "role": "system",
172
- "content": "You are an expert educational content creator. Create comprehensive, engaging, and pedagogically sound educational materials based on the provided document content."
173
  },
174
  {
175
  "role": "user",
@@ -189,92 +189,296 @@ def generate_content(prompt: str, max_tokens: int = 2000) -> str:
189
  print(f"API Error: {error_msg}") # Debug print
190
  return error_msg
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  # Content generation functions with @spaces.GPU decorator
193
  @spaces.GPU
194
  def generate_summary():
195
  """Generate comprehensive summary"""
196
- prompt = """Create a comprehensive summary of this document with the following structure:
197
-
198
- ## πŸ“‹ Executive Summary
199
- Provide a brief overview in 2-3 sentences.
200
-
201
- ## 🎯 Key Points
202
- List the main concepts, ideas, or arguments presented.
203
-
204
- ## πŸ“š Detailed Summary
205
- Provide a thorough summary organized by topics or sections.
206
-
207
- ## πŸ’‘ Important Takeaways
208
- Highlight the most crucial information students should remember.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  """
210
  return generate_content(prompt)
211
 
212
  @spaces.GPU
213
  def generate_study_notes():
214
  """Generate structured study notes"""
215
- prompt = """Create comprehensive study notes from this document with:
216
-
217
- ## πŸ“– Study Notes
218
-
219
- ### πŸ”‘ Key Concepts
220
- - Define important terms and concepts
221
- - Explain their significance
222
-
223
- ### πŸ“Š Main Topics
224
- Organize content into clear sections with:
225
- - Topic headings
226
- - Key points under each topic
227
- - Supporting details and examples
228
-
229
- ### 🧠 Memory Aids
230
- - Create mnemonics for complex information
231
- - Suggest visualization techniques
232
- - Provide connection points between concepts
233
-
234
- ### ⚑ Quick Review Points
235
- - Bullet points for rapid review
236
- - Essential facts and figures
 
 
 
 
 
 
 
 
 
 
237
  """
238
  return generate_content(prompt)
239
 
240
  @spaces.GPU
241
  def generate_quiz():
242
  """Generate quiz questions"""
243
- prompt = """Create a comprehensive quiz based on this document:
244
-
245
- ## πŸ“ Quiz Questions
246
-
247
- ### Multiple Choice Questions (5 questions)
248
- For each question, provide:
249
- - Clear question
250
- - 4 options (A, B, C, D)
251
- - Correct answer
252
- - Brief explanation
253
-
254
- ### Short Answer Questions (5 questions)
255
- - Questions requiring 2-3 sentence answers
256
- - Cover key concepts and applications
257
-
258
- ### Essay Questions (2 questions)
259
- - Thought-provoking questions requiring detailed responses
260
- - Focus on analysis, synthesis, or evaluation
261
-
262
- ### Answer Key
263
- Provide all correct answers with explanations.
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  """
265
  return generate_content(prompt, max_tokens=3000)
266
 
267
  @spaces.GPU
268
  def generate_flashcards():
269
- """Generate flashcards"""
270
- prompt = """Create 15-20 flashcards based on this document:
 
 
 
 
 
271
 
272
- ## 🎴 Flashcards
 
 
 
 
 
 
 
 
 
 
273
 
274
- Format each flashcard as:
275
- **Card X:**
276
- **Front:** [Question/Term]
277
- **Back:** [Answer/Definition/Explanation]
278
 
279
  Include flashcards for:
280
  - Key terms and definitions
@@ -283,148 +487,202 @@ def generate_flashcards():
283
  - Cause and effect relationships
284
  - Applications and examples
285
 
286
- Make questions clear and answers comprehensive but concise.
287
  """
288
  return generate_content(prompt, max_tokens=2500)
289
 
290
  @spaces.GPU
291
  def generate_mind_map():
292
  """Generate mind map structure"""
293
- prompt = """Create a detailed mind map structure for this document:
294
-
295
- ## 🧠 Mind Map Structure
296
-
297
- **Central Topic:** [Main subject of the document]
298
-
299
- ### Primary Branches:
300
- For each main topic, create branches with:
301
- - **Branch 1:** [Topic Name]
302
- - Sub-branch 1.1: [Subtopic]
303
- - Detail 1.1.1
304
- - Detail 1.1.2
305
- - Sub-branch 1.2: [Subtopic]
306
- - Detail 1.2.1
307
- - Detail 1.2.2
308
-
309
- ### Connections:
310
- - Identify relationships between different branches
311
- - Note cross-references and dependencies
312
- - Highlight cause-effect relationships
313
-
314
- ### Visual Elements Suggestions:
315
- - Color coding recommendations
316
- - Symbol suggestions for different types of information
317
- - Emphasis techniques for key concepts
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  """
319
  return generate_content(prompt)
320
 
321
  @spaces.GPU
322
  def generate_lesson_plan():
323
  """Generate lesson plan"""
324
- prompt = """Create a detailed lesson plan based on this document:
325
-
326
- ## πŸ“š Lesson Plan
327
-
328
- ### Learning Objectives
329
- By the end of this lesson, students will be able to:
330
- - [Specific, measurable objectives]
331
-
332
- ### Prerequisites
333
- - Required background knowledge
334
- - Recommended prior reading
335
-
336
- ### Lesson Structure (60 minutes)
337
-
338
- **Introduction (10 minutes)**
339
- - Hook/attention grabber
340
- - Learning objectives overview
341
-
342
- **Main Content (35 minutes)**
343
- - Key concepts presentation
344
- - Activities and examples
345
- - Discussion points
346
-
347
- **Practice & Application (10 minutes)**
348
- - Practice exercises
349
- - Real-world applications
350
-
351
- **Wrap-up & Assessment (5 minutes)**
352
- - Summary of key points
353
- - Quick assessment questions
354
-
355
- ### Materials Needed
356
- - List of required resources
357
-
358
- ### Assessment Methods
359
- - How to evaluate student understanding
360
-
361
- ### Homework/Extension Activities
362
- - Additional practice opportunities
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
  """
364
  return generate_content(prompt, max_tokens=2500)
365
 
366
  @spaces.GPU
367
  def generate_concept_explanations():
368
  """Generate detailed concept explanations"""
369
- prompt = """Provide detailed explanations of key concepts from this document:
370
 
371
- ## πŸ” Concept Deep Dive
372
 
373
- For each major concept, provide:
374
 
375
- ### Concept Name
376
- **Definition:** Clear, precise definition
 
377
 
378
- **Explanation:** Detailed explanation in simple terms
379
 
380
- **Examples:** Real-world examples and applications
381
 
382
- **Analogies:** Helpful comparisons to familiar concepts
383
 
384
- **Common Misconceptions:** What students often get wrong
385
 
386
- **Connection to Other Concepts:** How it relates to other topics
387
 
388
- **Practice Application:** Simple exercise or question
 
389
 
390
- ---
391
 
392
- Repeat this structure for all major concepts in the document.
393
  """
394
  return generate_content(prompt, max_tokens=3000)
395
 
396
  @spaces.GPU
397
  def generate_practice_problems():
398
  """Generate practice problems"""
399
- prompt = """Create practice problems based on this document:
400
-
401
- ## πŸ’ͺ Practice Problems
402
-
403
- ### Beginner Level (5 problems)
404
- - Basic application of concepts
405
- - Direct recall and simple calculations
406
- - Step-by-step solutions provided
407
-
408
- ### Intermediate Level (5 problems)
409
- - Multi-step problems
410
- - Requires understanding of relationships
411
- - Guided solutions with explanations
412
-
413
- ### Advanced Level (3 problems)
414
- - Complex scenarios
415
- - Requires analysis and synthesis
416
- - Detailed solution strategies
417
-
418
- ### Challenge Problems (2 problems)
419
- - Extension beyond document content
420
- - Creative application
421
- - Multiple solution approaches
422
-
423
- **For each problem, include:**
424
- - Clear problem statement
425
- - Required formulas/concepts
426
- - Step-by-step solution
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
  - Common mistakes to avoid
 
 
428
  """
429
  return generate_content(prompt, max_tokens=3500)
430
 
@@ -451,9 +709,13 @@ def create_interface():
451
  with gr.Blocks(title="πŸ“š Educational Content Creator Assistant", theme=gr.themes.Soft()) as app:
452
  gr.Markdown("""
453
  # πŸ“š Educational Content Creator Assistant
454
- Transform your documents into comprehensive educational materials using AI!
455
 
456
- **Features:** Study Notes β€’ Quizzes β€’ Flashcards β€’ Mind Maps β€’ Lesson Plans β€’ Practice Problems & More!
 
 
 
 
457
 
458
  *Powered by ZeroGPU for enhanced performance*
459
  """)
@@ -495,7 +757,7 @@ def create_interface():
495
  quiz_btn = gr.Button("πŸ“ Create Quiz", variant="primary")
496
 
497
  with gr.Row():
498
- flashcards_btn = gr.Button("🎴 Flashcards", variant="secondary")
499
  mindmap_btn = gr.Button("🧠 Mind Map", variant="secondary")
500
  lesson_btn = gr.Button("πŸ“š Lesson Plan", variant="secondary")
501
 
@@ -503,13 +765,16 @@ def create_interface():
503
  concepts_btn = gr.Button("πŸ” Concept Explanations", variant="secondary")
504
  problems_btn = gr.Button("πŸ’ͺ Practice Problems", variant="secondary")
505
 
506
- output = gr.Textbox(
507
- label="Generated Content",
508
- lines=20,
509
- max_lines=30,
510
- placeholder="Generated educational content will appear here...",
511
- show_copy_button=True
512
  )
 
 
 
 
 
513
 
514
  gr.Markdown("""
515
  ### πŸ“‹ How to Use:
@@ -517,27 +782,40 @@ def create_interface():
517
  2. **Configure:** Enter your API key and click "Configure API"
518
  3. **Upload:** Upload a PDF or DOCX document (make sure it contains readable text)
519
  4. **Process:** Click "Process Document" to extract text
520
- 5. **Generate:** Choose any educational content type to generate
521
-
522
- ### 🎯 Content Types:
523
- - **Summary:** Comprehensive overview with key points
524
- - **Study Notes:** Structured notes with key concepts and memory aids
525
- - **Quiz:** Multiple choice, short answer, and essay questions with answers
526
- - **Flashcards:** Question-answer pairs for memorization
527
- - **Mind Map:** Visual structure of document concepts
528
- - **Lesson Plan:** Complete teaching plan with objectives and activities
529
- - **Concept Explanations:** Deep dive into key concepts with examples
530
- - **Practice Problems:** Graded exercises from beginner to advanced
 
 
 
 
 
 
 
531
 
532
  ### πŸ’‘ Tips:
533
  - Make sure your PDF contains selectable text (not just images)
534
  - For best results, use documents with clear structure and headings
535
  - The app works with academic papers, textbooks, reports, and study materials
 
 
536
 
537
  ### ⚑ Performance Note:
538
  This app uses ZeroGPU for enhanced processing. Functions will automatically utilize GPU resources when needed.
539
  """)
540
 
 
 
 
 
541
  # Event handlers
542
  def setup_api_and_update_status(api_key):
543
  result = setup_client(api_key)
@@ -560,15 +838,102 @@ def create_interface():
560
  outputs=[process_status, doc_status]
561
  )
562
 
563
- # Content generation button handlers
564
- summary_btn.click(generate_summary, outputs=[output])
565
- notes_btn.click(generate_study_notes, outputs=[output])
566
- quiz_btn.click(generate_quiz, outputs=[output])
567
- flashcards_btn.click(generate_flashcards, outputs=[output])
568
- mindmap_btn.click(generate_mind_map, outputs=[output])
569
- lesson_btn.click(generate_lesson_plan, outputs=[output])
570
- concepts_btn.click(generate_concept_explanations, outputs=[output])
571
- problems_btn.click(generate_practice_problems, outputs=[output])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
572
 
573
  # Update status on app load
574
  def update_initial_status():
 
169
  messages=[
170
  {
171
  "role": "system",
172
+ "content": "You are an expert educational content creator. Create comprehensive, engaging, and pedagogically sound educational materials based on the provided document content. Format your response using proper HTML tags for better presentation."
173
  },
174
  {
175
  "role": "user",
 
189
  print(f"API Error: {error_msg}") # Debug print
190
  return error_msg
191
 
192
+ def create_download_file(content: str, filename: str) -> str:
193
+ """Create downloadable HTML file"""
194
+ html_template = f"""
195
+ <!DOCTYPE html>
196
+ <html lang="en">
197
+ <head>
198
+ <meta charset="UTF-8">
199
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
200
+ <title>Educational Content - {filename}</title>
201
+ <style>
202
+ body {{
203
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
204
+ line-height: 1.6;
205
+ margin: 0;
206
+ padding: 20px;
207
+ background-color: #f5f5f5;
208
+ }}
209
+ .container {{
210
+ max-width: 1200px;
211
+ margin: 0 auto;
212
+ background: white;
213
+ padding: 30px;
214
+ border-radius: 10px;
215
+ box-shadow: 0 0 20px rgba(0,0,0,0.1);
216
+ }}
217
+ h1, h2, h3, h4, h5, h6 {{
218
+ color: #2c3e50;
219
+ margin-top: 30px;
220
+ margin-bottom: 15px;
221
+ }}
222
+ .flashcard {{
223
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
224
+ border-radius: 15px;
225
+ padding: 20px;
226
+ margin: 15px;
227
+ box-shadow: 0 8px 25px rgba(0,0,0,0.15);
228
+ cursor: pointer;
229
+ transition: all 0.3s ease;
230
+ color: white;
231
+ position: relative;
232
+ min-height: 150px;
233
+ display: flex;
234
+ flex-direction: column;
235
+ justify-content: center;
236
+ }}
237
+ .flashcard:hover {{
238
+ transform: translateY(-5px);
239
+ box-shadow: 0 12px 35px rgba(0,0,0,0.25);
240
+ }}
241
+ .flashcard-front, .flashcard-back {{
242
+ text-align: center;
243
+ }}
244
+ .flashcard-back {{
245
+ display: none;
246
+ }}
247
+ .play-btn {{
248
+ position: absolute;
249
+ top: 10px;
250
+ right: 15px;
251
+ background: rgba(255,255,255,0.2);
252
+ border: none;
253
+ border-radius: 50%;
254
+ width: 40px;
255
+ height: 40px;
256
+ font-size: 16px;
257
+ color: white;
258
+ cursor: pointer;
259
+ transition: all 0.3s ease;
260
+ }}
261
+ .play-btn:hover {{
262
+ background: rgba(255,255,255,0.3);
263
+ transform: scale(1.1);
264
+ }}
265
+ .quiz-question {{
266
+ background: #f8f9fa;
267
+ border-left: 4px solid #007bff;
268
+ padding: 15px;
269
+ margin: 15px 0;
270
+ border-radius: 5px;
271
+ }}
272
+ .answer-key {{
273
+ background: #d4edda;
274
+ border: 1px solid #c3e6cb;
275
+ padding: 15px;
276
+ border-radius: 5px;
277
+ margin: 10px 0;
278
+ }}
279
+ .concept-box {{
280
+ background: #fff3cd;
281
+ border: 1px solid #ffeaa7;
282
+ border-radius: 8px;
283
+ padding: 20px;
284
+ margin: 15px 0;
285
+ }}
286
+ .mind-map-branch {{
287
+ background: #e3f2fd;
288
+ border-left: 4px solid #2196f3;
289
+ padding: 15px;
290
+ margin: 10px 0;
291
+ border-radius: 5px;
292
+ }}
293
+ .print-btn {{
294
+ position: fixed;
295
+ top: 20px;
296
+ right: 20px;
297
+ background: #007bff;
298
+ color: white;
299
+ border: none;
300
+ padding: 10px 20px;
301
+ border-radius: 5px;
302
+ cursor: pointer;
303
+ font-size: 14px;
304
+ }}
305
+ @media print {{
306
+ .print-btn {{ display: none; }}
307
+ body {{ background: white; }}
308
+ .container {{ box-shadow: none; }}
309
+ }}
310
+ </style>
311
+ </head>
312
+ <body>
313
+ <button class="print-btn" onclick="window.print()">πŸ–¨οΈ Print</button>
314
+ <div class="container">
315
+ {content}
316
+ </div>
317
+ <script>
318
+ function toggleCard(cardId) {{
319
+ const front = document.getElementById(cardId + '-front');
320
+ const back = document.getElementById(cardId + '-back');
321
+ const btn = document.getElementById(cardId + '-btn');
322
+
323
+ if (front.style.display !== 'none') {{
324
+ front.style.display = 'none';
325
+ back.style.display = 'block';
326
+ btn.innerHTML = 'πŸ”„';
327
+ }} else {{
328
+ front.style.display = 'block';
329
+ back.style.display = 'none';
330
+ btn.innerHTML = '▢️';
331
+ }}
332
+ }}
333
+ </script>
334
+ </body>
335
+ </html>
336
+ """
337
+
338
+ # Save to temporary file
339
+ temp_filename = f"temp_{filename}.html"
340
+ with open(temp_filename, 'w', encoding='utf-8') as f:
341
+ f.write(html_template)
342
+
343
+ return temp_filename
344
+
345
  # Content generation functions with @spaces.GPU decorator
346
  @spaces.GPU
347
  def generate_summary():
348
  """Generate comprehensive summary"""
349
+ prompt = """Create a comprehensive summary of this document with proper HTML formatting:
350
+
351
+ Use these HTML tags for structure:
352
+ - <h1> for main title
353
+ - <h2> for section headers (Executive Summary, Key Points, etc.)
354
+ - <h3> for subsections
355
+ - <ul> and <li> for bullet points
356
+ - <p> for paragraphs
357
+ - <strong> for emphasis
358
+ - <div class="concept-box"> for important concepts
359
+
360
+ Structure:
361
+ <h1>πŸ“‹ Document Summary</h1>
362
+
363
+ <h2>🎯 Executive Summary</h2>
364
+ <p>Provide a brief overview in 2-3 sentences.</p>
365
+
366
+ <h2>πŸ”‘ Key Points</h2>
367
+ <ul>
368
+ <li>List the main concepts, ideas, or arguments presented</li>
369
+ </ul>
370
+
371
+ <h2>πŸ“š Detailed Summary</h2>
372
+ <p>Provide a thorough summary organized by topics or sections.</p>
373
+
374
+ <h2>πŸ’‘ Important Takeaways</h2>
375
+ <div class="concept-box">
376
+ <p>Highlight the most crucial information students should remember.</p>
377
+ </div>
378
  """
379
  return generate_content(prompt)
380
 
381
  @spaces.GPU
382
  def generate_study_notes():
383
  """Generate structured study notes"""
384
+ prompt = """Create comprehensive study notes from this document using proper HTML formatting:
385
+
386
+ Use HTML structure with:
387
+ - <h1> for main title: Study Notes
388
+ - <h2> for major sections
389
+ - <h3> for subsections
390
+ - <ul><li> for lists
391
+ - <div class="concept-box"> for key concepts
392
+ - <strong> for important terms
393
+
394
+ Structure:
395
+ <h1>πŸ“– Study Notes</h1>
396
+
397
+ <h2>πŸ”‘ Key Concepts</h2>
398
+ <div class="concept-box">
399
+ Define important terms and concepts with their significance
400
+ </div>
401
+
402
+ <h2>πŸ“Š Main Topics</h2>
403
+ Organize content into clear sections with topic headings, key points, and supporting details
404
+
405
+ <h2>🧠 Memory Aids</h2>
406
+ <ul>
407
+ <li>Mnemonics for complex information</li>
408
+ <li>Visualization techniques</li>
409
+ <li>Connection points between concepts</li>
410
+ </ul>
411
+
412
+ <h2>⚑ Quick Review Points</h2>
413
+ <ul>
414
+ <li>Essential facts and figures for rapid review</li>
415
+ </ul>
416
  """
417
  return generate_content(prompt)
418
 
419
  @spaces.GPU
420
  def generate_quiz():
421
  """Generate quiz questions"""
422
+ prompt = """Create a comprehensive quiz based on this document using HTML formatting:
423
+
424
+ <h1>πŸ“ Quiz Questions</h1>
425
+
426
+ <h2>Multiple Choice Questions</h2>
427
+ For each question, use this format:
428
+ <div class="quiz-question">
429
+ <h3>Question 1:</h3>
430
+ <p>[Question text]</p>
431
+ <ol type="A">
432
+ <li>Option A</li>
433
+ <li>Option B</li>
434
+ <li>Option C</li>
435
+ <li>Option D</li>
436
+ </ol>
437
+ </div>
438
+
439
+ <h2>Short Answer Questions</h2>
440
+ <div class="quiz-question">
441
+ Questions requiring 2-3 sentence answers covering key concepts
442
+ </div>
443
+
444
+ <h2>Essay Questions</h2>
445
+ <div class="quiz-question">
446
+ Thought-provoking questions requiring detailed responses
447
+ </div>
448
+
449
+ <h2>πŸ“š Answer Key</h2>
450
+ <div class="answer-key">
451
+ <h3>Multiple Choice Answers:</h3>
452
+ <p>Provide all correct answers with explanations</p>
453
+ </div>
454
+
455
+ Create 5 multiple choice, 5 short answer, and 2 essay questions.
456
  """
457
  return generate_content(prompt, max_tokens=3000)
458
 
459
  @spaces.GPU
460
  def generate_flashcards():
461
+ """Generate interactive flashcards"""
462
+ prompt = """Create 15-20 interactive flashcards based on this document.
463
+
464
+ Format each flashcard using this exact HTML structure:
465
+
466
+ <h1>🎴 Interactive Flashcards</h1>
467
+ <p><em>Click the play button (▢️) on each card to reveal the answer!</em></p>
468
 
469
+ <div class="flashcard" onclick="toggleCard('card1')">
470
+ <button class="play-btn" id="card1-btn">▢️</button>
471
+ <div class="flashcard-front" id="card1-front">
472
+ <h3>Card 1</h3>
473
+ <p><strong>[Question/Term]</strong></p>
474
+ </div>
475
+ <div class="flashcard-back" id="card1-back">
476
+ <h3>Answer</h3>
477
+ <p>[Answer/Definition/Explanation]</p>
478
+ </div>
479
+ </div>
480
 
481
+ Continue this pattern for each flashcard, incrementing the card numbers (card2, card3, etc.).
 
 
 
482
 
483
  Include flashcards for:
484
  - Key terms and definitions
 
487
  - Cause and effect relationships
488
  - Applications and examples
489
 
490
+ Make questions clear and answers comprehensive but concise. Use proper HTML formatting throughout.
491
  """
492
  return generate_content(prompt, max_tokens=2500)
493
 
494
  @spaces.GPU
495
  def generate_mind_map():
496
  """Generate mind map structure"""
497
+ prompt = """Create a detailed mind map structure for this document using HTML:
498
+
499
+ <h1>🧠 Mind Map Structure</h1>
500
+
501
+ <div class="concept-box">
502
+ <h2>Central Topic:</h2>
503
+ <p><strong>[Main subject of the document]</strong></p>
504
+ </div>
505
+
506
+ <h2>Primary Branches:</h2>
507
+
508
+ For each main topic, create branches using this structure:
509
+ <div class="mind-map-branch">
510
+ <h3>Branch 1: [Topic Name]</h3>
511
+ <ul>
512
+ <li><strong>Sub-branch 1.1:</strong> [Subtopic]
513
+ <ul>
514
+ <li>Detail 1.1.1</li>
515
+ <li>Detail 1.1.2</li>
516
+ </ul>
517
+ </li>
518
+ </ul>
519
+ </div>
520
+
521
+ <h2>πŸ”— Connections</h2>
522
+ <div class="concept-box">
523
+ <ul>
524
+ <li>Relationships between different branches</li>
525
+ <li>Cross-references and dependencies</li>
526
+ <li>Cause-effect relationships</li>
527
+ </ul>
528
+ </div>
529
+
530
+ <h2>🎨 Visual Elements Suggestions</h2>
531
+ <ul>
532
+ <li>Color coding recommendations</li>
533
+ <li>Symbol suggestions for different types of information</li>
534
+ <li>Emphasis techniques for key concepts</li>
535
+ </ul>
536
  """
537
  return generate_content(prompt)
538
 
539
  @spaces.GPU
540
  def generate_lesson_plan():
541
  """Generate lesson plan"""
542
+ prompt = """Create a detailed lesson plan based on this document using HTML formatting:
543
+
544
+ <h1>πŸ“š Lesson Plan</h1>
545
+
546
+ <h2>🎯 Learning Objectives</h2>
547
+ <p>By the end of this lesson, students will be able to:</p>
548
+ <ul>
549
+ <li>[Specific, measurable objectives]</li>
550
+ </ul>
551
+
552
+ <h2>πŸ“‹ Prerequisites</h2>
553
+ <div class="concept-box">
554
+ <ul>
555
+ <li>Required background knowledge</li>
556
+ <li>Recommended prior reading</li>
557
+ </ul>
558
+ </div>
559
+
560
+ <h2>⏰ Lesson Structure (60 minutes)</h2>
561
+
562
+ <h3>Introduction (10 minutes)</h3>
563
+ <ul>
564
+ <li>Hook/attention grabber</li>
565
+ <li>Learning objectives overview</li>
566
+ </ul>
567
+
568
+ <h3>Main Content (35 minutes)</h3>
569
+ <ul>
570
+ <li>Key concepts presentation</li>
571
+ <li>Activities and examples</li>
572
+ <li>Discussion points</li>
573
+ </ul>
574
+
575
+ <h3>Practice & Application (10 minutes)</h3>
576
+ <ul>
577
+ <li>Practice exercises</li>
578
+ <li>Real-world applications</li>
579
+ </ul>
580
+
581
+ <h3>Wrap-up & Assessment (5 minutes)</h3>
582
+ <ul>
583
+ <li>Summary of key points</li>
584
+ <li>Quick assessment questions</li>
585
+ </ul>
586
+
587
+ <h2>πŸ“¦ Materials Needed</h2>
588
+ <ul>
589
+ <li>List of required resources</li>
590
+ </ul>
591
+
592
+ <h2>πŸ“Š Assessment Methods</h2>
593
+ <div class="answer-key">
594
+ <p>How to evaluate student understanding</p>
595
+ </div>
596
+
597
+ <h2>πŸ“ Homework/Extension Activities</h2>
598
+ <ul>
599
+ <li>Additional practice opportunities</li>
600
+ </ul>
601
  """
602
  return generate_content(prompt, max_tokens=2500)
603
 
604
  @spaces.GPU
605
  def generate_concept_explanations():
606
  """Generate detailed concept explanations"""
607
+ prompt = """Provide detailed explanations of key concepts from this document using HTML:
608
 
609
+ <h1>πŸ” Concept Deep Dive</h1>
610
 
611
+ For each major concept, use this structure:
612
 
613
+ <div class="concept-box">
614
+ <h2>[Concept Name]</h2>
615
+ <p><strong>Definition:</strong> Clear, precise definition</p>
616
 
617
+ <p><strong>Explanation:</strong> Detailed explanation in simple terms</p>
618
 
619
+ <p><strong>Examples:</strong> Real-world examples and applications</p>
620
 
621
+ <p><strong>Analogies:</strong> Helpful comparisons to familiar concepts</p>
622
 
623
+ <p><strong>Common Misconceptions:</strong> What students often get wrong</p>
624
 
625
+ <p><strong>Connection to Other Concepts:</strong> How it relates to other topics</p>
626
 
627
+ <p><strong>Practice Application:</strong> Simple exercise or question</p>
628
+ </div>
629
 
630
+ <hr>
631
 
632
+ Repeat this structure for all major concepts in the document using proper HTML formatting.
633
  """
634
  return generate_content(prompt, max_tokens=3000)
635
 
636
  @spaces.GPU
637
  def generate_practice_problems():
638
  """Generate practice problems"""
639
+ prompt = """Create practice problems based on this document using HTML formatting:
640
+
641
+ <h1>πŸ’ͺ Practice Problems</h1>
642
+
643
+ <h2>🟒 Beginner Level</h2>
644
+ <div class="quiz-question">
645
+ <h3>Problem 1:</h3>
646
+ <p>[Problem statement]</p>
647
+ <div class="answer-key">
648
+ <p><strong>Solution:</strong> Step-by-step solution provided</p>
649
+ </div>
650
+ </div>
651
+
652
+ <h2>🟑 Intermediate Level</h2>
653
+ <div class="quiz-question">
654
+ <h3>Problem 1:</h3>
655
+ <p>[Multi-step problem requiring understanding of relationships]</p>
656
+ <div class="answer-key">
657
+ <p><strong>Solution:</strong> Guided solutions with explanations</p>
658
+ </div>
659
+ </div>
660
+
661
+ <h2>πŸ”΄ Advanced Level</h2>
662
+ <div class="quiz-question">
663
+ <h3>Problem 1:</h3>
664
+ <p>[Complex scenarios requiring analysis and synthesis]</p>
665
+ <div class="answer-key">
666
+ <p><strong>Solution:</strong> Detailed solution strategies</p>
667
+ </div>
668
+ </div>
669
+
670
+ <h2>πŸ† Challenge Problems</h2>
671
+ <div class="concept-box">
672
+ <h3>Challenge 1:</h3>
673
+ <p>[Extension beyond document content with creative application]</p>
674
+ <div class="answer-key">
675
+ <p><strong>Multiple Solution Approaches:</strong> Various ways to solve</p>
676
+ </div>
677
+ </div>
678
+
679
+ For each problem, include:
680
+ - Clear problem statement with HTML formatting
681
+ - Required formulas/concepts in <strong> tags
682
+ - Step-by-step solution in answer-key divs
683
  - Common mistakes to avoid
684
+
685
+ Create 5 beginner, 5 intermediate, 3 advanced, and 2 challenge problems.
686
  """
687
  return generate_content(prompt, max_tokens=3500)
688
 
 
709
  with gr.Blocks(title="πŸ“š Educational Content Creator Assistant", theme=gr.themes.Soft()) as app:
710
  gr.Markdown("""
711
  # πŸ“š Educational Content Creator Assistant
712
+ Transform your documents into comprehensive educational materials using AI with interactive features!
713
 
714
+ **New Features:**
715
+ - 🎴 Interactive Flashcards with Play Buttons
716
+ - πŸ“„ HTML Formatted Responses
717
+ - πŸ’Ύ Download All Content as HTML Files
718
+ - πŸ–¨οΈ Print-Ready Formats
719
 
720
  *Powered by ZeroGPU for enhanced performance*
721
  """)
 
757
  quiz_btn = gr.Button("πŸ“ Create Quiz", variant="primary")
758
 
759
  with gr.Row():
760
+ flashcards_btn = gr.Button("🎴 Interactive Flashcards", variant="secondary")
761
  mindmap_btn = gr.Button("🧠 Mind Map", variant="secondary")
762
  lesson_btn = gr.Button("πŸ“š Lesson Plan", variant="secondary")
763
 
 
765
  concepts_btn = gr.Button("πŸ” Concept Explanations", variant="secondary")
766
  problems_btn = gr.Button("πŸ’ͺ Practice Problems", variant="secondary")
767
 
768
+ # HTML output with download capability
769
+ output = gr.HTML(
770
+ label="Generated Content (Interactive)",
771
+ value="<p>Generated educational content will appear here with interactive features...</p>"
 
 
772
  )
773
+
774
+ # Download buttons
775
+ with gr.Row():
776
+ download_file = gr.File(label="πŸ“₯ Download Content", visible=False)
777
+ download_btn = gr.Button("πŸ’Ύ Prepare Download", variant="secondary", visible=False)
778
 
779
  gr.Markdown("""
780
  ### πŸ“‹ How to Use:
 
782
  2. **Configure:** Enter your API key and click "Configure API"
783
  3. **Upload:** Upload a PDF or DOCX document (make sure it contains readable text)
784
  4. **Process:** Click "Process Document" to extract text
785
+ 5. **Generate:** Choose any educational content type to generate interactive HTML content
786
+ 6. **Download:** Use the "Prepare Download" button to get an HTML file with all content
787
+
788
+ ### 🎯 Enhanced Content Types:
789
+ - **πŸ“‹ Summary:** Comprehensive overview with styled HTML sections
790
+ - **πŸ“– Study Notes:** Structured notes with highlighted key concepts
791
+ - **πŸ“ Quiz:** Interactive quiz with styled questions and answer keys
792
+ - **🎴 Interactive Flashcards:** Click-to-flip cards with play buttons!
793
+ - **🧠 Mind Map:** Visual structure with styled branches
794
+ - **πŸ“š Lesson Plan:** Complete teaching plan with time management
795
+ - **πŸ” Concept Explanations:** Deep dive with styled concept boxes
796
+ - **πŸ’ͺ Practice Problems:** Graded exercises with solution reveals
797
+
798
+ ### ✨ New Interactive Features:
799
+ - **🎴 Flashcards:** Click the play button (▢️) to flip cards and see answers
800
+ - **πŸ“„ HTML Formatting:** All content now uses proper HTML styling
801
+ - **πŸ’Ύ Download:** Get complete HTML files with embedded CSS and JavaScript
802
+ - **πŸ–¨οΈ Print Ready:** Downloaded files include print-optimized styling
803
 
804
  ### πŸ’‘ Tips:
805
  - Make sure your PDF contains selectable text (not just images)
806
  - For best results, use documents with clear structure and headings
807
  - The app works with academic papers, textbooks, reports, and study materials
808
+ - Interactive flashcards work best when viewed in the HTML output
809
+ - Downloaded files can be opened in any web browser for offline use
810
 
811
  ### ⚑ Performance Note:
812
  This app uses ZeroGPU for enhanced processing. Functions will automatically utilize GPU resources when needed.
813
  """)
814
 
815
+ # Store the last generated content for download
816
+ last_content = gr.State("")
817
+ last_content_type = gr.State("")
818
+
819
  # Event handlers
820
  def setup_api_and_update_status(api_key):
821
  result = setup_client(api_key)
 
838
  outputs=[process_status, doc_status]
839
  )
840
 
841
+ # Enhanced content generation functions that return HTML and enable download
842
+ def generate_and_display_summary():
843
+ content = generate_summary()
844
+ return content, content, "summary", gr.update(visible=True)
845
+
846
+ def generate_and_display_notes():
847
+ content = generate_study_notes()
848
+ return content, content, "study_notes", gr.update(visible=True)
849
+
850
+ def generate_and_display_quiz():
851
+ content = generate_quiz()
852
+ return content, content, "quiz", gr.update(visible=True)
853
+
854
+ def generate_and_display_flashcards():
855
+ content = generate_flashcards()
856
+ return content, content, "flashcards", gr.update(visible=True)
857
+
858
+ def generate_and_display_mindmap():
859
+ content = generate_mind_map()
860
+ return content, content, "mind_map", gr.update(visible=True)
861
+
862
+ def generate_and_display_lesson():
863
+ content = generate_lesson_plan()
864
+ return content, content, "lesson_plan", gr.update(visible=True)
865
+
866
+ def generate_and_display_concepts():
867
+ content = generate_concept_explanations()
868
+ return content, content, "concept_explanations", gr.update(visible=True)
869
+
870
+ def generate_and_display_problems():
871
+ content = generate_practice_problems()
872
+ return content, content, "practice_problems", gr.update(visible=True)
873
+
874
+ # Download preparation function
875
+ def prepare_download(content, content_type):
876
+ if not content or content.startswith("❌"):
877
+ return None
878
+
879
+ # Create downloadable file
880
+ filename = f"educational_content_{content_type}"
881
+ temp_file = create_download_file(content, filename)
882
+ return temp_file
883
+
884
+ # Content generation button handlers with download capability
885
+ summary_btn.click(
886
+ generate_and_display_summary,
887
+ outputs=[output, last_content, last_content_type, download_btn]
888
+ )
889
+
890
+ notes_btn.click(
891
+ generate_and_display_notes,
892
+ outputs=[output, last_content, last_content_type, download_btn]
893
+ )
894
+
895
+ quiz_btn.click(
896
+ generate_and_display_quiz,
897
+ outputs=[output, last_content, last_content_type, download_btn]
898
+ )
899
+
900
+ flashcards_btn.click(
901
+ generate_and_display_flashcards,
902
+ outputs=[output, last_content, last_content_type, download_btn]
903
+ )
904
+
905
+ mindmap_btn.click(
906
+ generate_and_display_mindmap,
907
+ outputs=[output, last_content, last_content_type, download_btn]
908
+ )
909
+
910
+ lesson_btn.click(
911
+ generate_and_display_lesson,
912
+ outputs=[output, last_content, last_content_type, download_btn]
913
+ )
914
+
915
+ concepts_btn.click(
916
+ generate_and_display_concepts,
917
+ outputs=[output, last_content, last_content_type, download_btn]
918
+ )
919
+
920
+ problems_btn.click(
921
+ generate_and_display_problems,
922
+ outputs=[output, last_content, last_content_type, download_btn]
923
+ )
924
+
925
+ # Download button handler
926
+ def handle_download(content, content_type):
927
+ if content and not content.startswith("❌"):
928
+ temp_file = prepare_download(content, content_type)
929
+ return temp_file, gr.update(visible=True)
930
+ return None, gr.update(visible=False)
931
+
932
+ download_btn.click(
933
+ handle_download,
934
+ inputs=[last_content, last_content_type],
935
+ outputs=[download_file, download_file]
936
+ )
937
 
938
  # Update status on app load
939
  def update_initial_status():