Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
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> |
|