Danielah17 commited on
Commit
9841228
ยท
verified ยท
1 Parent(s): 65971fd

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +186 -1
app.py CHANGED
@@ -309,6 +309,133 @@ def ai_study_helper(image, study_type):
309
  except Exception as e:
310
  return f"โŒ Error generating study insights: {str(e)}"
311
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
  # Custom CSS for professional styling
313
  custom_css = """
314
  .gradio-container {
@@ -684,8 +811,66 @@ with gr.Blocks(title="AI Multimedia Studio", theme=gr.themes.Soft(), css=custom_
684
  outputs=[study_output],
685
  show_progress="full"
686
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
687
 
688
- # Footer
689
  gr.HTML("""
690
  <div class="footer">
691
  <p>Powered by <strong>Hugging Face Transformers</strong> & <strong>Supertonic TTS</strong> |
 
309
  except Exception as e:
310
  return f"โŒ Error generating study insights: {str(e)}"
311
 
312
+ def ai_study_helper_for_kids(image, learning_style):
313
+ """
314
+ Provide AI-powered kid-friendly study assistance based on image content.
315
+ Uses simple language, fun facts, and gamified learning elements.
316
+
317
+ Args:
318
+ image: Input image (PIL Image or numpy array)
319
+ learning_style: Type of kid-friendly learning aid
320
+
321
+ Returns:
322
+ Kid-friendly study content with fun and engaging format
323
+ """
324
+ if image is None:
325
+ return "Please upload an image for your learning adventure! ๐ŸŒŸ"
326
+
327
+ try:
328
+ # Extract text from image
329
+ result = image_to_text(image)
330
+ extracted_text = result[0]['generated_text']
331
+
332
+ study_content = ""
333
+
334
+ if learning_style == "Fun Summary":
335
+ study_content = f"""
336
+ โœจ **FUN SUMMARY FOR KIDS!** โœจ
337
+
338
+ ๐Ÿ“– What We're Learning About:
339
+ {extracted_text}
340
+
341
+ ๐ŸŽฏ Super Cool Points to Remember:
342
+ โญ The main idea is: {extracted_text[:60]}...
343
+ โญ This is important because it helps us understand cool stuff!
344
+ โญ You can find examples of this everywhere around you!
345
+
346
+ ๐Ÿ’ก Fun Fact: Did you know? Learning by playing is the best way! ๐ŸŽฎ
347
+
348
+ โฑ๏ธ Perfect Study Time: 10-15 minutes is awesome! Then take a break! ๐ŸŽ‰
349
+ """
350
+
351
+ elif learning_style == "Interactive Quiz":
352
+ study_content = f"""
353
+ ๐ŸŽฎ **SUPER FUN QUIZ TIME!** ๐ŸŽฎ
354
+
355
+ Based on: {extracted_text[:80]}...
356
+
357
+ ๐Ÿ“ Try to Answer These Fun Questions:
358
+
359
+ โ“ Question 1: What's the MAIN thing about this topic?
360
+ ๐Ÿ’ญ Think about it... You got this! ๐Ÿ’ช
361
+
362
+ โ“ Question 2: Can you tell your friend about this in simple words?
363
+ ๐Ÿ’ญ Teaching others is the BEST way to learn! ๐Ÿ“š
364
+
365
+ โ“ Question 3: Where do you see this in real life?
366
+ ๐Ÿ’ญ (Hint: Look around you!) ๐Ÿ‘€
367
+
368
+ โ“ Question 4: What's the coolest part of this?
369
+ ๐Ÿ’ญ Everyone learns what's cool to THEM! ๐ŸŒŸ
370
+
371
+ ๐Ÿ† YOU'RE AMAZING FOR TRYING! ๐Ÿ†
372
+ """
373
+
374
+ elif learning_style == "Memory Game":
375
+ words = extracted_text.split()[:5]
376
+ study_content = f"""
377
+ ๐Ÿง  **MEMORY CHAMPION CHALLENGE!** ๐Ÿง 
378
+
379
+ Let's train your SUPER BRAIN! ๐ŸŽฏ
380
+
381
+ ๐Ÿ“š Key Words to Remember:
382
+ {', '.join([f'โœจ {word}' for word in words])}
383
+
384
+ ๐ŸŽฎ MEMORY GAME RULES:
385
+ 1๏ธโƒฃ Read the words above carefully (10 seconds)
386
+ 2๏ธโƒฃ Close your eyes and think about them
387
+ 3๏ธโƒฃ Can you remember them all? Try it!
388
+ 4๏ธโƒฃ Repeat this game 3 times to be a MEMORY MASTER! ๐Ÿ‘‘
389
+
390
+ ๐Ÿ’ช YOUR BRAIN POWER IS INCREASING!
391
+ ๐Ÿ“Š Track your progress:
392
+ - Try 1: How many did you remember? ___/5
393
+ - Try 2: How many did you remember? ___/5
394
+ - Try 3: How many did you remember? ___/5
395
+
396
+ ๐ŸŽ‰ AWESOME JOB! Your brain is SUPER POWERFUL! ๐ŸŒŸ
397
+ """
398
+
399
+ else: # Learning Tips for Kids
400
+ study_content = f"""
401
+ ๐ŸŒŸ **SUPER COOL LEARNING TIPS FOR YOU!** ๐ŸŒŸ
402
+
403
+ Topic: {extracted_text[:100]}...
404
+
405
+ ๐ŸŽฏ AWESOME STUDY TRICKS:
406
+
407
+ ๐ŸŽจ Make It Colorful!
408
+ - Use different colored pens or pencils
409
+ - Draw pictures to remember things
410
+ - Make it FUN and PRETTY! ๐Ÿ–๏ธ
411
+
412
+ ๐ŸŽต Use Music & Rhythm!
413
+ - Make up a song about what you're learning
414
+ - Sing it while you study
415
+ - Dance while learning = SUPER FUN! ๐ŸŽถ
416
+
417
+ ๐ŸŽฌ Act It Out!
418
+ - Use hand movements to remember ideas
419
+ - Tell your friends like you're a teacher
420
+ - Pretend you're explaining to an alien! ๐Ÿ‘ฝ
421
+
422
+ ๐Ÿƒ Move Your Body!
423
+ - Study for 10 minutes, then play for 5 minutes
424
+ - Jump, stretch, or dance between lessons
425
+ - Exercise helps your brain grow BIGGER & STRONGER! ๐Ÿ’ช
426
+
427
+ ๐Ÿ‘ฅ Study with Friends!
428
+ - Teaching each other is the BEST way to learn
429
+ - Play learning games together
430
+ - Make it a FUN GROUP ACTIVITY! ๐ŸŽ‰
431
+
432
+ ๐Ÿ† YOU'RE A LEARNING SUPERSTAR! โญ
433
+ """
434
+
435
+ return study_content
436
+ except Exception as e:
437
+ return f"๐Ÿ™ˆ Oops! Something went wrong. Let's try again! Error: {str(e)}"
438
+
439
  # Custom CSS for professional styling
440
  custom_css = """
441
  .gradio-container {
 
811
  outputs=[study_output],
812
  show_progress="full"
813
  )
814
+
815
+ # ===== TAB 5: Study Helper for Kids =====
816
+ with gr.TabItem("๐ŸŽจ Study Helper for Kids"):
817
+
818
+ gr.Markdown("""
819
+ # ๐ŸŒŸ **WELCOME TO AWESOME LEARNING LAND!** ๐ŸŒŸ
820
+
821
+ ๐Ÿ“š **Learning is FUN and EXCITING!**
822
+
823
+ Upload your homework, and let our super cool AI help you learn in amazing ways!
824
+ Choose your favorite learning style and get ready to become a LEARNING SUPERSTAR! ๐Ÿš€
825
+ """)
826
+
827
+ with gr.Row():
828
+ with gr.Column(scale=1):
829
+ gr.Markdown("### ๐Ÿ“ค Upload Your Homework", elem_classes="section-title")
830
+ kids_study_image_input = gr.Image(
831
+ label="",
832
+ type="pil",
833
+ height=350,
834
+ show_label=False
835
+ )
836
+
837
+ gr.Markdown("### ๐ŸŽฎ Pick Your Learning Style", elem_classes="section-title")
838
+ kids_learning_style_dropdown = gr.Dropdown(
839
+ choices=[
840
+ "Fun Summary",
841
+ "Interactive Quiz",
842
+ "Memory Game",
843
+ "Learning Tips for Kids"
844
+ ],
845
+ label="What sounds fun to you?",
846
+ value="Fun Summary",
847
+ info="Choose how you want to learn! ๐ŸŽฏ"
848
+ )
849
+
850
+ kids_study_generate_btn = gr.Button(
851
+ "๐ŸŽ‰ Start Learning Adventure!",
852
+ variant="primary",
853
+ elem_classes="generate-btn",
854
+ size="lg"
855
+ )
856
+
857
+ with gr.Column(scale=1):
858
+ gr.Markdown("### ๐ŸŒˆ Your Learning Experience", elem_classes="section-title")
859
+ kids_study_output = gr.Textbox(
860
+ label="",
861
+ lines=14,
862
+ show_label=False,
863
+ placeholder="Your fun learning content will appear here! Get ready for an adventure! ๐Ÿš€",
864
+ interactive=False
865
+ )
866
+
867
+ kids_study_generate_btn.click(
868
+ fn=ai_study_helper_for_kids,
869
+ inputs=[kids_study_image_input, kids_learning_style_dropdown],
870
+ outputs=[kids_study_output],
871
+ show_progress="full"
872
+ )
873
 
 
874
  gr.HTML("""
875
  <div class="footer">
876
  <p>Powered by <strong>Hugging Face Transformers</strong> & <strong>Supertonic TTS</strong> |