Spaces:
Runtime error
Runtime error
Upload 51 files
Browse filesThis view is limited to 50 files because it contains too many changes. Β See raw diff
- .gitattributes +14 -0
- ai_lang_teacher/.gitignore +1 -0
- ai_lang_teacher/.ipynb_checkpoints/.gitignore-checkpoint +1 -0
- ai_lang_teacher/.ipynb_checkpoints/Teacher design-checkpoint.md +119 -0
- ai_lang_teacher/.ipynb_checkpoints/app-Copy1-checkpoint.py +491 -0
- ai_lang_teacher/.ipynb_checkpoints/app-checkpoint.py +483 -0
- ai_lang_teacher/.ipynb_checkpoints/lesson_format-checkpoint.txt +0 -0
- ai_lang_teacher/.ipynb_checkpoints/lesson_plan-checkpoint +36 -0
- ai_lang_teacher/.ipynb_checkpoints/teacher_script-checkpoint.txt +0 -0
- ai_lang_teacher/.virtual_documents/Long clip transcriber.ipynb +153 -0
- ai_lang_teacher/.virtual_documents/Teacher.ipynb +112 -0
- ai_lang_teacher/.virtual_documents/Transcriber.ipynb +110 -0
- ai_lang_teacher/.virtual_documents/Untitled.ipynb +112 -0
- ai_lang_teacher/.virtual_documents/YT_downloader.ipynb +72 -0
- ai_lang_teacher/FFU EP-1 Wonderland Journey into the Darkness.txt +0 -0
- ai_lang_teacher/Gurren Lagann - Giga Drill Break.txt +0 -0
- ai_lang_teacher/README.md +1 -0
- ai_lang_teacher/Teacher design.md +105 -0
- ai_lang_teacher/app-Copy1.py +489 -0
- ai_lang_teacher/app.py +483 -0
- ai_lang_teacher/converted_audio/Birthday Party Mobile Suit Gundam Wing.wav +3 -0
- ai_lang_teacher/converted_audio/Gurren Lagann - Giga Drill Break.wav +3 -0
- ai_lang_teacher/converted_audio/Kamina - Believe in me who believes in you.wav +3 -0
- ai_lang_teacher/converted_audio/clips/Birthday Party Mobile Suit Gundam Wing_clip_1.wav +3 -0
- ai_lang_teacher/converted_audio/clips/Birthday Party Mobile Suit Gundam Wing_clip_2.wav +3 -0
- ai_lang_teacher/converted_audio/clips/Birthday Party Mobile Suit Gundam Wing_clip_3.wav +3 -0
- ai_lang_teacher/converted_audio/clips/Birthday Party Mobile Suit Gundam Wing_clip_4.wav +0 -0
- ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_1.wav +3 -0
- ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_2.wav +3 -0
- ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_3.wav +3 -0
- ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_4.wav +3 -0
- ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_5.wav +3 -0
- ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_6.wav +0 -0
- ai_lang_teacher/downloads/Birthday Party Mobile Suit Gundam Wing.mp4 +3 -0
- ai_lang_teacher/downloads/Gurren Lagann - Giga Drill Break.mp4 +3 -0
- ai_lang_teacher/downloads/Kamina - Believe in me who believes in you.mp4 +3 -0
- ai_lang_teacher/lesson_format.txt +30 -0
- ai_lang_teacher/lesson_plan +36 -0
- ai_lang_teacher/survey_answers.json +1 -0
- ai_lang_teacher/teacher_script.txt +0 -0
- ai_lang_teacher/transcript/.ipynb_checkpoints/Kamina - Believe in me who believes in you-checkpoint.json +1 -0
- ai_lang_teacher/transcript/.ipynb_checkpoints/Kamina - Believe in me who believes in you-checkpoint.vtt +20 -0
- ai_lang_teacher/transcript/.ipynb_checkpoints/Kobeni Goes Berserk Chainsaw Man-checkpoint.json +4 -0
- ai_lang_teacher/transcript/.ipynb_checkpoints/simple-checkpoint.json +12 -0
- ai_lang_teacher/transcript/Birthday Party Mobile Suit Gundam Wing.json +5 -0
- ai_lang_teacher/transcript/FFU EP-1 Wonderland Journey into the Darkness.json +5 -0
- ai_lang_teacher/transcript/Kamina - Believe in me who believes in you.json +1 -0
- ai_lang_teacher/transcript/Kamina - Believe in me who believes in you.vtt +11 -0
- ai_lang_teacher/transcript/Kobeni Goes Berserk Chainsaw Man.json +5 -0
- ai_lang_teacher/transcript/simple.json +4 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,17 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
ai_lang_teacher/converted_audio/Birthday[[:space:]]Party[[:space:]][[:space:]]Mobile[[:space:]]Suit[[:space:]]Gundam[[:space:]]Wing.wav filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
ai_lang_teacher/converted_audio/clips/Birthday[[:space:]]Party[[:space:]][[:space:]]Mobile[[:space:]]Suit[[:space:]]Gundam[[:space:]]Wing_clip_1.wav filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
ai_lang_teacher/converted_audio/clips/Birthday[[:space:]]Party[[:space:]][[:space:]]Mobile[[:space:]]Suit[[:space:]]Gundam[[:space:]]Wing_clip_2.wav filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
ai_lang_teacher/converted_audio/clips/Birthday[[:space:]]Party[[:space:]][[:space:]]Mobile[[:space:]]Suit[[:space:]]Gundam[[:space:]]Wing_clip_3.wav filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
ai_lang_teacher/converted_audio/clips/Gurren[[:space:]]Lagann[[:space:]]-[[:space:]]Giga[[:space:]]Drill[[:space:]]Break_clip_1.wav filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
ai_lang_teacher/converted_audio/clips/Gurren[[:space:]]Lagann[[:space:]]-[[:space:]]Giga[[:space:]]Drill[[:space:]]Break_clip_2.wav filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
ai_lang_teacher/converted_audio/clips/Gurren[[:space:]]Lagann[[:space:]]-[[:space:]]Giga[[:space:]]Drill[[:space:]]Break_clip_3.wav filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
ai_lang_teacher/converted_audio/clips/Gurren[[:space:]]Lagann[[:space:]]-[[:space:]]Giga[[:space:]]Drill[[:space:]]Break_clip_4.wav filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
ai_lang_teacher/converted_audio/clips/Gurren[[:space:]]Lagann[[:space:]]-[[:space:]]Giga[[:space:]]Drill[[:space:]]Break_clip_5.wav filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
ai_lang_teacher/converted_audio/Gurren[[:space:]]Lagann[[:space:]]-[[:space:]]Giga[[:space:]]Drill[[:space:]]Break.wav filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
ai_lang_teacher/converted_audio/Kamina[[:space:]]-[[:space:]]Believe[[:space:]]in[[:space:]]me[[:space:]]who[[:space:]]believes[[:space:]]in[[:space:]]you.wav filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
ai_lang_teacher/downloads/Birthday[[:space:]]Party[[:space:]][[:space:]]Mobile[[:space:]]Suit[[:space:]]Gundam[[:space:]]Wing.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
ai_lang_teacher/downloads/Gurren[[:space:]]Lagann[[:space:]]-[[:space:]]Giga[[:space:]]Drill[[:space:]]Break.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
ai_lang_teacher/downloads/Kamina[[:space:]]-[[:space:]]Believe[[:space:]]in[[:space:]]me[[:space:]]who[[:space:]]believes[[:space:]]in[[:space:]]you.mp4 filter=lfs diff=lfs merge=lfs -text
|
ai_lang_teacher/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
ai_lang_teacher/.ipynb_checkpoints/.gitignore-checkpoint
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
ai_lang_teacher/.ipynb_checkpoints/Teacher design-checkpoint.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# # Approach on how to design a lesson for a student (ChatGPT brainstorm session)
|
| 2 |
+
|
| 3 |
+
Teaching a language through submitted audio/video clips with a focus on pure immersion and minimal flashcard reliance is an innovative and effective approach, often referred to as "immersive learning." Here's a step-by-step guide on how to do it:
|
| 4 |
+
|
| 5 |
+
**Step 1: Choose the Target Language:**
|
| 6 |
+
- Start by selecting the target language you want to teach through immersion. Ensure that you have access to a variety of authentic audio and video clips in that language.
|
| 7 |
+
|
| 8 |
+
**Step 2: Build a Diverse Collection of Resources:**
|
| 9 |
+
- Gather a wide range of audio and video clips, including:
|
| 10 |
+
- Conversations between native speakers.
|
| 11 |
+
- News broadcasts, podcasts, or radio shows.
|
| 12 |
+
- Movies, TV shows, or YouTube videos.
|
| 13 |
+
- Songs and music in the target language.
|
| 14 |
+
- Interviews or documentaries.
|
| 15 |
+
|
| 16 |
+
**Step 3: Create Structured Learning Experiences:**
|
| 17 |
+
- Organize the immersion-based learning experience into structured modules or themes. For example:
|
| 18 |
+
- Beginner modules: Simple conversations, basic vocabulary.
|
| 19 |
+
- Intermediate modules: More complex conversations, culture, and context.
|
| 20 |
+
- Advanced modules: In-depth discussions, idiomatic expressions.
|
| 21 |
+
|
| 22 |
+
**Step 4: Provide Guided Prompts:**
|
| 23 |
+
- Alongside each audio or video clip, provide guided prompts or questions to encourage active listening and comprehension.
|
| 24 |
+
- For beginners, these prompts can be simple questions about the content.
|
| 25 |
+
- For advanced learners, prompts can be more open-ended, encouraging critical thinking and analysis.
|
| 26 |
+
|
| 27 |
+
**Step 5: Encourage Active Engagement:**
|
| 28 |
+
- Encourage learners to actively engage with the content by:
|
| 29 |
+
- Repeatedly listening to the clips to improve listening skills.
|
| 30 |
+
- Attempting to transcribe or summarize what they hear.
|
| 31 |
+
- Discussing the content with fellow learners or language partners.
|
| 32 |
+
- Creating their own responses or conversations based on what they've learned.
|
| 33 |
+
|
| 34 |
+
**Step 6: Foster Collaborative Learning:**
|
| 35 |
+
- Create a community or platform where learners can share their thoughts, questions, and experiences related to the language immersion.
|
| 36 |
+
- Encourage peer-to-peer learning, where learners can help each other with comprehension and pronunciation.
|
| 37 |
+
|
| 38 |
+
**Step 7: Track Progress and Set Goals:**
|
| 39 |
+
- Implement a system for tracking progress, possibly through regular assessments or self-assessment tools.
|
| 40 |
+
- Encourage learners to set achievable language learning goals.
|
| 41 |
+
|
| 42 |
+
**Step 8: Promote Cultural Understanding:**
|
| 43 |
+
- Use video clips that provide insights into the culture, customs, and traditions of the target language's speakers.
|
| 44 |
+
- Encourage learners to explore the cultural context in addition to language skills.
|
| 45 |
+
|
| 46 |
+
**Step 9: Adjust the Challenge Level:**
|
| 47 |
+
- Gradually increase the complexity of the clips and modules as learners progress.
|
| 48 |
+
- Provide access to more advanced content for those ready to tackle higher-level language skills.
|
| 49 |
+
|
| 50 |
+
**Step 10: Encourage Consistency:**
|
| 51 |
+
- Emphasize the importance of regular exposure and practice. Encourage learners to incorporate language learning into their daily routines.
|
| 52 |
+
|
| 53 |
+
**Step 11: Provide Feedback and Support:**
|
| 54 |
+
- Offer constructive feedback and support to learners who may have questions or need clarification.
|
| 55 |
+
|
| 56 |
+
**Step 12: Celebrate Achievements:**
|
| 57 |
+
- Celebrate milestones and achievements with learners to keep them motivated.
|
| 58 |
+
|
| 59 |
+
This immersion-based approach relies on learners actively engaging with authentic language content, promoting natural language acquisition and cultural understanding. It's a dynamic and effective way to teach a language without heavy reliance on flashcards or traditional classroom methods.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Creating a lesson based on the provided transcript for immersion learning involves using the content as a springboard to introduce and reinforce language concepts. Here's a structured lesson plan based on the transcript:
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
**Lesson Title: Building Language Skills through Immersion - Believe in Yourself**
|
| 67 |
+
|
| 68 |
+
**Objective:** By the end of this lesson, learners will be able to understand and use basic phrases related to belief and encouragement in Japanese.
|
| 69 |
+
|
| 70 |
+
**Materials Needed:**
|
| 71 |
+
- The provided transcript with audio recording.
|
| 72 |
+
- Access to a digital platform for discussions and sharing.
|
| 73 |
+
|
| 74 |
+
**Lesson Structure:**
|
| 75 |
+
|
| 76 |
+
**1. Warm-Up (5 minutes):**
|
| 77 |
+
- Play the audio clip of the transcript to familiarize learners with the content.
|
| 78 |
+
- Ask learners if they recognize any words or phrases from the clip.
|
| 79 |
+
|
| 80 |
+
**2. Introduction to Context (10 minutes):**
|
| 81 |
+
- Provide some background information about the context of the transcript, explaining that it's a conversation between two individuals.
|
| 82 |
+
- Discuss the importance of self-belief and encouragement in language learning.
|
| 83 |
+
|
| 84 |
+
**3. Audio Listening (15 minutes):**
|
| 85 |
+
- Play the audio clip once without interruption to allow learners to get a sense of the conversation.
|
| 86 |
+
- Play the audio clip again, pausing at each phrase or sentence to break it down for discussion.
|
| 87 |
+
- Encourage learners to repeat each phrase after the audio to practice pronunciation.
|
| 88 |
+
|
| 89 |
+
**4. Vocabulary Building (10 minutes):**
|
| 90 |
+
- Introduce the Japanese words and phrases from the transcript:
|
| 91 |
+
- γγγ (ii ka) - Listen or Pay attention.
|
| 92 |
+
- εΏγγγͺ (wasurenna) - Don't forget or Remember.
|
| 93 |
+
- γεγδΏ‘γγ (omae o shinjiro) - Believe in yourself or Have faith in yourself.
|
| 94 |
+
|
| 95 |
+
**5. Comprehension and Discussion (20 minutes):**
|
| 96 |
+
- Engage learners in a discussion about the transcript:
|
| 97 |
+
- What do they think the conversation is about?
|
| 98 |
+
- What emotions or messages do they detect in the dialogue?
|
| 99 |
+
- How would they respond to such encouragement in their own language learning journey?
|
| 100 |
+
- Encourage learners to express their thoughts in the target language, even if it's just a few words or sentences.
|
| 101 |
+
|
| 102 |
+
**6. Role-Play (15 minutes):**
|
| 103 |
+
- Divide learners into pairs or small groups.
|
| 104 |
+
- Assign roles and have them create their own encouraging dialogues in Japanese using the phrases learned.
|
| 105 |
+
- Encourage them to perform the dialogues for the class.
|
| 106 |
+
|
| 107 |
+
**7. Cultural Insights (10 minutes):**
|
| 108 |
+
- Discuss the significance of encouragement and self-belief in Japanese culture.
|
| 109 |
+
- Share anecdotes or examples of how these concepts are practiced in Japanese society.
|
| 110 |
+
|
| 111 |
+
**8. Homework and Self-Study (5 minutes):**
|
| 112 |
+
- Assign listening homework: Ask learners to find and listen to audio clips or videos in Japanese that contain similar phrases of encouragement.
|
| 113 |
+
- Encourage them to share their findings and reflections in the next class.
|
| 114 |
+
|
| 115 |
+
**9. Recap and Feedback (5 minutes):**
|
| 116 |
+
- Recap the key phrases and concepts learned in the lesson.
|
| 117 |
+
- Gather feedback from learners on their experience and what they found most valuable.
|
| 118 |
+
|
| 119 |
+
This lesson plan combines listening comprehension, vocabulary building, discussion, role-play, and cultural insights to immerse learners in the language and context. It promotes active engagement and encourages learners to apply what they've learned in real-life situations.
|
ai_lang_teacher/.ipynb_checkpoints/app-Copy1-checkpoint.py
ADDED
|
@@ -0,0 +1,491 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from streamlit import elements
|
| 4 |
+
import json
|
| 5 |
+
import uuid
|
| 6 |
+
import os
|
| 7 |
+
from pytube import YouTube
|
| 8 |
+
from moviepy.editor import VideoFileClip
|
| 9 |
+
import openai
|
| 10 |
+
from langchain.llms import OpenAI
|
| 11 |
+
from langchain.chat_models import ChatOpenAI
|
| 12 |
+
from langchain import PromptTemplate
|
| 13 |
+
from langchain.prompts import ChatPromptTemplate
|
| 14 |
+
import time
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
#############--------------- ID and Surveys ------------########################
|
| 19 |
+
# Generate unique user ID
|
| 20 |
+
def generate_unique_id():
|
| 21 |
+
return str(uuid.uuid4())
|
| 22 |
+
|
| 23 |
+
# Save survey answers to a file
|
| 24 |
+
def save_survey_answers(unique_id, answers):
|
| 25 |
+
with open('survey_answers.json', 'w') as f:
|
| 26 |
+
json.dump({unique_id: answers}, f)
|
| 27 |
+
# f.write('\n')
|
| 28 |
+
|
| 29 |
+
# Load all stored unique IDs
|
| 30 |
+
def load_unique_ids():
|
| 31 |
+
try:
|
| 32 |
+
with open('unique_ids.json', 'r') as f:
|
| 33 |
+
return json.load(f)
|
| 34 |
+
except FileNotFoundError:
|
| 35 |
+
return []
|
| 36 |
+
|
| 37 |
+
# Save a unique ID
|
| 38 |
+
def save_unique_id(unique_id):
|
| 39 |
+
ids = load_unique_ids()
|
| 40 |
+
ids.append(unique_id)
|
| 41 |
+
with open('unique_ids.json', 'w') as f:
|
| 42 |
+
json.dump(ids, f)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
#############--------------- Video transcription ------------########################
|
| 46 |
+
|
| 47 |
+
# Download video from URL
|
| 48 |
+
def download_video(url, output_directory='./downloads'):
|
| 49 |
+
try:
|
| 50 |
+
yt = YouTube(url)
|
| 51 |
+
video = yt.streams.get_highest_resolution()
|
| 52 |
+
if not os.path.exists(output_directory):
|
| 53 |
+
os.makedirs(output_directory)
|
| 54 |
+
video.download(output_path=output_directory)
|
| 55 |
+
return os.path.join(output_directory, video.default_filename), 'Video downloaded successfully.'
|
| 56 |
+
except Exception as e:
|
| 57 |
+
message = f'An error occurred: {e}'
|
| 58 |
+
return None, message
|
| 59 |
+
|
| 60 |
+
# Convert video to audio
|
| 61 |
+
def convert_to_audio(video_path, output_directory='./converted_audio'):
|
| 62 |
+
try:
|
| 63 |
+
video = VideoFileClip(video_path)
|
| 64 |
+
audio_filename = f"{os.path.basename(video_path).split('.')[0]}.wav"
|
| 65 |
+
audio_path = os.path.join(output_directory, audio_filename)
|
| 66 |
+
if not os.path.exists(output_directory):
|
| 67 |
+
os.makedirs(output_directory)
|
| 68 |
+
video.audio.write_audiofile(audio_path)
|
| 69 |
+
message = 'Audio converted successfully.'
|
| 70 |
+
return audio_path, message
|
| 71 |
+
except Exception as e:
|
| 72 |
+
message = f"An error occurred: {e}"
|
| 73 |
+
return None, message
|
| 74 |
+
|
| 75 |
+
# Transcribe audio
|
| 76 |
+
# Take WAV file from downloads and save to converted audio folder
|
| 77 |
+
import os
|
| 78 |
+
from dotenv import load_dotenv, find_dotenv
|
| 79 |
+
import openai
|
| 80 |
+
import eyed3
|
| 81 |
+
import pyaudio
|
| 82 |
+
import wave
|
| 83 |
+
import json
|
| 84 |
+
|
| 85 |
+
# Load API key from .env file
|
| 86 |
+
load_dotenv(find_dotenv())
|
| 87 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 88 |
+
|
| 89 |
+
# Split long audio files into clips to be processed by Whisper API
|
| 90 |
+
def split_audio_pyaudio(audio_path, clip_duration_sec=30, overlap_duration_sec=3, output_folder='converted_audio/clips'):
|
| 91 |
+
clip_list = []
|
| 92 |
+
file_name = os.path.basename(audio_path)[:-4]
|
| 93 |
+
|
| 94 |
+
# Determine the total duration of the audio file
|
| 95 |
+
if audio_path.endswith('.mp3'):
|
| 96 |
+
audio_file = eyed3.load(audio_path)
|
| 97 |
+
total_duration = audio_file.info.time_secs
|
| 98 |
+
elif audio_path.endswith('.wav'):
|
| 99 |
+
with wave.open(audio_path, 'rb') as wf:
|
| 100 |
+
n_frames = wf.getnframes()
|
| 101 |
+
framerate = wf.getframerate()
|
| 102 |
+
total_duration = n_frames / framerate
|
| 103 |
+
else:
|
| 104 |
+
raise ValueError("Unsupported audio format")
|
| 105 |
+
|
| 106 |
+
if not os.path.exists(output_folder):
|
| 107 |
+
os.makedirs(output_folder)
|
| 108 |
+
|
| 109 |
+
CHUNK = 1024
|
| 110 |
+
FORMAT = pyaudio.paInt16
|
| 111 |
+
CHANNELS = 2
|
| 112 |
+
RATE = 44100
|
| 113 |
+
clip_duration_samples = clip_duration_sec * RATE
|
| 114 |
+
overlap_samples = overlap_duration_sec * RATE
|
| 115 |
+
|
| 116 |
+
wf = wave.open(audio_path, 'rb')
|
| 117 |
+
p = pyaudio.PyAudio()
|
| 118 |
+
|
| 119 |
+
clip_number = 1
|
| 120 |
+
for start_sample in range(0, int(total_duration * RATE), clip_duration_samples - overlap_samples):
|
| 121 |
+
frames = []
|
| 122 |
+
|
| 123 |
+
for i in range(0, int(RATE / CHUNK * clip_duration_sec)):
|
| 124 |
+
data = wf.readframes(CHUNK)
|
| 125 |
+
if not data:
|
| 126 |
+
break
|
| 127 |
+
frames.append(data)
|
| 128 |
+
|
| 129 |
+
clip_path = f"{output_folder}/{file_name}_clip_{clip_number}.wav"
|
| 130 |
+
wf_clip = wave.open(clip_path, 'wb')
|
| 131 |
+
wf_clip.setnchannels(CHANNELS)
|
| 132 |
+
wf_clip.setsampwidth(p.get_sample_size(FORMAT))
|
| 133 |
+
wf_clip.setframerate(RATE)
|
| 134 |
+
wf_clip.writeframes(b''.join(frames))
|
| 135 |
+
wf_clip.close()
|
| 136 |
+
|
| 137 |
+
clip_list.append(clip_path)
|
| 138 |
+
clip_number += 1
|
| 139 |
+
|
| 140 |
+
wf.close()
|
| 141 |
+
p.terminate()
|
| 142 |
+
|
| 143 |
+
return clip_list
|
| 144 |
+
|
| 145 |
+
# Takes WAV audio clips and transcribes them and saves them to JSON
|
| 146 |
+
def transcribe(audio_path):
|
| 147 |
+
clip_path_list = split_audio_pyaudio(audio_path)
|
| 148 |
+
file_name = os.path.basename(audio_path)[:-4]
|
| 149 |
+
transcribed_clips = []
|
| 150 |
+
# Ensure the transcript file is empty to start with
|
| 151 |
+
with open(f'{file_name}.txt', 'w') as txt_file:
|
| 152 |
+
pass
|
| 153 |
+
|
| 154 |
+
for clip in clip_path_list:
|
| 155 |
+
with wave.open(clip, 'rb') as wf:
|
| 156 |
+
n_frames = wf.getnframes()
|
| 157 |
+
framerate = wf.getframerate()
|
| 158 |
+
clip_duration = n_frames / framerate
|
| 159 |
+
|
| 160 |
+
if clip_duration < 0.1:
|
| 161 |
+
print(f"Skipping short clip (less than 0.1 sec): {clip}")
|
| 162 |
+
continue # Skip short clips
|
| 163 |
+
|
| 164 |
+
with open(clip, 'rb') as audio_file:
|
| 165 |
+
transcript = openai.Audio.transcribe(
|
| 166 |
+
file=audio_file,
|
| 167 |
+
model="whisper-1",
|
| 168 |
+
response_format='text',
|
| 169 |
+
temperature=0.0
|
| 170 |
+
)
|
| 171 |
+
transcribed_clips.append(transcript + '\n')
|
| 172 |
+
# with open(f'transcript/{file_name}.text', 'a') as txt_file:
|
| 173 |
+
# txt_file.write(transcript + '\n')
|
| 174 |
+
full_transcript_str = ''.join(transcribed_clips)
|
| 175 |
+
|
| 176 |
+
messages=[
|
| 177 |
+
{'role':'system', 'content':'''You are a robot that is specifically designed to figure out what language a transcript is in.
|
| 178 |
+
When given a transcript, ONLY return the ISO-639-1 language code. Take your time and think this through.'''},
|
| 179 |
+
{'role': 'user', 'content': 'je suis amΓ©ricain'},
|
| 180 |
+
{'role': 'assistant', 'content': 'fr'},
|
| 181 |
+
{'role': 'user', 'content': full_transcript_str}
|
| 182 |
+
]
|
| 183 |
+
|
| 184 |
+
response = openai.ChatCompletion.create(
|
| 185 |
+
model='gpt-3.5-turbo-0613',
|
| 186 |
+
messages=messages,
|
| 187 |
+
temperature=0
|
| 188 |
+
)
|
| 189 |
+
language = response['choices'][0]['message']['content']
|
| 190 |
+
|
| 191 |
+
transcript_json = {'title': os.path.basename(audio_path)[:-4], 'transcript': full_transcript_str, 'language' : language}
|
| 192 |
+
|
| 193 |
+
with open(f'transcript/{file_name}.json', 'w') as json_file:
|
| 194 |
+
json.dump(transcript_json, json_file, indent=4)
|
| 195 |
+
|
| 196 |
+
message = "Transcription process completed!"
|
| 197 |
+
return transcript_json, message
|
| 198 |
+
# def transcribe_audio(audio_path):
|
| 199 |
+
# try:
|
| 200 |
+
# # audio_file = open(audio_path, 'rb')
|
| 201 |
+
# # v1_transcript = openai.Audio.transcribe(
|
| 202 |
+
# # file=audio_file,
|
| 203 |
+
# # model="whisper-1",
|
| 204 |
+
# # response_format='json',
|
| 205 |
+
# # temperature=0.2
|
| 206 |
+
# # )
|
| 207 |
+
|
| 208 |
+
# # Detect language
|
| 209 |
+
# messages = [
|
| 210 |
+
# {'role': 'system', 'content': 'You are a robot that is specifically designed to figure out what language a transcript is in. When given a transcript, ONLY return the ISO-639-1 language code. Take your time and think this through.'},
|
| 211 |
+
# {'role': 'user', 'content': v1_transcript['text'][:100]}
|
| 212 |
+
# ]
|
| 213 |
+
# response = openai.ChatCompletion.create(
|
| 214 |
+
# model='gpt-3.5-turbo-0613',
|
| 215 |
+
# messages=messages,
|
| 216 |
+
# temperature=0
|
| 217 |
+
# )
|
| 218 |
+
# language = response['choices'][0]['message']['content']
|
| 219 |
+
# v1_transcript['language'] = language
|
| 220 |
+
|
| 221 |
+
# # Display in chat box
|
| 222 |
+
# message = "Transcription successful."
|
| 223 |
+
# return v1_transcript, message
|
| 224 |
+
# except Exception as e:
|
| 225 |
+
# message = f"An error occurred: {e}"
|
| 226 |
+
# return None, message
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
# Save the transcript
|
| 230 |
+
# def save_transcript(transcript, audio_path, output_directory='./transcripts'):
|
| 231 |
+
# try:
|
| 232 |
+
# transcript_filename = f"{os.path.basename(audio_path).split('.')[0]}"
|
| 233 |
+
# if not os.path.exists(output_directory):
|
| 234 |
+
# os.makedirs(output_directory)
|
| 235 |
+
# json_path = os.path.join(output_directory, f'{transcript_filename}.json')
|
| 236 |
+
# with open(json_path, 'w') as json_file:
|
| 237 |
+
# json.dump(transcript, json_file)
|
| 238 |
+
# message = 'Transcript saved successfully.'
|
| 239 |
+
# return json_path, message
|
| 240 |
+
# except Exception as e:
|
| 241 |
+
# message = f"An error occurred: {e}"
|
| 242 |
+
# return None, message
|
| 243 |
+
|
| 244 |
+
#############--------------- Teacher ------------########################
|
| 245 |
+
# Function to get plain English word for language code
|
| 246 |
+
def get_language_word(language, openai_api_key=''):
|
| 247 |
+
llm = OpenAI(model_name='gpt-3.5-turbo-0613', openai_api_key=openai_api_key, temperature=0)
|
| 248 |
+
template = '''Convert the ISO-639-1 language code into the plain english word for the language. ONLY return the english word for that language, nothing more.
|
| 249 |
+
Here is the language code: {language}
|
| 250 |
+
Take your time and think this through. Remember only respond with one word, the english word for the language.'''
|
| 251 |
+
prompt = PromptTemplate(
|
| 252 |
+
input_variables=['language'],
|
| 253 |
+
template=template,
|
| 254 |
+
)
|
| 255 |
+
final_prompt = prompt.format(language=language)
|
| 256 |
+
return llm(final_prompt)
|
| 257 |
+
|
| 258 |
+
# Function to create lesson outline
|
| 259 |
+
def create_lesson_outline(transcript_json, learning_goal='learn new languague', num_words='5', openai_api_key=''):
|
| 260 |
+
try:
|
| 261 |
+
with open('lesson_format.txt', 'r') as txt_file:
|
| 262 |
+
lesson_format = txt_file.read()
|
| 263 |
+
except FileNotFoundError:
|
| 264 |
+
return "Error: 'lesson_format.txt' not found. Please make sure it's in the current working directory."
|
| 265 |
+
|
| 266 |
+
chat = ChatOpenAI(temperature=0.2, model='gpt-3.5-turbo-0613', openai_api_key=openai_api_key)
|
| 267 |
+
template_string = '''Create a lesson based on this title ```{title}```, following this transcript ```{transcript_text}```, and following this format ```{lesson_format}```. Keep in mind the student's learning goal ```{learning_goal}``` and the number of words they want to learn```{num_words}```. For context you are making a lesson plan based on the title of an audio clip taken from a youtube video. Again the title of the video is {title}. Take this into account when making the title of the lesson plan and teaching the concept.
|
| 268 |
+
Only output the lesson plan, nothing more'''
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
prompt_template = ChatPromptTemplate.from_template(template_string)
|
| 272 |
+
messages = prompt_template.format_messages(
|
| 273 |
+
lesson_format=lesson_format,
|
| 274 |
+
transcript_text=transcript_json['transcript'],
|
| 275 |
+
title=transcript_json['title'],
|
| 276 |
+
learning_goal=learning_goal,
|
| 277 |
+
num_words=num_words
|
| 278 |
+
)
|
| 279 |
+
response = chat(messages)
|
| 280 |
+
message = 'Lesson outline created successfully.'
|
| 281 |
+
return response.content, message
|
| 282 |
+
|
| 283 |
+
#############--------------- Chat bot ------------########################
|
| 284 |
+
|
| 285 |
+
# Initialize the chatbox state
|
| 286 |
+
def initialize_chatbox():
|
| 287 |
+
if "messages" not in st.session_state:
|
| 288 |
+
st.session_state["messages"] = []
|
| 289 |
+
|
| 290 |
+
# Add a message to the chatbox
|
| 291 |
+
def add_to_chatbox(role, message):
|
| 292 |
+
st.session_state.messages.append({"role": role, "content": message})
|
| 293 |
+
|
| 294 |
+
if role == "user": # If the message is from the user
|
| 295 |
+
response = openai.ChatCompletion.create(
|
| 296 |
+
model="gpt-3.5-turbo-0613",
|
| 297 |
+
prompt=message,
|
| 298 |
+
max_tokens=150 # Limit the response to 150 tokens
|
| 299 |
+
)
|
| 300 |
+
teacher_response = response.choices[0] # Extract the bot's response text
|
| 301 |
+
st.session_state.messages.append({"role": "assistant", "content": teacher_response})
|
| 302 |
+
|
| 303 |
+
# Display the chatbox
|
| 304 |
+
def display_chatbox():
|
| 305 |
+
st.markdown("<div id='chatbox-container'>", unsafe_allow_html=True)
|
| 306 |
+
for msg in st.session_state.messages:
|
| 307 |
+
st.chat_message(msg["role"]).write(msg["content"])
|
| 308 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
############################## Main Streamlit app #################################
|
| 314 |
+
# Main function
|
| 315 |
+
def main():
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
# Initialize all session_state variables
|
| 319 |
+
for key, default_value in {
|
| 320 |
+
'access_granted': False,
|
| 321 |
+
'survey_done': False,
|
| 322 |
+
'unique_id': '',
|
| 323 |
+
'show_chat_window': False,
|
| 324 |
+
'video_url': '',
|
| 325 |
+
'chat_history': [],
|
| 326 |
+
'messages': [],
|
| 327 |
+
'transcribe_clicked': False,
|
| 328 |
+
}.items():
|
| 329 |
+
if key not in st.session_state:
|
| 330 |
+
st.session_state[key] = default_value
|
| 331 |
+
|
| 332 |
+
st.title('Language Learning AI Tutor')
|
| 333 |
+
st.text('Please wait a few mins after hitting the "Create Lesson" button')
|
| 334 |
+
|
| 335 |
+
# Access Control
|
| 336 |
+
# Check if the API key is already in the session state
|
| 337 |
+
if "api_key" not in st.session_state or not st.session_state.api_key:
|
| 338 |
+
# If the API key is not in the session state, display the input field
|
| 339 |
+
entered_api_key = st.text_input("Enter your API key:", type='password')
|
| 340 |
+
openai.api_key = entered_api_key
|
| 341 |
+
openai_api_key = entered_api_key
|
| 342 |
+
|
| 343 |
+
# Update the session state with the entered API key
|
| 344 |
+
if entered_api_key:
|
| 345 |
+
st.session_state.api_key = entered_api_key
|
| 346 |
+
else:
|
| 347 |
+
st.write("API key loaded successfully!")
|
| 348 |
+
# Load the API key:
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
if not st.session_state['access_granted']:
|
| 358 |
+
entered_id = st.text_input('Enter your unique ID to access the app:')
|
| 359 |
+
|
| 360 |
+
if st.button('Submit ID'):
|
| 361 |
+
unique_ids = load_unique_ids()
|
| 362 |
+
if entered_id in unique_ids:
|
| 363 |
+
st.session_state['access_granted'] = True
|
| 364 |
+
st.session_state['survey_done'] = True
|
| 365 |
+
st.session_state['unique_id'] = entered_id
|
| 366 |
+
st.success("Access granted.")
|
| 367 |
+
st.experimental_rerun()
|
| 368 |
+
else:
|
| 369 |
+
st.warning('Invalid ID. Access denied.')
|
| 370 |
+
|
| 371 |
+
if st.button('Generate New ID'):
|
| 372 |
+
new_id = generate_unique_id()
|
| 373 |
+
save_unique_id(new_id)
|
| 374 |
+
st.session_state['access_granted'] = True
|
| 375 |
+
st.session_state['unique_id'] = new_id
|
| 376 |
+
st.session_state['survey_done'] = False
|
| 377 |
+
st.success(f"New ID generated: {new_id}")
|
| 378 |
+
|
| 379 |
+
else:
|
| 380 |
+
if not st.session_state['survey_done']:
|
| 381 |
+
st.subheader('Survey Questions')
|
| 382 |
+
learning_goal = st.text_input("What's your daily learning goal?")
|
| 383 |
+
num_words = st.text_input('How many words do you want to learn?')
|
| 384 |
+
|
| 385 |
+
if st.button('Submit Survey'):
|
| 386 |
+
answers = {'learning_goal': learning_goal, 'num_words': num_words}
|
| 387 |
+
save_survey_answers(st.session_state['unique_id'], answers)
|
| 388 |
+
st.session_state['learning_goal'] = learning_goal
|
| 389 |
+
st.session_state['num_words'] = num_words
|
| 390 |
+
st.session_state['survey_done'] = True
|
| 391 |
+
st.success('Survey answers submitted!')
|
| 392 |
+
st.experimental_rerun()
|
| 393 |
+
|
| 394 |
+
# Sidebar for Video Upload
|
| 395 |
+
if st.session_state['access_granted'] and st.session_state['survey_done']:
|
| 396 |
+
with st.sidebar:
|
| 397 |
+
st.title('Video Upload')
|
| 398 |
+
video_url = st.text_input('Paste your YouTube video link here')
|
| 399 |
+
if st.button('Create Lesson'):
|
| 400 |
+
st.session_state.video_url = video_url
|
| 401 |
+
st.session_state.show_chat_window = True
|
| 402 |
+
st.session_state.transcribe_clicked = True
|
| 403 |
+
# st.sidebar.video(video_url)
|
| 404 |
+
# Save to session state that video should be displayed
|
| 405 |
+
st.session_state.display_video = True
|
| 406 |
+
|
| 407 |
+
# Check if video should be displayed in the sidebar
|
| 408 |
+
if 'display_video' in st.session_state and st.session_state.display_video:
|
| 409 |
+
st.sidebar.video(video_url)
|
| 410 |
+
|
| 411 |
+
# Clears state/screen
|
| 412 |
+
if st.button("Clear Messages"):
|
| 413 |
+
if 'messages' in st.session_state:
|
| 414 |
+
st.session_state['messages']=[]
|
| 415 |
+
|
| 416 |
+
# Main chat interface
|
| 417 |
+
if st.session_state.get('show_chat_window', False):
|
| 418 |
+
# Display previous chat messages
|
| 419 |
+
for message in st.session_state.messages:
|
| 420 |
+
with st.chat_message(message["role"]):
|
| 421 |
+
st.markdown(message["content"])
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
user_input = st.chat_input("begin lesson here and ask questions...")
|
| 426 |
+
if user_input:
|
| 427 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 428 |
+
|
| 429 |
+
# Ensure that st.session_state.messages is a list with the correct structure
|
| 430 |
+
if not isinstance(st.session_state.messages, list):
|
| 431 |
+
st.session_state.messages = []
|
| 432 |
+
|
| 433 |
+
response = openai.ChatCompletion.create(
|
| 434 |
+
model="gpt-3.5-turbo-0613",
|
| 435 |
+
messages=st.session_state.messages,
|
| 436 |
+
max_tokens=500 # Limit the response to 150 tokens
|
| 437 |
+
)
|
| 438 |
+
teacher_response = response.choices[0].message['content'].strip() # Extract the teacher's response text correctly
|
| 439 |
+
|
| 440 |
+
st.session_state.messages.append({"role": "assistant", "content": teacher_response})
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
# Perform transcription if Transcribe button is clicked
|
| 444 |
+
if st.session_state.get('transcribe_clicked', False):
|
| 445 |
+
st.session_state.transcribe_clicked = False
|
| 446 |
+
|
| 447 |
+
# Download video
|
| 448 |
+
video_path, video_message = download_video(st.session_state['video_url'])
|
| 449 |
+
st.session_state.messages.append({"role": "assistant", "content": video_message})
|
| 450 |
+
|
| 451 |
+
if video_path:
|
| 452 |
+
# Convert to audio
|
| 453 |
+
audio_path, audio_message = convert_to_audio(video_path)
|
| 454 |
+
st.session_state.messages.append({"role": "assistant", "content": audio_message})
|
| 455 |
+
|
| 456 |
+
if audio_path:
|
| 457 |
+
# Transcribe audio
|
| 458 |
+
transcript_data, transcript_message = transcribe(audio_path)
|
| 459 |
+
st.session_state.messages.append({"role": "assistant", "content": transcript_message})
|
| 460 |
+
|
| 461 |
+
# if transcript_data is not None:
|
| 462 |
+
# Detect language
|
| 463 |
+
language = get_language_word(transcript_data['language'])
|
| 464 |
+
st.session_state.messages.append({"role": "assistant", "content": f"Detected language is {language}"})
|
| 465 |
+
|
| 466 |
+
# Create lesson from transcript
|
| 467 |
+
lesson_content, lesson_message = create_lesson_outline(transcript_data)
|
| 468 |
+
st.session_state.messages.append({"role": "assistant", "content": "Here's the transcript and the lesson plan"})
|
| 469 |
+
st.session_state.messages.append({"role": "assistant", "content": '**Transcript: **' + transcript_data['transcript']})
|
| 470 |
+
st.session_state.messages.append({"role": "assistant", "content": '**Lesson plan: **' + lesson_content})
|
| 471 |
+
# st.session_state.messages.append({"role": "assistant", "content": lesson_content})
|
| 472 |
+
st.session_state.messages.append(
|
| 473 |
+
{"role": "system", "content": f'Follow the lesson plan as outlined: {lesson_content} and try your best not to deviate. Teach each word one at at time and explain in detail, including writing system or other relavent details for a firt time learner. Think this out step by step'})
|
| 474 |
+
# Temporary way to handle memory in the meantime
|
| 475 |
+
token_count = response['usage']['total_tokens']
|
| 476 |
+
if token_count >= 3000:
|
| 477 |
+
st.session_state.messages = []
|
| 478 |
+
print(st.session_state.messages)
|
| 479 |
+
st.experimental_rerun()
|
| 480 |
+
|
| 481 |
+
# Entry point
|
| 482 |
+
if __name__ == '__main__':
|
| 483 |
+
main()
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
|
| 491 |
+
|
ai_lang_teacher/.ipynb_checkpoints/app-checkpoint.py
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from streamlit import elements
|
| 4 |
+
import json
|
| 5 |
+
import uuid
|
| 6 |
+
import os
|
| 7 |
+
from pytube import YouTube
|
| 8 |
+
from moviepy.editor import VideoFileClip
|
| 9 |
+
import openai
|
| 10 |
+
from langchain.llms import OpenAI
|
| 11 |
+
from langchain.chat_models import ChatOpenAI
|
| 12 |
+
from langchain import PromptTemplate
|
| 13 |
+
from langchain.prompts import ChatPromptTemplate
|
| 14 |
+
import time
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
#############--------------- ID and Surveys ------------########################
|
| 19 |
+
# Generate unique user ID
|
| 20 |
+
def generate_unique_id():
|
| 21 |
+
return str(uuid.uuid4())
|
| 22 |
+
|
| 23 |
+
# Save survey answers to a file
|
| 24 |
+
def save_survey_answers(unique_id, answers):
|
| 25 |
+
with open('survey_answers.json', 'w') as f:
|
| 26 |
+
json.dump({unique_id: answers}, f)
|
| 27 |
+
# f.write('\n')
|
| 28 |
+
|
| 29 |
+
# Load all stored unique IDs
|
| 30 |
+
def load_unique_ids():
|
| 31 |
+
try:
|
| 32 |
+
with open('unique_ids.json', 'r') as f:
|
| 33 |
+
return json.load(f)
|
| 34 |
+
except FileNotFoundError:
|
| 35 |
+
return []
|
| 36 |
+
|
| 37 |
+
# Save a unique ID
|
| 38 |
+
def save_unique_id(unique_id):
|
| 39 |
+
ids = load_unique_ids()
|
| 40 |
+
ids.append(unique_id)
|
| 41 |
+
with open('unique_ids.json', 'w') as f:
|
| 42 |
+
json.dump(ids, f)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
#############--------------- Video transcription ------------########################
|
| 46 |
+
|
| 47 |
+
# Download video from URL
|
| 48 |
+
def download_video(url, output_directory='./downloads'):
|
| 49 |
+
try:
|
| 50 |
+
yt = YouTube(url)
|
| 51 |
+
video = yt.streams.get_highest_resolution()
|
| 52 |
+
if not os.path.exists(output_directory):
|
| 53 |
+
os.makedirs(output_directory)
|
| 54 |
+
video.download(output_path=output_directory)
|
| 55 |
+
return os.path.join(output_directory, video.default_filename), 'Video downloaded successfully.'
|
| 56 |
+
except Exception as e:
|
| 57 |
+
message = f'An error occurred: {e}'
|
| 58 |
+
return None, message
|
| 59 |
+
|
| 60 |
+
# Convert video to audio
|
| 61 |
+
def convert_to_audio(video_path, output_directory='./converted_audio'):
|
| 62 |
+
try:
|
| 63 |
+
video = VideoFileClip(video_path)
|
| 64 |
+
audio_filename = f"{os.path.basename(video_path).split('.')[0]}.wav"
|
| 65 |
+
audio_path = os.path.join(output_directory, audio_filename)
|
| 66 |
+
if not os.path.exists(output_directory):
|
| 67 |
+
os.makedirs(output_directory)
|
| 68 |
+
video.audio.write_audiofile(audio_path)
|
| 69 |
+
message = 'Audio converted successfully.'
|
| 70 |
+
return audio_path, message
|
| 71 |
+
except Exception as e:
|
| 72 |
+
message = f"An error occurred: {e}"
|
| 73 |
+
return None, message
|
| 74 |
+
|
| 75 |
+
# Transcribe audio
|
| 76 |
+
# Take WAV file from downloads and save to converted audio folder
|
| 77 |
+
import os
|
| 78 |
+
from dotenv import load_dotenv, find_dotenv
|
| 79 |
+
import openai
|
| 80 |
+
import eyed3
|
| 81 |
+
import pyaudio
|
| 82 |
+
import wave
|
| 83 |
+
import json
|
| 84 |
+
|
| 85 |
+
# Load API key from .env file
|
| 86 |
+
load_dotenv(find_dotenv())
|
| 87 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 88 |
+
|
| 89 |
+
# Split long audio files into clips to be processed by Whisper API
|
| 90 |
+
def split_audio_pyaudio(audio_path, clip_duration_sec=30, overlap_duration_sec=3, output_folder='converted_audio/clips'):
|
| 91 |
+
clip_list = []
|
| 92 |
+
file_name = os.path.basename(audio_path)[:-4]
|
| 93 |
+
|
| 94 |
+
# Determine the total duration of the audio file
|
| 95 |
+
if audio_path.endswith('.mp3'):
|
| 96 |
+
audio_file = eyed3.load(audio_path)
|
| 97 |
+
total_duration = audio_file.info.time_secs
|
| 98 |
+
elif audio_path.endswith('.wav'):
|
| 99 |
+
with wave.open(audio_path, 'rb') as wf:
|
| 100 |
+
n_frames = wf.getnframes()
|
| 101 |
+
framerate = wf.getframerate()
|
| 102 |
+
total_duration = n_frames / framerate
|
| 103 |
+
else:
|
| 104 |
+
raise ValueError("Unsupported audio format")
|
| 105 |
+
|
| 106 |
+
if not os.path.exists(output_folder):
|
| 107 |
+
os.makedirs(output_folder)
|
| 108 |
+
|
| 109 |
+
CHUNK = 1024
|
| 110 |
+
FORMAT = pyaudio.paInt16
|
| 111 |
+
CHANNELS = 2
|
| 112 |
+
RATE = 44100
|
| 113 |
+
clip_duration_samples = clip_duration_sec * RATE
|
| 114 |
+
overlap_samples = overlap_duration_sec * RATE
|
| 115 |
+
|
| 116 |
+
wf = wave.open(audio_path, 'rb')
|
| 117 |
+
p = pyaudio.PyAudio()
|
| 118 |
+
|
| 119 |
+
clip_number = 1
|
| 120 |
+
for start_sample in range(0, int(total_duration * RATE), clip_duration_samples - overlap_samples):
|
| 121 |
+
frames = []
|
| 122 |
+
|
| 123 |
+
for i in range(0, int(RATE / CHUNK * clip_duration_sec)):
|
| 124 |
+
data = wf.readframes(CHUNK)
|
| 125 |
+
if not data:
|
| 126 |
+
break
|
| 127 |
+
frames.append(data)
|
| 128 |
+
|
| 129 |
+
clip_path = f"{output_folder}/{file_name}_clip_{clip_number}.wav"
|
| 130 |
+
wf_clip = wave.open(clip_path, 'wb')
|
| 131 |
+
wf_clip.setnchannels(CHANNELS)
|
| 132 |
+
wf_clip.setsampwidth(p.get_sample_size(FORMAT))
|
| 133 |
+
wf_clip.setframerate(RATE)
|
| 134 |
+
wf_clip.writeframes(b''.join(frames))
|
| 135 |
+
wf_clip.close()
|
| 136 |
+
|
| 137 |
+
clip_list.append(clip_path)
|
| 138 |
+
clip_number += 1
|
| 139 |
+
|
| 140 |
+
wf.close()
|
| 141 |
+
p.terminate()
|
| 142 |
+
|
| 143 |
+
return clip_list
|
| 144 |
+
|
| 145 |
+
# Takes WAV audio clips and transcribes them and saves them to JSON
|
| 146 |
+
def transcribe(audio_path):
|
| 147 |
+
clip_path_list = split_audio_pyaudio(audio_path)
|
| 148 |
+
file_name = os.path.basename(audio_path)[:-4]
|
| 149 |
+
transcribed_clips = []
|
| 150 |
+
# Ensure the transcript file is empty to start with
|
| 151 |
+
with open(f'{file_name}.txt', 'w') as txt_file:
|
| 152 |
+
pass
|
| 153 |
+
|
| 154 |
+
for clip in clip_path_list:
|
| 155 |
+
with wave.open(clip, 'rb') as wf:
|
| 156 |
+
n_frames = wf.getnframes()
|
| 157 |
+
framerate = wf.getframerate()
|
| 158 |
+
clip_duration = n_frames / framerate
|
| 159 |
+
|
| 160 |
+
if clip_duration < 0.1:
|
| 161 |
+
print(f"Skipping short clip (less than 0.1 sec): {clip}")
|
| 162 |
+
continue # Skip short clips
|
| 163 |
+
|
| 164 |
+
with open(clip, 'rb') as audio_file:
|
| 165 |
+
transcript = openai.Audio.transcribe(
|
| 166 |
+
file=audio_file,
|
| 167 |
+
model="whisper-1",
|
| 168 |
+
response_format='text',
|
| 169 |
+
temperature=0.0
|
| 170 |
+
)
|
| 171 |
+
transcribed_clips.append(transcript + '\n')
|
| 172 |
+
# with open(f'transcript/{file_name}.text', 'a') as txt_file:
|
| 173 |
+
# txt_file.write(transcript + '\n')
|
| 174 |
+
full_transcript_str = ''.join(transcribed_clips)
|
| 175 |
+
|
| 176 |
+
messages=[
|
| 177 |
+
{'role':'system', 'content':'''You are a robot that is specifically designed to figure out what language a transcript is in.
|
| 178 |
+
When given a transcript, ONLY return the ISO-639-1 language code. Take your time and think this through.'''},
|
| 179 |
+
{'role': 'user', 'content': 'je suis amΓ©ricain'},
|
| 180 |
+
{'role': 'assistant', 'content': 'fr'},
|
| 181 |
+
{'role': 'user', 'content': full_transcript_str}
|
| 182 |
+
]
|
| 183 |
+
|
| 184 |
+
response = openai.ChatCompletion.create(
|
| 185 |
+
model='gpt-3.5-turbo-0613',
|
| 186 |
+
messages=messages,
|
| 187 |
+
temperature=0
|
| 188 |
+
)
|
| 189 |
+
language = response['choices'][0]['message']['content']
|
| 190 |
+
|
| 191 |
+
transcript_json = {'title': os.path.basename(audio_path)[:-4], 'transcript': full_transcript_str, 'language' : language}
|
| 192 |
+
|
| 193 |
+
with open(f'transcript/{file_name}.json', 'w') as json_file:
|
| 194 |
+
json.dump(transcript_json, json_file, indent=4)
|
| 195 |
+
|
| 196 |
+
message = "Transcription process completed!"
|
| 197 |
+
return transcript_json, message
|
| 198 |
+
# def transcribe_audio(audio_path):
|
| 199 |
+
# try:
|
| 200 |
+
# # audio_file = open(audio_path, 'rb')
|
| 201 |
+
# # v1_transcript = openai.Audio.transcribe(
|
| 202 |
+
# # file=audio_file,
|
| 203 |
+
# # model="whisper-1",
|
| 204 |
+
# # response_format='json',
|
| 205 |
+
# # temperature=0.2
|
| 206 |
+
# # )
|
| 207 |
+
|
| 208 |
+
# # Detect language
|
| 209 |
+
# messages = [
|
| 210 |
+
# {'role': 'system', 'content': 'You are a robot that is specifically designed to figure out what language a transcript is in. When given a transcript, ONLY return the ISO-639-1 language code. Take your time and think this through.'},
|
| 211 |
+
# {'role': 'user', 'content': v1_transcript['text'][:100]}
|
| 212 |
+
# ]
|
| 213 |
+
# response = openai.ChatCompletion.create(
|
| 214 |
+
# model='gpt-3.5-turbo-0613',
|
| 215 |
+
# messages=messages,
|
| 216 |
+
# temperature=0
|
| 217 |
+
# )
|
| 218 |
+
# language = response['choices'][0]['message']['content']
|
| 219 |
+
# v1_transcript['language'] = language
|
| 220 |
+
|
| 221 |
+
# # Display in chat box
|
| 222 |
+
# message = "Transcription successful."
|
| 223 |
+
# return v1_transcript, message
|
| 224 |
+
# except Exception as e:
|
| 225 |
+
# message = f"An error occurred: {e}"
|
| 226 |
+
# return None, message
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
# Save the transcript
|
| 230 |
+
# def save_transcript(transcript, audio_path, output_directory='./transcripts'):
|
| 231 |
+
# try:
|
| 232 |
+
# transcript_filename = f"{os.path.basename(audio_path).split('.')[0]}"
|
| 233 |
+
# if not os.path.exists(output_directory):
|
| 234 |
+
# os.makedirs(output_directory)
|
| 235 |
+
# json_path = os.path.join(output_directory, f'{transcript_filename}.json')
|
| 236 |
+
# with open(json_path, 'w') as json_file:
|
| 237 |
+
# json.dump(transcript, json_file)
|
| 238 |
+
# message = 'Transcript saved successfully.'
|
| 239 |
+
# return json_path, message
|
| 240 |
+
# except Exception as e:
|
| 241 |
+
# message = f"An error occurred: {e}"
|
| 242 |
+
# return None, message
|
| 243 |
+
|
| 244 |
+
#############--------------- Teacher ------------########################
|
| 245 |
+
# Function to get plain English word for language code
|
| 246 |
+
def get_language_word(language, openai_api_key=''):
|
| 247 |
+
llm = OpenAI(model_name='gpt-3.5-turbo-0613', openai_api_key=openai_api_key, temperature=0)
|
| 248 |
+
template = '''Convert the ISO-639-1 language code into the plain english word for the language. ONLY return the english word for that language, nothing more.
|
| 249 |
+
Here is the language code: {language}
|
| 250 |
+
Take your time and think this through. Remember only respond with one word, the english word for the language.'''
|
| 251 |
+
prompt = PromptTemplate(
|
| 252 |
+
input_variables=['language'],
|
| 253 |
+
template=template,
|
| 254 |
+
)
|
| 255 |
+
final_prompt = prompt.format(language=language)
|
| 256 |
+
return llm(final_prompt)
|
| 257 |
+
|
| 258 |
+
# Function to create lesson outline
|
| 259 |
+
def create_lesson_outline(transcript_json, learning_goal='learn new languague', num_words='5', openai_api_key=''):
|
| 260 |
+
try:
|
| 261 |
+
with open('lesson_format.txt', 'r') as txt_file:
|
| 262 |
+
lesson_format = txt_file.read()
|
| 263 |
+
except FileNotFoundError:
|
| 264 |
+
return "Error: 'lesson_format.txt' not found. Please make sure it's in the current working directory."
|
| 265 |
+
|
| 266 |
+
chat = ChatOpenAI(temperature=0.2, model='gpt-3.5-turbo-0613', openai_api_key=openai_api_key)
|
| 267 |
+
template_string = '''Create a lesson based on this title ```{title}```, following this transcript ```{transcript_text}```, and following this format ```{lesson_format}```. Keep in mind the student's learning goal ```{learning_goal}``` and the number of words they want to learn```{num_words}```. For context you are making a lesson plan based on the title of an audio clip taken from a youtube video. Again the title of the video is {title}. Take this into account when making the title of the lesson plan and teaching the concept.
|
| 268 |
+
Only output the lesson plan, nothing more'''
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
prompt_template = ChatPromptTemplate.from_template(template_string)
|
| 272 |
+
messages = prompt_template.format_messages(
|
| 273 |
+
lesson_format=lesson_format,
|
| 274 |
+
transcript_text=transcript_json['transcript'],
|
| 275 |
+
title=transcript_json['title'],
|
| 276 |
+
learning_goal=learning_goal,
|
| 277 |
+
num_words=num_words
|
| 278 |
+
)
|
| 279 |
+
response = chat(messages)
|
| 280 |
+
message = 'Lesson outline created successfully.'
|
| 281 |
+
return response.content, message
|
| 282 |
+
|
| 283 |
+
#############--------------- Chat bot ------------########################
|
| 284 |
+
|
| 285 |
+
# Initialize the chatbox state
|
| 286 |
+
def initialize_chatbox():
|
| 287 |
+
if "messages" not in st.session_state:
|
| 288 |
+
st.session_state["messages"] = []
|
| 289 |
+
|
| 290 |
+
# Add a message to the chatbox
|
| 291 |
+
def add_to_chatbox(role, message):
|
| 292 |
+
st.session_state.messages.append({"role": role, "content": message})
|
| 293 |
+
|
| 294 |
+
if role == "user": # If the message is from the user
|
| 295 |
+
response = openai.ChatCompletion.create(
|
| 296 |
+
model="gpt-3.5-turbo-0613",
|
| 297 |
+
prompt=message,
|
| 298 |
+
max_tokens=150 # Limit the response to 150 tokens
|
| 299 |
+
)
|
| 300 |
+
teacher_response = response.choices[0] # Extract the bot's response text
|
| 301 |
+
st.session_state.messages.append({"role": "assistant", "content": teacher_response})
|
| 302 |
+
|
| 303 |
+
# Display the chatbox
|
| 304 |
+
def display_chatbox():
|
| 305 |
+
st.markdown("<div id='chatbox-container'>", unsafe_allow_html=True)
|
| 306 |
+
for msg in st.session_state.messages:
|
| 307 |
+
st.chat_message(msg["role"]).write(msg["content"])
|
| 308 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
############################## Main Streamlit app #################################
|
| 314 |
+
# Main function
|
| 315 |
+
def main():
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
# Initialize all session_state variables
|
| 319 |
+
for key, default_value in {
|
| 320 |
+
'access_granted': False,
|
| 321 |
+
'survey_done': False,
|
| 322 |
+
'unique_id': '',
|
| 323 |
+
'show_chat_window': False,
|
| 324 |
+
'video_url': '',
|
| 325 |
+
'chat_history': [],
|
| 326 |
+
'messages': [],
|
| 327 |
+
'transcribe_clicked': False,
|
| 328 |
+
}.items():
|
| 329 |
+
if key not in st.session_state:
|
| 330 |
+
st.session_state[key] = default_value
|
| 331 |
+
|
| 332 |
+
st.title('Language Learning AI Tutor')
|
| 333 |
+
st.text('Please wait a few mins after hitting the "Create Lesson" button')
|
| 334 |
+
|
| 335 |
+
# Access Control
|
| 336 |
+
# Check if the API key is already in the session state
|
| 337 |
+
if "api_key" not in st.session_state or not st.session_state.api_key:
|
| 338 |
+
# If the API key is not in the session state, display the input field
|
| 339 |
+
entered_api_key = st.text_input("Enter your API key:", type='password')
|
| 340 |
+
openai.api_key = entered_api_key
|
| 341 |
+
openai_api_key = entered_api_key
|
| 342 |
+
|
| 343 |
+
# Update the session state with the entered API key
|
| 344 |
+
if entered_api_key:
|
| 345 |
+
st.session_state.api_key = entered_api_key
|
| 346 |
+
else:
|
| 347 |
+
st.write("API key loaded successfully!")
|
| 348 |
+
# Load the API key:
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
if not st.session_state['access_granted']:
|
| 358 |
+
entered_id = st.text_input('Enter your unique ID to access the app:')
|
| 359 |
+
|
| 360 |
+
if st.button('Submit ID'):
|
| 361 |
+
unique_ids = load_unique_ids()
|
| 362 |
+
if entered_id in unique_ids:
|
| 363 |
+
st.session_state['access_granted'] = True
|
| 364 |
+
st.session_state['survey_done'] = True
|
| 365 |
+
st.session_state['unique_id'] = entered_id
|
| 366 |
+
st.success("Access granted.")
|
| 367 |
+
st.experimental_rerun()
|
| 368 |
+
else:
|
| 369 |
+
st.warning('Invalid ID. Access denied.')
|
| 370 |
+
|
| 371 |
+
if st.button('Generate New ID'):
|
| 372 |
+
new_id = generate_unique_id()
|
| 373 |
+
save_unique_id(new_id)
|
| 374 |
+
st.session_state['access_granted'] = True
|
| 375 |
+
st.session_state['unique_id'] = new_id
|
| 376 |
+
st.session_state['survey_done'] = False
|
| 377 |
+
st.success(f"New ID generated: {new_id}")
|
| 378 |
+
|
| 379 |
+
else:
|
| 380 |
+
if not st.session_state['survey_done']:
|
| 381 |
+
st.subheader('Survey Questions')
|
| 382 |
+
learning_goal = st.text_input("What's your daily learning goal?")
|
| 383 |
+
num_words = st.text_input('How many words do you want to learn?')
|
| 384 |
+
|
| 385 |
+
if st.button('Submit Survey'):
|
| 386 |
+
answers = {'learning_goal': learning_goal, 'num_words': num_words}
|
| 387 |
+
save_survey_answers(st.session_state['unique_id'], answers)
|
| 388 |
+
st.session_state['learning_goal'] = learning_goal
|
| 389 |
+
st.session_state['num_words'] = num_words
|
| 390 |
+
st.session_state['survey_done'] = True
|
| 391 |
+
st.success('Survey answers submitted!')
|
| 392 |
+
st.experimental_rerun()
|
| 393 |
+
|
| 394 |
+
# Sidebar for Video Upload
|
| 395 |
+
if st.session_state['access_granted'] and st.session_state['survey_done']:
|
| 396 |
+
with st.sidebar:
|
| 397 |
+
st.title('Video Upload')
|
| 398 |
+
video_url = st.text_input('Paste your YouTube video link here')
|
| 399 |
+
if st.button('Create Lesson'):
|
| 400 |
+
st.session_state.video_url = video_url
|
| 401 |
+
st.session_state.show_chat_window = True
|
| 402 |
+
st.session_state.transcribe_clicked = True
|
| 403 |
+
# st.sidebar.video(video_url)
|
| 404 |
+
# Save to session state that video should be displayed
|
| 405 |
+
st.session_state.display_video = True
|
| 406 |
+
|
| 407 |
+
# Check if video should be displayed in the sidebar
|
| 408 |
+
if 'display_video' in st.session_state and st.session_state.display_video:
|
| 409 |
+
st.sidebar.video(video_url)
|
| 410 |
+
|
| 411 |
+
# Clears state/screen
|
| 412 |
+
if st.button("Clear Messages"):
|
| 413 |
+
if 'messages' in st.session_state:
|
| 414 |
+
st.session_state['messages']=[]
|
| 415 |
+
|
| 416 |
+
# Main chat interface
|
| 417 |
+
if st.session_state.get('show_chat_window', False):
|
| 418 |
+
# Display previous chat messages
|
| 419 |
+
for message in st.session_state.messages:
|
| 420 |
+
with st.chat_message(message["role"]):
|
| 421 |
+
st.markdown(message["content"])
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
user_input = st.chat_input("begin lesson here and ask questions...")
|
| 426 |
+
if user_input:
|
| 427 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 428 |
+
|
| 429 |
+
# Ensure that st.session_state.messages is a list with the correct structure
|
| 430 |
+
if not isinstance(st.session_state.messages, list):
|
| 431 |
+
st.session_state.messages = []
|
| 432 |
+
|
| 433 |
+
response = openai.ChatCompletion.create(
|
| 434 |
+
model="gpt-3.5-turbo-0613",
|
| 435 |
+
messages=st.session_state.messages,
|
| 436 |
+
max_tokens=500 # Limit the response to 150 tokens
|
| 437 |
+
)
|
| 438 |
+
teacher_response = response.choices[0].message['content'].strip() # Extract the teacher's response text correctly
|
| 439 |
+
st.session_state.messages.append({"role": "assistant", "content": teacher_response})
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
# Perform transcription if Transcribe button is clicked
|
| 443 |
+
if st.session_state.get('transcribe_clicked', False):
|
| 444 |
+
st.session_state.transcribe_clicked = False
|
| 445 |
+
|
| 446 |
+
# Download video
|
| 447 |
+
video_path, video_message = download_video(st.session_state['video_url'])
|
| 448 |
+
st.session_state.messages.append({"role": "assistant", "content": video_message})
|
| 449 |
+
|
| 450 |
+
if video_path:
|
| 451 |
+
# Convert to audio
|
| 452 |
+
audio_path, audio_message = convert_to_audio(video_path)
|
| 453 |
+
st.session_state.messages.append({"role": "assistant", "content": audio_message})
|
| 454 |
+
|
| 455 |
+
if audio_path:
|
| 456 |
+
# Transcribe audio
|
| 457 |
+
transcript_data, transcript_message = transcribe(audio_path)
|
| 458 |
+
st.session_state.messages.append({"role": "assistant", "content": transcript_message})
|
| 459 |
+
|
| 460 |
+
# if transcript_data is not None:
|
| 461 |
+
# Detect language
|
| 462 |
+
language = get_language_word(transcript_data['language'])
|
| 463 |
+
st.session_state.messages.append({"role": "assistant", "content": f"Detected language is {language}"})
|
| 464 |
+
|
| 465 |
+
# Create lesson from transcript
|
| 466 |
+
lesson_content, lesson_message = create_lesson_outline(transcript_data)
|
| 467 |
+
st.session_state.messages.append({"role": "assistant", "content": "Here's the transcript and the lesson plan"})
|
| 468 |
+
st.session_state.messages.append({"role": "assistant", "content": '**Transcript: **' + transcript_data['transcript']})
|
| 469 |
+
st.session_state.messages.append({"role": "assistant", "content": '**Lesson plan: **' + lesson_content})
|
| 470 |
+
# st.session_state.messages.append({"role": "assistant", "content": lesson_content})
|
| 471 |
+
st.session_state.messages.append(
|
| 472 |
+
{"role": "system", "content": f'Follow the lesson plan as outlined: {lesson_content} and try your best not to deviate. Teach each word one at at time and explain in detail, including writing system or other relavent details for a firt time learner. Think this out step by step'})
|
| 473 |
+
st.experimental_rerun()
|
| 474 |
+
|
| 475 |
+
# Entry point
|
| 476 |
+
if __name__ == '__main__':
|
| 477 |
+
main()
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
|
ai_lang_teacher/.ipynb_checkpoints/lesson_format-checkpoint.txt
ADDED
|
File without changes
|
ai_lang_teacher/.ipynb_checkpoints/lesson_plan-checkpoint
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
**Lesson Title:** Building Confidence and Trust in Japanese
|
| 2 |
+
|
| 3 |
+
**Objective:** By the end of this lesson, learners will be able to understand and use basic Japanese phrases related to building confidence and trust in oneself and others.
|
| 4 |
+
|
| 5 |
+
**Lesson Structure:**
|
| 6 |
+
|
| 7 |
+
**1. Introduction (2 minutes):**
|
| 8 |
+
- Greet the learners and briefly introduce the purpose of the lesson: to learn basic Japanese phrases related to building confidence and trust.
|
| 9 |
+
|
| 10 |
+
**2. Audio Listening (5 minutes):**
|
| 11 |
+
- Ask the student (refer to their name) to play the audio clip of the transcript once to allow learners to listen and get a feel for the pronunciation and intonation.
|
| 12 |
+
|
| 13 |
+
**3. Vocabulary Building (5 minutes):**
|
| 14 |
+
- Introduce and explain the key phrases:
|
| 15 |
+
- γγγγ·γ’γ³ (ii ka shimon) - Listen up, Simon.
|
| 16 |
+
- εΏγγγͺ (wasurenna) - Don't forget.
|
| 17 |
+
- γεγδΏ‘γγ (omae o shinjiro) - Believe in yourself.
|
| 18 |
+
- δΏΊγδΏ‘γγγεγ§γγͺγ (ore ga shinjiru omae demo nai) - It's not about you believing in me.
|
| 19 |
+
- γεγδΏ‘γγδΏΊγ§γγͺγ (omae ga shinjiru ore demo nai) - It's not about me believing in you.
|
| 20 |
+
- γεγδΏ‘γγγεγδΏ‘γγ (omae ga shinjiru omae o shinjiro) - Believe in the version of yourself that you believe in.
|
| 21 |
+
- Pronounce each phrase clearly and encourage learners to repeat after you.
|
| 22 |
+
|
| 23 |
+
**4. Practice (2 minutes):**
|
| 24 |
+
- Ask learners to repeat each phrase after you to practice pronunciation.
|
| 25 |
+
|
| 26 |
+
**5. Summary (1 minute):**
|
| 27 |
+
- Summarize what was learned in the lesson: the meanings and pronunciations of the three phrases.
|
| 28 |
+
|
| 29 |
+
**6. Closing Remarks (1 minute):**
|
| 30 |
+
- Encourage learners to continue practicing these phrases on their own and use them to encourage themselves and others.
|
| 31 |
+
|
| 32 |
+
**7. Homework (optional, 1 minute):**
|
| 33 |
+
- If desired, assign optional homework: Have learners find a friend or family member to share the phrases they've learned and encourage them in Japanese.
|
| 34 |
+
|
| 35 |
+
**8. Q&A:**
|
| 36 |
+
- Open the floor for any questions learners may have.
|
ai_lang_teacher/.ipynb_checkpoints/teacher_script-checkpoint.txt
ADDED
|
File without changes
|
ai_lang_teacher/.virtual_documents/Long clip transcriber.ipynb
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# download clip to a download folder
|
| 2 |
+
import os
|
| 3 |
+
from pytube import YouTube
|
| 4 |
+
import gradio as gr
|
| 5 |
+
def download_video(url):
|
| 6 |
+
try:
|
| 7 |
+
yt = YouTube(url)
|
| 8 |
+
video = yt.streams.get_highest_resolution()
|
| 9 |
+
output_directory = './downloads' # Note: Using './' to specify a relative path
|
| 10 |
+
if not os.path.exists(output_directory):
|
| 11 |
+
os.makedirs(output_directory)
|
| 12 |
+
video.download(output_path=output_directory)
|
| 13 |
+
return f"Video '{yt.title}' has been downloaded successfully."
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"An error occurred: {e}"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
interface = gr.Interface(
|
| 19 |
+
fn=download_video,
|
| 20 |
+
inputs=gr.inputs.Textbox(label="Enter YouTube URL:"),
|
| 21 |
+
outputs=gr.outputs.Textbox(label="Status:")
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Launch the interface and capture the URL
|
| 25 |
+
url = interface.launch()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Take WAV file from downloads and save to converted audio folder
|
| 30 |
+
import os
|
| 31 |
+
from dotenv import load_dotenv, find_dotenv
|
| 32 |
+
import openai
|
| 33 |
+
import eyed3
|
| 34 |
+
import pyaudio
|
| 35 |
+
import wave
|
| 36 |
+
import json
|
| 37 |
+
|
| 38 |
+
# Load API key from .env file
|
| 39 |
+
load_dotenv(find_dotenv())
|
| 40 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 41 |
+
|
| 42 |
+
def split_audio_pyaudio(audio_path, clip_duration_sec=30, overlap_duration_sec=3, output_folder='converted_audio/clips'):
|
| 43 |
+
clip_list = []
|
| 44 |
+
file_name = os.path.basename(audio_path)[:-4]
|
| 45 |
+
|
| 46 |
+
# Determine the total duration of the audio file
|
| 47 |
+
if audio_path.endswith('.mp3'):
|
| 48 |
+
audio_file = eyed3.load(audio_path)
|
| 49 |
+
total_duration = audio_file.info.time_secs
|
| 50 |
+
elif audio_path.endswith('.wav'):
|
| 51 |
+
with wave.open(audio_path, 'rb') as wf:
|
| 52 |
+
n_frames = wf.getnframes()
|
| 53 |
+
framerate = wf.getframerate()
|
| 54 |
+
total_duration = n_frames / framerate
|
| 55 |
+
else:
|
| 56 |
+
raise ValueError("Unsupported audio format")
|
| 57 |
+
|
| 58 |
+
if not os.path.exists(output_folder):
|
| 59 |
+
os.makedirs(output_folder)
|
| 60 |
+
|
| 61 |
+
CHUNK = 1024
|
| 62 |
+
FORMAT = pyaudio.paInt16
|
| 63 |
+
CHANNELS = 2
|
| 64 |
+
RATE = 44100
|
| 65 |
+
clip_duration_samples = clip_duration_sec * RATE
|
| 66 |
+
overlap_samples = overlap_duration_sec * RATE
|
| 67 |
+
|
| 68 |
+
wf = wave.open(audio_path, 'rb')
|
| 69 |
+
p = pyaudio.PyAudio()
|
| 70 |
+
|
| 71 |
+
clip_number = 1
|
| 72 |
+
for start_sample in range(0, int(total_duration * RATE), clip_duration_samples - overlap_samples):
|
| 73 |
+
frames = []
|
| 74 |
+
|
| 75 |
+
for i in range(0, int(RATE / CHUNK * clip_duration_sec)):
|
| 76 |
+
data = wf.readframes(CHUNK)
|
| 77 |
+
if not data:
|
| 78 |
+
break
|
| 79 |
+
frames.append(data)
|
| 80 |
+
|
| 81 |
+
clip_path = f"{output_folder}/{file_name}_clip_{clip_number}.wav"
|
| 82 |
+
wf_clip = wave.open(clip_path, 'wb')
|
| 83 |
+
wf_clip.setnchannels(CHANNELS)
|
| 84 |
+
wf_clip.setsampwidth(p.get_sample_size(FORMAT))
|
| 85 |
+
wf_clip.setframerate(RATE)
|
| 86 |
+
wf_clip.writeframes(b''.join(frames))
|
| 87 |
+
wf_clip.close()
|
| 88 |
+
|
| 89 |
+
clip_list.append(clip_path)
|
| 90 |
+
clip_number += 1
|
| 91 |
+
|
| 92 |
+
wf.close()
|
| 93 |
+
p.terminate()
|
| 94 |
+
|
| 95 |
+
return clip_list
|
| 96 |
+
|
| 97 |
+
def transcribe(audio_path):
|
| 98 |
+
clip_path_list = split_audio_pyaudio(audio_path)
|
| 99 |
+
file_name = os.path.basename(audio_path)[:-4]
|
| 100 |
+
transcribed_clips = []
|
| 101 |
+
# Ensure the transcript file is empty to start with
|
| 102 |
+
with open(f'{file_name}.txt', 'w') as txt_file:
|
| 103 |
+
pass
|
| 104 |
+
|
| 105 |
+
for clip in clip_path_list:
|
| 106 |
+
with wave.open(clip, 'rb') as wf:
|
| 107 |
+
n_frames = wf.getnframes()
|
| 108 |
+
framerate = wf.getframerate()
|
| 109 |
+
clip_duration = n_frames / framerate
|
| 110 |
+
|
| 111 |
+
if clip_duration < 0.1:
|
| 112 |
+
print(f"Skipping short clip (less than 0.1 sec): {clip}")
|
| 113 |
+
continue # Skip short clips
|
| 114 |
+
|
| 115 |
+
with open(clip, 'rb') as audio_file:
|
| 116 |
+
transcript = openai.Audio.transcribe(
|
| 117 |
+
file=audio_file,
|
| 118 |
+
model="whisper-1",
|
| 119 |
+
response_format='text',
|
| 120 |
+
temperature=0.2
|
| 121 |
+
)
|
| 122 |
+
transcribed_clips.append(transcript + '\n')
|
| 123 |
+
# with open(f'transcript/{file_name}.text', 'a') as txt_file:
|
| 124 |
+
# txt_file.write(transcript + '\n')
|
| 125 |
+
full_transcript_str = ''.join(transcribed_clips)
|
| 126 |
+
|
| 127 |
+
messages=[
|
| 128 |
+
{'role':'system', 'content':'''You are a robot that is specifically designed to figure out what language a transcript is in.
|
| 129 |
+
When given a transcript, ONLY return the ISO-639-1 language code. Take your time and think this through.'''},
|
| 130 |
+
{'role': 'user', 'content': 'je suis amΓ©ricain'},
|
| 131 |
+
{'role': 'assistant', 'content': 'fr'},
|
| 132 |
+
{'role': 'user', 'content': full_transcript_str}
|
| 133 |
+
]
|
| 134 |
+
|
| 135 |
+
response = openai.ChatCompletion.create(
|
| 136 |
+
model='gpt-3.5-turbo-0613',
|
| 137 |
+
messages=messages,
|
| 138 |
+
temperature=0
|
| 139 |
+
)
|
| 140 |
+
language = response['choices'][0]['message']['content']
|
| 141 |
+
|
| 142 |
+
transcript_json = {'transcript': full_transcript_str, 'language' : language}
|
| 143 |
+
|
| 144 |
+
with open(f'transcript/{file_name}.json', 'w') as json_file:
|
| 145 |
+
json.dump(transcript_json, json_file, indent=4)
|
| 146 |
+
|
| 147 |
+
print("Transcription process completed!")
|
| 148 |
+
|
| 149 |
+
transcribe('simple.wav')
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
|
ai_lang_teacher/.virtual_documents/Teacher.ipynb
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.llms import OpenAI
|
| 2 |
+
from langchain.chat_models import ChatOpenAI
|
| 3 |
+
from langchain import PromptTemplate
|
| 4 |
+
from dotenv import load_dotenv, find_dotenv
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 8 |
+
openai_api_key = os.getenv('OPENAI_API_KEY')
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
# select language (should be in the data of the Transcript)
|
| 12 |
+
import json
|
| 13 |
+
transcript_path = 'transcript/Kamina - Believe in me who believes in you.json'
|
| 14 |
+
with open(transcript_path, 'r') as json_file:
|
| 15 |
+
transcript = json.load(json_file)
|
| 16 |
+
language = transcript['language']
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
llm = OpenAI(model_name='gpt-3.5-turbo-0613', openai_api_key=openai_api_key, temperature=0)
|
| 20 |
+
template = '''Convert the ISO-639-1 language code into the plain english word for the language. ONLY return the english word for that language, nothing more.
|
| 21 |
+
Here is the language code: {language}
|
| 22 |
+
Take your time and think this through. Remember only respond with one word, the english word for the language
|
| 23 |
+
|
| 24 |
+
Example:
|
| 25 |
+
input: fr
|
| 26 |
+
your response: french
|
| 27 |
+
'''
|
| 28 |
+
|
| 29 |
+
prompt = PromptTemplate(
|
| 30 |
+
input_variables=['language'],
|
| 31 |
+
template=template,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
final_prompt = prompt.format(language = language)
|
| 35 |
+
language = llm(final_prompt)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# Design and give student outline structure of the lesson
|
| 42 |
+
## everything should happen in a large chat window
|
| 43 |
+
## if first lesson student should recieve the basics for learning japanese (kana table gojuon)
|
| 44 |
+
## give a txt or md or pdf of lesson outline and lesson notes (vocab, romaji, kana, kanji used)
|
| 45 |
+
## when designing the lesson it should pull out the keywords in relation to the clip of interest
|
| 46 |
+
|
| 47 |
+
from langchain.chat_models import ChatOpenAI
|
| 48 |
+
from langchain.prompts import ChatPromptTemplate
|
| 49 |
+
|
| 50 |
+
chat = ChatOpenAI(temperature=0.0, model='gpt-3.5-turbo-0613')
|
| 51 |
+
|
| 52 |
+
transcript_text = transcript['text']
|
| 53 |
+
with open('lesson_format.txt', 'r') as txt_file:
|
| 54 |
+
lesson_format= txt_file.read()
|
| 55 |
+
|
| 56 |
+
template_string = '''Create a lesson based on this transcript {transcript_text} following this format {lesson_format}.
|
| 57 |
+
Only output the lesson plan, nothing more'''
|
| 58 |
+
|
| 59 |
+
prompt_template = ChatPromptTemplate.from_template(template_string)
|
| 60 |
+
prompt_template.messages[0].prompt.input_variables
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
messages = prompt_template.format_messages(
|
| 64 |
+
lesson_format=lesson_format,
|
| 65 |
+
transcript_text=transcript_text
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
response = chat(messages)
|
| 69 |
+
print(messages)
|
| 70 |
+
print('')
|
| 71 |
+
print(response)
|
| 72 |
+
lesson_plan = response.content
|
| 73 |
+
with open('lesson_plan.md', 'w',encoding='utf-8') as md_file:
|
| 74 |
+
md_file.write(lesson_plan)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
# Introduction and greeting to student.
|
| 78 |
+
## Ask their name and greet them
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
# Warm Up
|
| 85 |
+
## Play the clip in full
|
| 86 |
+
## Prompt to ask the student to play the clip and ask if they recognize any words
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# Introduction to Context
|
| 90 |
+
## Discuss what is happening in the clip in English
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
# Audion Listening and Vocab Building
|
| 94 |
+
## play the clip in smaller chunks and explain what every part means
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
# Practice
|
| 100 |
+
## ask student to repeat each clip and tell the teacher when they are done practicing. Provide the clip for them to practice
|
| 101 |
+
## provide them a way to record their voice and see what Whisper API thinks, compare that to the words being asked.
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
# Summary of the lesson
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
# Allow student to ask questions
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
# Memory
|
| 111 |
+
## short term memomry = sliding window/summary approach in lang chain
|
| 112 |
+
## long term memory = vector store + fetching and scanning database of memories
|
ai_lang_teacher/.virtual_documents/Transcriber.ipynb
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# download clip to a download folder
|
| 2 |
+
import os
|
| 3 |
+
from pytube import YouTube
|
| 4 |
+
import gradio as gr
|
| 5 |
+
def download_video(url):
|
| 6 |
+
try:
|
| 7 |
+
yt = YouTube(url)
|
| 8 |
+
video = yt.streams.get_highest_resolution()
|
| 9 |
+
output_directory = './downloads' # Note: Using './' to specify a relative path
|
| 10 |
+
if not os.path.exists(output_directory):
|
| 11 |
+
os.makedirs(output_directory)
|
| 12 |
+
video.download(output_path=output_directory)
|
| 13 |
+
return f"Video '{yt.title}' has been downloaded successfully."
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"An error occurred: {e}"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
interface = gr.Interface(
|
| 19 |
+
fn=download_video,
|
| 20 |
+
inputs=gr.inputs.Textbox(label="Enter YouTube URL:"),
|
| 21 |
+
outputs=gr.outputs.Textbox(label="Status:")
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Launch the interface and capture the URL
|
| 25 |
+
url = interface.launch()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# transcribe clip
|
| 31 |
+
## Convert clip to audio
|
| 32 |
+
from moviepy.editor import VideoFileClip
|
| 33 |
+
video_path = 'downloads/Kamina - Believe in me who believes in you.mp4'
|
| 34 |
+
video = VideoFileClip(video_path)
|
| 35 |
+
audio_path = f'converted_audio/{video_path[9:-4]}.wav' # removes .mp4 file extension
|
| 36 |
+
video.audio.write_audiofile(audio_path)
|
| 37 |
+
|
| 38 |
+
## Transcribe audio
|
| 39 |
+
### Note: Thinking to run a loop to stich together overlapping segments so that transcript is clean. use prompt argument and a way to reference last x-amount of strings of transcript as its being written.
|
| 40 |
+
|
| 41 |
+
### raw_transcript as json
|
| 42 |
+
import openai
|
| 43 |
+
import os
|
| 44 |
+
from dotenv import load_dotenv, find_dotenv
|
| 45 |
+
|
| 46 |
+
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 47 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 48 |
+
|
| 49 |
+
audio_file = open(audio_path, 'rb') # rb is read binary, used to open non-txt files like audio or images
|
| 50 |
+
v1_transcript = openai.Audio.transcribe(
|
| 51 |
+
file=audio_file,
|
| 52 |
+
model="whisper-1",
|
| 53 |
+
response_format='json',
|
| 54 |
+
temperature=0.2
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
### raw_transcript as vtt
|
| 58 |
+
audio_file = open(audio_path, 'rb') # rb is read binary, used to open non-txt files like audio or images
|
| 59 |
+
v1_transcript_vtt = openai.Audio.transcribe(
|
| 60 |
+
file=audio_file,
|
| 61 |
+
model="whisper-1",
|
| 62 |
+
response_format='vtt',
|
| 63 |
+
temperature=0.2
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
# ### ask chatgpt what language this trancript is in (give it the first 1000 strs) should return a one word string
|
| 68 |
+
# #
|
| 69 |
+
messages=[
|
| 70 |
+
{'role':'system', 'content':'''You are a robot that is specifically designed to figure out what language a transcript is in.
|
| 71 |
+
When given a transcript, ONLY return the ISO-639-1 language code. Take your time and think this through.'''},
|
| 72 |
+
{'role': 'user', 'content': 'je suis amΓ©ricain'},
|
| 73 |
+
{'role': 'assistant', 'content': 'fr'},
|
| 74 |
+
{'role': 'user', 'content': v1_transcript['text']}
|
| 75 |
+
]
|
| 76 |
+
response = openai.ChatCompletion.create(
|
| 77 |
+
model='gpt-3.5-turbo-0613',
|
| 78 |
+
messages=messages,
|
| 79 |
+
temperature=0
|
| 80 |
+
)
|
| 81 |
+
language = response['choices'][0]['message']['content']
|
| 82 |
+
v1_transcript['language'] = language
|
| 83 |
+
# ### retranscribe in correct language to improve accuracy
|
| 84 |
+
# audio_file = open(audio_path, 'rb') # rb is read binary, used to open non-txt files like audio or images
|
| 85 |
+
# v2_transcript = openai.Audio.transcribe(
|
| 86 |
+
# file=audio_file,
|
| 87 |
+
# model="whisper-1",
|
| 88 |
+
# response_format='json',
|
| 89 |
+
# temperature=0.2
|
| 90 |
+
# language=language
|
| 91 |
+
# )
|
| 92 |
+
# ###
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
# save transcript as jhson and or vtt file with timestamps
|
| 96 |
+
import json
|
| 97 |
+
transcript_path = f'transcript/{audio_path[15:-4]}.json'
|
| 98 |
+
with open(transcript_path, 'w') as json_file:
|
| 99 |
+
json.dump(v1_transcript, json_file)
|
| 100 |
+
|
| 101 |
+
transcript_path = f'transcript/{audio_path[15:-4]}.vtt'
|
| 102 |
+
with open(transcript_path, 'w',encoding='utf-8') as vtt_file:
|
| 103 |
+
vtt_file.write(v1_transcript_vtt)
|
| 104 |
+
|
| 105 |
+
print(v1_transcript)
|
| 106 |
+
print('')
|
| 107 |
+
print(v1_transcript_vtt)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
# pass to teacher the v1_transcript (json object) or load the object
|
ai_lang_teacher/.virtual_documents/Untitled.ipynb
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.llms import OpenAI
|
| 2 |
+
from langchain.chat_models import ChatOpenAI
|
| 3 |
+
from langchain import PromptTemplate
|
| 4 |
+
from dotenv import load_dotenv, find_dotenv
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 8 |
+
openai_api_key = os.getenv('OPENAI_API_KEY')
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
# select language (should be in the data of the Transcript)
|
| 12 |
+
import json
|
| 13 |
+
transcript_path = 'transcript/Kamina - Believe in me who believes in you.json'
|
| 14 |
+
with open(transcript_path, 'r') as json_file:
|
| 15 |
+
transcript = json.load(json_file)
|
| 16 |
+
language = transcript['language']
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
llm = OpenAI(model_name='gpt-3.5-turbo-0613', openai_api_key=openai_api_key, temperature=0)
|
| 20 |
+
template = '''Convert the ISO-639-1 language code into the plain english word for the language. ONLY return the english word for that language, nothing more.
|
| 21 |
+
Here is the language code: {language}
|
| 22 |
+
Take your time and think this through. Remember only respond with one word, the english word for the language
|
| 23 |
+
|
| 24 |
+
Example:
|
| 25 |
+
input: fr
|
| 26 |
+
your response: french
|
| 27 |
+
'''
|
| 28 |
+
|
| 29 |
+
prompt = PromptTemplate(
|
| 30 |
+
input_variables=['language'],
|
| 31 |
+
template=template,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
final_prompt = prompt.format(language = language)
|
| 35 |
+
language = llm(final_prompt)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# Design and give student outline structure of the lesson
|
| 42 |
+
## everything should happen in a large chat window
|
| 43 |
+
## if first lesson student should recieve the basics for learning japanese (kana table gojuon)
|
| 44 |
+
## give a txt or md or pdf of lesson outline and lesson notes (vocab, romaji, kana, kanji used)
|
| 45 |
+
## when designing the lesson it should pull out the keywords in relation to the clip of interest
|
| 46 |
+
|
| 47 |
+
from langchain.chat_models import ChatOpenAI
|
| 48 |
+
from langchain.prompts import ChatPromptTemplate
|
| 49 |
+
|
| 50 |
+
chat = ChatOpenAI(temperature=0.0, model='gpt-3.5-turbo-0613')
|
| 51 |
+
|
| 52 |
+
transcript_text = transcript['text']
|
| 53 |
+
with open('lesson_format.txt', 'r') as txt_file:
|
| 54 |
+
lesson_format= txt_file.read()
|
| 55 |
+
|
| 56 |
+
template_string = '''Create a lesson based on this transcript {transcript_text} following this format {lesson_format}.
|
| 57 |
+
Only output the lesson plan, nothing more'''
|
| 58 |
+
|
| 59 |
+
prompt_template = ChatPromptTemplate.from_template(template_string)
|
| 60 |
+
prompt_template.messages[0].prompt.input_variables
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
messages = prompt_template.format_messages(
|
| 64 |
+
lesson_format=lesson_format,
|
| 65 |
+
transcript_text=transcript_text
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
response = chat(messages)
|
| 69 |
+
print(messages)
|
| 70 |
+
print('')
|
| 71 |
+
print(response)
|
| 72 |
+
lesson_plan = response.content
|
| 73 |
+
with open('lesson_plan.md', 'w',encoding='utf-8') as md_file:
|
| 74 |
+
md_file.write(lesson_plan)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
# Introduction and greeting to student.
|
| 78 |
+
## Ask their name and greet them
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
# Warm Up
|
| 85 |
+
## Play the clip in full
|
| 86 |
+
## Prompt to ask the student to play the clip and ask if they recognize any words
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# Introduction to Context
|
| 90 |
+
## Discuss what is happening in the clip in English
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
# Audion Listening and Vocab Building
|
| 94 |
+
## play the clip in smaller chunks and explain what every part means
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
# Practice
|
| 100 |
+
## ask student to repeat each clip and tell the teacher when they are done practicing. Provide the clip for them to practice
|
| 101 |
+
## provide them a way to record their voice and see what Whisper API thinks, compare that to the words being asked.
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
# Summary of the lesson
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
# Allow student to ask questions
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
# Memory
|
| 111 |
+
## short term memomry = sliding window/summary approach in lang chain
|
| 112 |
+
## long term memory = vector store + fetching and scanning database of memories
|
ai_lang_teacher/.virtual_documents/YT_downloader.ipynb
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# download clip to a download folder
|
| 2 |
+
import os
|
| 3 |
+
from pytube import YouTube
|
| 4 |
+
|
| 5 |
+
def download_video(url):
|
| 6 |
+
try:
|
| 7 |
+
yt = YouTube(url)
|
| 8 |
+
video = yt.streams.get_highest_resolution()
|
| 9 |
+
output_directory = './downloads' # Note: Using './' to specify a relative path
|
| 10 |
+
if not os.path.exists(output_directory):
|
| 11 |
+
os.makedirs(output_directory)
|
| 12 |
+
video.download(output_path=output_directory)
|
| 13 |
+
return f"Video '{yt.title}' has been downloaded successfully."
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"An error occurred: {e}"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
interface = gr.Interface(
|
| 19 |
+
fn=download_video,
|
| 20 |
+
inputs=gr.inputs.Textbox(label="Enter YouTube URL:"),
|
| 21 |
+
outputs=gr.outputs.Textbox(label="Status:")
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Launch the interface and capture the URL
|
| 25 |
+
url = interface.launch()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# transcribe clip
|
| 31 |
+
## Convert clip to audio
|
| 32 |
+
from moviepy.editor import VideoFileClip
|
| 33 |
+
video_path = 'downloads/Kamina - Believe in me who believes in you.mp4'
|
| 34 |
+
video = VideoFileClip(video_path)
|
| 35 |
+
audio_path = f'converted_audio/{video_path[9:-4]}.wav' # removes .mp4 file extension
|
| 36 |
+
video.audio.write_audiofile(audio_path)
|
| 37 |
+
|
| 38 |
+
## Transcribe audio
|
| 39 |
+
### Note: Thinking to run a loop to stich together overlapping segments so that transcript is clean. use prompt argument and a way to reference last x-amount of strings of transcript as its being written.
|
| 40 |
+
|
| 41 |
+
### raw_transcript
|
| 42 |
+
import openai
|
| 43 |
+
import os
|
| 44 |
+
from dotenv import load_dotenv
|
| 45 |
+
load_dotenv()
|
| 46 |
+
openai_key = os.getenv('OPENAI_API_KEY')
|
| 47 |
+
audio_file = open(audio_path, 'rb') # rb is read binary, used to open non-txt files like audio or images
|
| 48 |
+
v1_transcript = openai.Audio.transcribe(
|
| 49 |
+
file=audio_file,
|
| 50 |
+
model="whisper-1",
|
| 51 |
+
response_format='json',
|
| 52 |
+
temperature=0.2
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# ### ask chatgpt what language this trancript is in (give it the first 1000 strs) should return a one word string
|
| 56 |
+
# language=
|
| 57 |
+
# ### retranscribe in correct language to improve accuracy
|
| 58 |
+
# audio_file = open(audio_path, 'rb') # rb is read binary, used to open non-txt files like audio or images
|
| 59 |
+
# v2_transcript = openai.Audio.transcribe(
|
| 60 |
+
# file=audio_file,
|
| 61 |
+
# model="whisper-1",
|
| 62 |
+
# response_format='json',
|
| 63 |
+
# temperature=0.2
|
| 64 |
+
# language=language
|
| 65 |
+
# )
|
| 66 |
+
# ###
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
# save transcript
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# pass to teacher
|
ai_lang_teacher/FFU EP-1 Wonderland Journey into the Darkness.txt
ADDED
|
File without changes
|
ai_lang_teacher/Gurren Lagann - Giga Drill Break.txt
ADDED
|
File without changes
|
ai_lang_teacher/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# streamlit_hackathon
|
ai_lang_teacher/Teacher design.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# # Approach on how to design a lesson for a student (ChatGPT brainstorm session)
|
| 2 |
+
|
| 3 |
+
Teaching a language through submitted audio/video clips with a focus on pure immersion and minimal flashcard reliance is an innovative and effective approach, often referred to as "immersive learning." Here's a step-by-step guide on how to do it:
|
| 4 |
+
|
| 5 |
+
**Step 1: Choose the Target Language:**
|
| 6 |
+
- Start by selecting the target language you want to teach through immersion. Ensure that you have access to a variety of authentic audio and video clips in that language.
|
| 7 |
+
|
| 8 |
+
**Step 2: Build a Diverse Collection of Resources:**
|
| 9 |
+
- Gather a wide range of audio and video clips, including:
|
| 10 |
+
- Conversations between native speakers.
|
| 11 |
+
- News broadcasts, podcasts, or radio shows.
|
| 12 |
+
- Movies, TV shows, or YouTube videos.
|
| 13 |
+
- Songs and music in the target language.
|
| 14 |
+
- Interviews or documentaries.
|
| 15 |
+
|
| 16 |
+
**Step 3: Create Structured Learning Experiences:**
|
| 17 |
+
- Organize the immersion-based learning experience into structured modules or themes. For example:
|
| 18 |
+
- Beginner modules: Simple conversations, basic vocabulary.
|
| 19 |
+
- Intermediate modules: More complex conversations, culture, and context.
|
| 20 |
+
- Advanced modules: In-depth discussions, idiomatic expressions.
|
| 21 |
+
|
| 22 |
+
**Step 4: Provide Guided Prompts:**
|
| 23 |
+
- Alongside each audio or video clip, provide guided prompts or questions to encourage active listening and comprehension.
|
| 24 |
+
- For beginners, these prompts can be simple questions about the content.
|
| 25 |
+
- For advanced learners, prompts can be more open-ended, encouraging critical thinking and analysis.
|
| 26 |
+
|
| 27 |
+
**Step 5: Encourage Active Engagement:**
|
| 28 |
+
- Encourage learners to actively engage with the content by:
|
| 29 |
+
- Repeatedly listening to the clips to improve listening skills.
|
| 30 |
+
- Attempting to transcribe or summarize what they hear.
|
| 31 |
+
- Discussing the content with fellow learners or language partners.
|
| 32 |
+
- Creating their own responses or conversations based on what they've learned.
|
| 33 |
+
|
| 34 |
+
**Step 6: Foster Collaborative Learning:**
|
| 35 |
+
- Create a community or platform where learners can share their thoughts, questions, and experiences related to the language immersion.
|
| 36 |
+
- Encourage peer-to-peer learning, where learners can help each other with comprehension and pronunciation.
|
| 37 |
+
|
| 38 |
+
**Step 7: Track Progress and Set Goals:**
|
| 39 |
+
- Implement a system for tracking progress, possibly through regular assessments or self-assessment tools.
|
| 40 |
+
- Encourage learners to set achievable language learning goals.
|
| 41 |
+
|
| 42 |
+
**Step 8: Promote Cultural Understanding:**
|
| 43 |
+
- Use video clips that provide insights into the culture, customs, and traditions of the target language's speakers.
|
| 44 |
+
- Encourage learners to explore the cultural context in addition to language skills.
|
| 45 |
+
|
| 46 |
+
**Step 9: Adjust the Challenge Level:**
|
| 47 |
+
- Gradually increase the complexity of the clips and modules as learners progress.
|
| 48 |
+
- Provide access to more advanced content for those ready to tackle higher-level language skills.
|
| 49 |
+
|
| 50 |
+
**Step 10: Encourage Consistency:**
|
| 51 |
+
- Emphasize the importance of regular exposure and practice. Encourage learners to incorporate language learning into their daily routines.
|
| 52 |
+
|
| 53 |
+
**Step 11: Provide Feedback and Support:**
|
| 54 |
+
- Offer constructive feedback and support to learners who may have questions or need clarification.
|
| 55 |
+
|
| 56 |
+
**Step 12: Celebrate Achievements:**
|
| 57 |
+
- Celebrate milestones and achievements with learners to keep them motivated.
|
| 58 |
+
|
| 59 |
+
This immersion-based approach relies on learners actively engaging with authentic language content, promoting natural language acquisition and cultural understanding. It's a dynamic and effective way to teach a language without heavy reliance on flashcards or traditional classroom methods.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Creating a lesson based on the provided transcript for immersion learning involves using the content as a springboard to introduce and reinforce language concepts. Here's a structured lesson plan based on the transcript:
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Certainly! For a shorter lesson, we'll focus on introducing some key vocabulary and phrases from the transcript. This mini-lesson is designed to be completed in less than 15 minutes.
|
| 67 |
+
|
| 68 |
+
**Lesson Title: Learning Basic Japanese Phrases - Believe in Yourself**
|
| 69 |
+
|
| 70 |
+
**Objective:** By the end of this short lesson, learners will be able to understand and use basic phrases related to belief and encouragement in Japanese.
|
| 71 |
+
|
| 72 |
+
**Materials Needed:**
|
| 73 |
+
- The provided transcript with audio recording.
|
| 74 |
+
|
| 75 |
+
**Lesson Structure:**
|
| 76 |
+
|
| 77 |
+
**1. Introduction (2 minutes):**
|
| 78 |
+
- Greet the learners and briefly introduce the purpose of the lesson: to learn basic Japanese phrases related to belief and encouragement.
|
| 79 |
+
|
| 80 |
+
**2. Audio Listening (5 minutes):**
|
| 81 |
+
- Play the audio clip of the transcript once to allow learners to listen and get a feel for the pronunciation and intonation.
|
| 82 |
+
|
| 83 |
+
**3. Vocabulary Building (5 minutes):**
|
| 84 |
+
- Introduce and explain the following key phrases:
|
| 85 |
+
- γγγ (ii ka) - Listen or Pay attention.
|
| 86 |
+
- εΏγγγͺ (wasurenna) - Don't forget or Remember.
|
| 87 |
+
- γεγδΏ‘γγ (omae o shinjiro) - Believe in yourself or Have faith in yourself.
|
| 88 |
+
- Pronounce each phrase clearly and encourage learners to repeat after you.
|
| 89 |
+
|
| 90 |
+
**4. Practice (2 minutes):**
|
| 91 |
+
- Ask learners to repeat each phrase after you to practice pronunciation.
|
| 92 |
+
|
| 93 |
+
**5. Summary (1 minute):**
|
| 94 |
+
- Summarize what was learned in the lesson: the meanings and pronunciations of the three phrases.
|
| 95 |
+
|
| 96 |
+
**6. Closing Remarks (1 minute):**
|
| 97 |
+
- Encourage learners to continue practicing these phrases on their own and use them to encourage themselves and others.
|
| 98 |
+
|
| 99 |
+
**7. Homework (optional, 1 minute):**
|
| 100 |
+
- If desired, assign optional homework: Have learners find a friend or family member to share the phrases they've learned and encourage them in Japanese.
|
| 101 |
+
|
| 102 |
+
**8. Q&A (2 minutes, if time allows):**
|
| 103 |
+
- Open the floor for any questions learners may have.
|
| 104 |
+
|
| 105 |
+
This condensed lesson focuses primarily on vocabulary and pronunciation, making it suitable for a short, introductory session of less than 15 minutes. It provides learners with basic phrases they can use immediately for self-encouragement and simple interactions.
|
ai_lang_teacher/app-Copy1.py
ADDED
|
@@ -0,0 +1,489 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from streamlit import elements
|
| 4 |
+
import json
|
| 5 |
+
import uuid
|
| 6 |
+
import os
|
| 7 |
+
from pytube import YouTube
|
| 8 |
+
from moviepy.editor import VideoFileClip
|
| 9 |
+
import openai
|
| 10 |
+
from langchain.llms import OpenAI
|
| 11 |
+
from langchain.chat_models import ChatOpenAI
|
| 12 |
+
from langchain import PromptTemplate
|
| 13 |
+
from langchain.prompts import ChatPromptTemplate
|
| 14 |
+
import time
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
#############--------------- ID and Surveys ------------########################
|
| 19 |
+
# Generate unique user ID
|
| 20 |
+
def generate_unique_id():
|
| 21 |
+
return str(uuid.uuid4())
|
| 22 |
+
|
| 23 |
+
# Save survey answers to a file
|
| 24 |
+
def save_survey_answers(unique_id, answers):
|
| 25 |
+
with open('survey_answers.json', 'w') as f:
|
| 26 |
+
json.dump({unique_id: answers}, f)
|
| 27 |
+
# f.write('\n')
|
| 28 |
+
|
| 29 |
+
# Load all stored unique IDs
|
| 30 |
+
def load_unique_ids():
|
| 31 |
+
try:
|
| 32 |
+
with open('unique_ids.json', 'r') as f:
|
| 33 |
+
return json.load(f)
|
| 34 |
+
except FileNotFoundError:
|
| 35 |
+
return []
|
| 36 |
+
|
| 37 |
+
# Save a unique ID
|
| 38 |
+
def save_unique_id(unique_id):
|
| 39 |
+
ids = load_unique_ids()
|
| 40 |
+
ids.append(unique_id)
|
| 41 |
+
with open('unique_ids.json', 'w') as f:
|
| 42 |
+
json.dump(ids, f)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
#############--------------- Video transcription ------------########################
|
| 46 |
+
|
| 47 |
+
# Download video from URL
|
| 48 |
+
def download_video(url, output_directory='./downloads'):
|
| 49 |
+
try:
|
| 50 |
+
yt = YouTube(url)
|
| 51 |
+
video = yt.streams.get_highest_resolution()
|
| 52 |
+
if not os.path.exists(output_directory):
|
| 53 |
+
os.makedirs(output_directory)
|
| 54 |
+
video.download(output_path=output_directory)
|
| 55 |
+
return os.path.join(output_directory, video.default_filename), 'Video downloaded successfully.'
|
| 56 |
+
except Exception as e:
|
| 57 |
+
message = f'An error occurred: {e}'
|
| 58 |
+
return None, message
|
| 59 |
+
|
| 60 |
+
# Convert video to audio
|
| 61 |
+
def convert_to_audio(video_path, output_directory='./converted_audio'):
|
| 62 |
+
try:
|
| 63 |
+
video = VideoFileClip(video_path)
|
| 64 |
+
audio_filename = f"{os.path.basename(video_path).split('.')[0]}.wav"
|
| 65 |
+
audio_path = os.path.join(output_directory, audio_filename)
|
| 66 |
+
if not os.path.exists(output_directory):
|
| 67 |
+
os.makedirs(output_directory)
|
| 68 |
+
video.audio.write_audiofile(audio_path)
|
| 69 |
+
message = 'Audio converted successfully.'
|
| 70 |
+
return audio_path, message
|
| 71 |
+
except Exception as e:
|
| 72 |
+
message = f"An error occurred: {e}"
|
| 73 |
+
return None, message
|
| 74 |
+
|
| 75 |
+
# Transcribe audio
|
| 76 |
+
# Take WAV file from downloads and save to converted audio folder
|
| 77 |
+
import os
|
| 78 |
+
from dotenv import load_dotenv, find_dotenv
|
| 79 |
+
import openai
|
| 80 |
+
import eyed3
|
| 81 |
+
import pyaudio
|
| 82 |
+
import wave
|
| 83 |
+
import json
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
# Split long audio files into clips to be processed by Whisper API
|
| 88 |
+
def split_audio_pyaudio(audio_path, clip_duration_sec=30, overlap_duration_sec=3, output_folder='converted_audio/clips'):
|
| 89 |
+
clip_list = []
|
| 90 |
+
file_name = os.path.basename(audio_path)[:-4]
|
| 91 |
+
|
| 92 |
+
# Determine the total duration of the audio file
|
| 93 |
+
if audio_path.endswith('.mp3'):
|
| 94 |
+
audio_file = eyed3.load(audio_path)
|
| 95 |
+
total_duration = audio_file.info.time_secs
|
| 96 |
+
elif audio_path.endswith('.wav'):
|
| 97 |
+
with wave.open(audio_path, 'rb') as wf:
|
| 98 |
+
n_frames = wf.getnframes()
|
| 99 |
+
framerate = wf.getframerate()
|
| 100 |
+
total_duration = n_frames / framerate
|
| 101 |
+
else:
|
| 102 |
+
raise ValueError("Unsupported audio format")
|
| 103 |
+
|
| 104 |
+
if not os.path.exists(output_folder):
|
| 105 |
+
os.makedirs(output_folder)
|
| 106 |
+
|
| 107 |
+
CHUNK = 1024
|
| 108 |
+
FORMAT = pyaudio.paInt16
|
| 109 |
+
CHANNELS = 2
|
| 110 |
+
RATE = 44100
|
| 111 |
+
clip_duration_samples = clip_duration_sec * RATE
|
| 112 |
+
overlap_samples = overlap_duration_sec * RATE
|
| 113 |
+
|
| 114 |
+
wf = wave.open(audio_path, 'rb')
|
| 115 |
+
p = pyaudio.PyAudio()
|
| 116 |
+
|
| 117 |
+
clip_number = 1
|
| 118 |
+
for start_sample in range(0, int(total_duration * RATE), clip_duration_samples - overlap_samples):
|
| 119 |
+
frames = []
|
| 120 |
+
|
| 121 |
+
for i in range(0, int(RATE / CHUNK * clip_duration_sec)):
|
| 122 |
+
data = wf.readframes(CHUNK)
|
| 123 |
+
if not data:
|
| 124 |
+
break
|
| 125 |
+
frames.append(data)
|
| 126 |
+
|
| 127 |
+
clip_path = f"{output_folder}/{file_name}_clip_{clip_number}.wav"
|
| 128 |
+
wf_clip = wave.open(clip_path, 'wb')
|
| 129 |
+
wf_clip.setnchannels(CHANNELS)
|
| 130 |
+
wf_clip.setsampwidth(p.get_sample_size(FORMAT))
|
| 131 |
+
wf_clip.setframerate(RATE)
|
| 132 |
+
wf_clip.writeframes(b''.join(frames))
|
| 133 |
+
wf_clip.close()
|
| 134 |
+
|
| 135 |
+
clip_list.append(clip_path)
|
| 136 |
+
clip_number += 1
|
| 137 |
+
|
| 138 |
+
wf.close()
|
| 139 |
+
p.terminate()
|
| 140 |
+
|
| 141 |
+
return clip_list
|
| 142 |
+
|
| 143 |
+
# Takes WAV audio clips and transcribes them and saves them to JSON
|
| 144 |
+
def transcribe(audio_path):
|
| 145 |
+
clip_path_list = split_audio_pyaudio(audio_path)
|
| 146 |
+
file_name = os.path.basename(audio_path)[:-4]
|
| 147 |
+
transcribed_clips = []
|
| 148 |
+
# Ensure the transcript file is empty to start with
|
| 149 |
+
with open(f'{file_name}.txt', 'w') as txt_file:
|
| 150 |
+
pass
|
| 151 |
+
|
| 152 |
+
for clip in clip_path_list:
|
| 153 |
+
with wave.open(clip, 'rb') as wf:
|
| 154 |
+
n_frames = wf.getnframes()
|
| 155 |
+
framerate = wf.getframerate()
|
| 156 |
+
clip_duration = n_frames / framerate
|
| 157 |
+
|
| 158 |
+
if clip_duration < 0.1:
|
| 159 |
+
print(f"Skipping short clip (less than 0.1 sec): {clip}")
|
| 160 |
+
continue # Skip short clips
|
| 161 |
+
|
| 162 |
+
with open(clip, 'rb') as audio_file:
|
| 163 |
+
transcript = openai.Audio.transcribe(
|
| 164 |
+
file=audio_file,
|
| 165 |
+
model="whisper-1",
|
| 166 |
+
response_format='text',
|
| 167 |
+
temperature=0.0
|
| 168 |
+
)
|
| 169 |
+
transcribed_clips.append(transcript + '\n')
|
| 170 |
+
# with open(f'transcript/{file_name}.text', 'a') as txt_file:
|
| 171 |
+
# txt_file.write(transcript + '\n')
|
| 172 |
+
full_transcript_str = ''.join(transcribed_clips)
|
| 173 |
+
|
| 174 |
+
messages=[
|
| 175 |
+
{'role':'system', 'content':'''You are a robot that is specifically designed to figure out what language a transcript is in.
|
| 176 |
+
When given a transcript, ONLY return the ISO-639-1 language code. Take your time and think this through.'''},
|
| 177 |
+
{'role': 'user', 'content': 'je suis amΓ©ricain'},
|
| 178 |
+
{'role': 'assistant', 'content': 'fr'},
|
| 179 |
+
{'role': 'user', 'content': full_transcript_str}
|
| 180 |
+
]
|
| 181 |
+
|
| 182 |
+
response = openai.ChatCompletion.create(
|
| 183 |
+
model='gpt-3.5-turbo-0613',
|
| 184 |
+
messages=messages,
|
| 185 |
+
temperature=0
|
| 186 |
+
)
|
| 187 |
+
language = response['choices'][0]['message']['content']
|
| 188 |
+
|
| 189 |
+
transcript_json = {'title': os.path.basename(audio_path)[:-4], 'transcript': full_transcript_str, 'language' : language}
|
| 190 |
+
|
| 191 |
+
with open(f'transcript/{file_name}.json', 'w') as json_file:
|
| 192 |
+
json.dump(transcript_json, json_file, indent=4)
|
| 193 |
+
|
| 194 |
+
message = "Transcription process completed!"
|
| 195 |
+
return transcript_json, message
|
| 196 |
+
# def transcribe_audio(audio_path):
|
| 197 |
+
# try:
|
| 198 |
+
# # audio_file = open(audio_path, 'rb')
|
| 199 |
+
# # v1_transcript = openai.Audio.transcribe(
|
| 200 |
+
# # file=audio_file,
|
| 201 |
+
# # model="whisper-1",
|
| 202 |
+
# # response_format='json',
|
| 203 |
+
# # temperature=0.2
|
| 204 |
+
# # )
|
| 205 |
+
|
| 206 |
+
# # Detect language
|
| 207 |
+
# messages = [
|
| 208 |
+
# {'role': 'system', 'content': 'You are a robot that is specifically designed to figure out what language a transcript is in. When given a transcript, ONLY return the ISO-639-1 language code. Take your time and think this through.'},
|
| 209 |
+
# {'role': 'user', 'content': v1_transcript['text'][:100]}
|
| 210 |
+
# ]
|
| 211 |
+
# response = openai.ChatCompletion.create(
|
| 212 |
+
# model='gpt-3.5-turbo-0613',
|
| 213 |
+
# messages=messages,
|
| 214 |
+
# temperature=0
|
| 215 |
+
# )
|
| 216 |
+
# language = response['choices'][0]['message']['content']
|
| 217 |
+
# v1_transcript['language'] = language
|
| 218 |
+
|
| 219 |
+
# # Display in chat box
|
| 220 |
+
# message = "Transcription successful."
|
| 221 |
+
# return v1_transcript, message
|
| 222 |
+
# except Exception as e:
|
| 223 |
+
# message = f"An error occurred: {e}"
|
| 224 |
+
# return None, message
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
# Save the transcript
|
| 228 |
+
# def save_transcript(transcript, audio_path, output_directory='./transcripts'):
|
| 229 |
+
# try:
|
| 230 |
+
# transcript_filename = f"{os.path.basename(audio_path).split('.')[0]}"
|
| 231 |
+
# if not os.path.exists(output_directory):
|
| 232 |
+
# os.makedirs(output_directory)
|
| 233 |
+
# json_path = os.path.join(output_directory, f'{transcript_filename}.json')
|
| 234 |
+
# with open(json_path, 'w') as json_file:
|
| 235 |
+
# json.dump(transcript, json_file)
|
| 236 |
+
# message = 'Transcript saved successfully.'
|
| 237 |
+
# return json_path, message
|
| 238 |
+
# except Exception as e:
|
| 239 |
+
# message = f"An error occurred: {e}"
|
| 240 |
+
# return None, message
|
| 241 |
+
|
| 242 |
+
#############--------------- Teacher ------------########################
|
| 243 |
+
# Function to get plain English word for language code
|
| 244 |
+
def get_language_word(language, openai_api_key=''):
|
| 245 |
+
llm = OpenAI(model_name='gpt-3.5-turbo-0613', openai_api_key=openai_api_key, temperature=0)
|
| 246 |
+
template = '''Convert the ISO-639-1 language code into the plain english word for the language. ONLY return the english word for that language, nothing more.
|
| 247 |
+
Here is the language code: {language}
|
| 248 |
+
Take your time and think this through. Remember only respond with one word, the english word for the language.'''
|
| 249 |
+
prompt = PromptTemplate(
|
| 250 |
+
input_variables=['language'],
|
| 251 |
+
template=template,
|
| 252 |
+
)
|
| 253 |
+
final_prompt = prompt.format(language=language)
|
| 254 |
+
return llm(final_prompt)
|
| 255 |
+
|
| 256 |
+
# Function to create lesson outline
|
| 257 |
+
def create_lesson_outline(transcript_json, learning_goal='learn new languague', num_words='5', openai_api_key=''):
|
| 258 |
+
try:
|
| 259 |
+
with open('lesson_format.txt', 'r') as txt_file:
|
| 260 |
+
lesson_format = txt_file.read()
|
| 261 |
+
except FileNotFoundError:
|
| 262 |
+
return "Error: 'lesson_format.txt' not found. Please make sure it's in the current working directory."
|
| 263 |
+
|
| 264 |
+
chat = ChatOpenAI(temperature=0.2, model='gpt-3.5-turbo-0613', openai_api_key=openai_api_key)
|
| 265 |
+
template_string = '''Create a lesson based on this title ```{title}```, following this transcript ```{transcript_text}```, and following this format ```{lesson_format}```. Keep in mind the student's learning goal ```{learning_goal}``` and the number of words they want to learn```{num_words}```. For context you are making a lesson plan based on the title of an audio clip taken from a youtube video. Again the title of the video is {title}. Take this into account when making the title of the lesson plan and teaching the concept.
|
| 266 |
+
Only output the lesson plan, nothing more'''
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
prompt_template = ChatPromptTemplate.from_template(template_string)
|
| 270 |
+
messages = prompt_template.format_messages(
|
| 271 |
+
lesson_format=lesson_format,
|
| 272 |
+
transcript_text=transcript_json['transcript'],
|
| 273 |
+
title=transcript_json['title'],
|
| 274 |
+
learning_goal=learning_goal,
|
| 275 |
+
num_words=num_words
|
| 276 |
+
)
|
| 277 |
+
response = chat(messages)
|
| 278 |
+
message = 'Lesson outline created successfully.'
|
| 279 |
+
return response.content, message
|
| 280 |
+
|
| 281 |
+
#############--------------- Chat bot ------------########################
|
| 282 |
+
|
| 283 |
+
# Initialize the chatbox state
|
| 284 |
+
def initialize_chatbox():
|
| 285 |
+
if "messages" not in st.session_state:
|
| 286 |
+
st.session_state["messages"] = []
|
| 287 |
+
|
| 288 |
+
# Add a message to the chatbox
|
| 289 |
+
def add_to_chatbox(role, message):
|
| 290 |
+
st.session_state.messages.append({"role": role, "content": message})
|
| 291 |
+
|
| 292 |
+
if role == "user": # If the message is from the user
|
| 293 |
+
response = openai.ChatCompletion.create(
|
| 294 |
+
model="gpt-3.5-turbo-0613",
|
| 295 |
+
prompt=message,
|
| 296 |
+
max_tokens=150 # Limit the response to 150 tokens
|
| 297 |
+
)
|
| 298 |
+
teacher_response = response.choices[0] # Extract the bot's response text
|
| 299 |
+
st.session_state.messages.append({"role": "assistant", "content": teacher_response})
|
| 300 |
+
|
| 301 |
+
# Display the chatbox
|
| 302 |
+
def display_chatbox():
|
| 303 |
+
st.markdown("<div id='chatbox-container'>", unsafe_allow_html=True)
|
| 304 |
+
for msg in st.session_state.messages:
|
| 305 |
+
st.chat_message(msg["role"]).write(msg["content"])
|
| 306 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
############################## Main Streamlit app #################################
|
| 312 |
+
# Main function
|
| 313 |
+
def main():
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
# Initialize all session_state variables
|
| 317 |
+
for key, default_value in {
|
| 318 |
+
'access_granted': False,
|
| 319 |
+
'survey_done': False,
|
| 320 |
+
'unique_id': '',
|
| 321 |
+
'show_chat_window': False,
|
| 322 |
+
'video_url': '',
|
| 323 |
+
'chat_history': [],
|
| 324 |
+
'messages': [],
|
| 325 |
+
'transcribe_clicked': False,
|
| 326 |
+
}.items():
|
| 327 |
+
if key not in st.session_state:
|
| 328 |
+
st.session_state[key] = default_value
|
| 329 |
+
|
| 330 |
+
st.title('Language Learning AI Tutor')
|
| 331 |
+
st.text('Please wait a few mins after hitting the "Create Lesson" button')
|
| 332 |
+
|
| 333 |
+
# Access Control
|
| 334 |
+
# Check if the API key is already in the session state
|
| 335 |
+
if "api_key" not in st.session_state or not st.session_state.api_key:
|
| 336 |
+
# If the API key is not in the session state, display the input field
|
| 337 |
+
entered_api_key = st.text_input("Enter your API key:", type='password')
|
| 338 |
+
openai.api_key = entered_api_key
|
| 339 |
+
openai_api_key = entered_api_key
|
| 340 |
+
|
| 341 |
+
# Update the session state with the entered API key
|
| 342 |
+
if entered_api_key:
|
| 343 |
+
st.session_state.api_key = entered_api_key
|
| 344 |
+
else:
|
| 345 |
+
st.write("API key loaded successfully!")
|
| 346 |
+
# Load the API key:
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
if not st.session_state['access_granted']:
|
| 356 |
+
entered_id = st.text_input('Enter your unique ID to access the app:')
|
| 357 |
+
|
| 358 |
+
if st.button('Submit ID'):
|
| 359 |
+
unique_ids = load_unique_ids()
|
| 360 |
+
if entered_id in unique_ids:
|
| 361 |
+
st.session_state['access_granted'] = True
|
| 362 |
+
st.session_state['survey_done'] = True
|
| 363 |
+
st.session_state['unique_id'] = entered_id
|
| 364 |
+
st.success("Access granted.")
|
| 365 |
+
st.experimental_rerun()
|
| 366 |
+
else:
|
| 367 |
+
st.warning('Invalid ID. Access denied.')
|
| 368 |
+
|
| 369 |
+
if st.button('Generate New ID'):
|
| 370 |
+
new_id = generate_unique_id()
|
| 371 |
+
save_unique_id(new_id)
|
| 372 |
+
st.session_state['access_granted'] = True
|
| 373 |
+
st.session_state['unique_id'] = new_id
|
| 374 |
+
st.session_state['survey_done'] = False
|
| 375 |
+
st.success(f"New ID generated: {new_id}")
|
| 376 |
+
|
| 377 |
+
else:
|
| 378 |
+
if not st.session_state['survey_done']:
|
| 379 |
+
st.subheader('Survey Questions')
|
| 380 |
+
learning_goal = st.text_input("What's your daily learning goal?")
|
| 381 |
+
num_words = st.text_input('How many words do you want to learn?')
|
| 382 |
+
|
| 383 |
+
if st.button('Submit Survey'):
|
| 384 |
+
answers = {'learning_goal': learning_goal, 'num_words': num_words}
|
| 385 |
+
save_survey_answers(st.session_state['unique_id'], answers)
|
| 386 |
+
st.session_state['learning_goal'] = learning_goal
|
| 387 |
+
st.session_state['num_words'] = num_words
|
| 388 |
+
st.session_state['survey_done'] = True
|
| 389 |
+
st.success('Survey answers submitted!')
|
| 390 |
+
st.experimental_rerun()
|
| 391 |
+
|
| 392 |
+
# Sidebar for Video Upload
|
| 393 |
+
if st.session_state['access_granted'] and st.session_state['survey_done']:
|
| 394 |
+
with st.sidebar:
|
| 395 |
+
st.title('Video Upload')
|
| 396 |
+
video_url = st.text_input('Paste your YouTube video link here')
|
| 397 |
+
if st.button('Create Lesson'):
|
| 398 |
+
st.session_state.video_url = video_url
|
| 399 |
+
st.session_state.show_chat_window = True
|
| 400 |
+
st.session_state.transcribe_clicked = True
|
| 401 |
+
# st.sidebar.video(video_url)
|
| 402 |
+
# Save to session state that video should be displayed
|
| 403 |
+
st.session_state.display_video = True
|
| 404 |
+
|
| 405 |
+
# Check if video should be displayed in the sidebar
|
| 406 |
+
if 'display_video' in st.session_state and st.session_state.display_video:
|
| 407 |
+
st.sidebar.video(video_url)
|
| 408 |
+
|
| 409 |
+
# Clears state/screen
|
| 410 |
+
if st.button("Clear Messages"):
|
| 411 |
+
if 'messages' in st.session_state:
|
| 412 |
+
st.session_state['messages']=[]
|
| 413 |
+
|
| 414 |
+
# Main chat interface
|
| 415 |
+
if st.session_state.get('show_chat_window', False):
|
| 416 |
+
# Display previous chat messages
|
| 417 |
+
for message in st.session_state.messages:
|
| 418 |
+
with st.chat_message(message["role"]):
|
| 419 |
+
st.markdown(message["content"])
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
user_input = st.chat_input("begin lesson here and ask questions...")
|
| 424 |
+
if user_input:
|
| 425 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 426 |
+
|
| 427 |
+
# Ensure that st.session_state.messages is a list with the correct structure
|
| 428 |
+
if not isinstance(st.session_state.messages, list):
|
| 429 |
+
st.session_state.messages = []
|
| 430 |
+
|
| 431 |
+
response = openai.ChatCompletion.create(
|
| 432 |
+
model="gpt-3.5-turbo-0613",
|
| 433 |
+
messages=st.session_state.messages,
|
| 434 |
+
max_tokens=500 # Limit the response to 150 tokens
|
| 435 |
+
)
|
| 436 |
+
teacher_response = response.choices[0].message['content'].strip() # Extract the teacher's response text correctly
|
| 437 |
+
|
| 438 |
+
st.session_state.messages.append({"role": "assistant", "content": teacher_response})
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
# Perform transcription if Transcribe button is clicked
|
| 442 |
+
if st.session_state.get('transcribe_clicked', False):
|
| 443 |
+
st.session_state.transcribe_clicked = False
|
| 444 |
+
|
| 445 |
+
# Download video
|
| 446 |
+
video_path, video_message = download_video(st.session_state['video_url'])
|
| 447 |
+
st.session_state.messages.append({"role": "assistant", "content": video_message})
|
| 448 |
+
|
| 449 |
+
if video_path:
|
| 450 |
+
# Convert to audio
|
| 451 |
+
audio_path, audio_message = convert_to_audio(video_path)
|
| 452 |
+
st.session_state.messages.append({"role": "assistant", "content": audio_message})
|
| 453 |
+
|
| 454 |
+
if audio_path:
|
| 455 |
+
# Transcribe audio
|
| 456 |
+
transcript_data, transcript_message = transcribe(audio_path)
|
| 457 |
+
st.session_state.messages.append({"role": "assistant", "content": transcript_message})
|
| 458 |
+
|
| 459 |
+
# if transcript_data is not None:
|
| 460 |
+
# Detect language
|
| 461 |
+
language = get_language_word(transcript_data['language'])
|
| 462 |
+
st.session_state.messages.append({"role": "assistant", "content": f"Detected language is {language}"})
|
| 463 |
+
|
| 464 |
+
# Create lesson from transcript
|
| 465 |
+
lesson_content, lesson_message = create_lesson_outline(transcript_data)
|
| 466 |
+
st.session_state.messages.append({"role": "assistant", "content": "Here's the transcript and the lesson plan"})
|
| 467 |
+
st.session_state.messages.append({"role": "assistant", "content": '**Transcript: **' + transcript_data['transcript']})
|
| 468 |
+
st.session_state.messages.append({"role": "assistant", "content": '**Lesson plan: **' + lesson_content})
|
| 469 |
+
# st.session_state.messages.append({"role": "assistant", "content": lesson_content})
|
| 470 |
+
st.session_state.messages.append(
|
| 471 |
+
{"role": "system", "content": f'Follow the lesson plan as outlined: {lesson_content} and try your best not to deviate. Teach each word one at at time and explain in detail, including writing system or other relavent details for a firt time learner. Think this out step by step'})
|
| 472 |
+
# Temporary way to handle memory in the meantime
|
| 473 |
+
token_count = response['usage']['total_tokens']
|
| 474 |
+
if token_count >= 3000:
|
| 475 |
+
st.session_state.messages = []
|
| 476 |
+
print(st.session_state.messages)
|
| 477 |
+
st.experimental_rerun()
|
| 478 |
+
|
| 479 |
+
# Entry point
|
| 480 |
+
if __name__ == '__main__':
|
| 481 |
+
main()
|
| 482 |
+
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
|
ai_lang_teacher/app.py
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from streamlit import elements
|
| 4 |
+
import json
|
| 5 |
+
import uuid
|
| 6 |
+
import os
|
| 7 |
+
from pytube import YouTube
|
| 8 |
+
from moviepy.editor import VideoFileClip
|
| 9 |
+
import openai
|
| 10 |
+
from langchain.llms import OpenAI
|
| 11 |
+
from langchain.chat_models import ChatOpenAI
|
| 12 |
+
from langchain import PromptTemplate
|
| 13 |
+
from langchain.prompts import ChatPromptTemplate
|
| 14 |
+
import time
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
#############--------------- ID and Surveys ------------########################
|
| 19 |
+
# Generate unique user ID
|
| 20 |
+
def generate_unique_id():
|
| 21 |
+
return str(uuid.uuid4())
|
| 22 |
+
|
| 23 |
+
# Save survey answers to a file
|
| 24 |
+
def save_survey_answers(unique_id, answers):
|
| 25 |
+
with open('survey_answers.json', 'w') as f:
|
| 26 |
+
json.dump({unique_id: answers}, f)
|
| 27 |
+
# f.write('\n')
|
| 28 |
+
|
| 29 |
+
# Load all stored unique IDs
|
| 30 |
+
def load_unique_ids():
|
| 31 |
+
try:
|
| 32 |
+
with open('unique_ids.json', 'r') as f:
|
| 33 |
+
return json.load(f)
|
| 34 |
+
except FileNotFoundError:
|
| 35 |
+
return []
|
| 36 |
+
|
| 37 |
+
# Save a unique ID
|
| 38 |
+
def save_unique_id(unique_id):
|
| 39 |
+
ids = load_unique_ids()
|
| 40 |
+
ids.append(unique_id)
|
| 41 |
+
with open('unique_ids.json', 'w') as f:
|
| 42 |
+
json.dump(ids, f)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
#############--------------- Video transcription ------------########################
|
| 46 |
+
|
| 47 |
+
# Download video from URL
|
| 48 |
+
def download_video(url, output_directory='./downloads'):
|
| 49 |
+
try:
|
| 50 |
+
yt = YouTube(url)
|
| 51 |
+
video = yt.streams.get_highest_resolution()
|
| 52 |
+
if not os.path.exists(output_directory):
|
| 53 |
+
os.makedirs(output_directory)
|
| 54 |
+
video.download(output_path=output_directory)
|
| 55 |
+
return os.path.join(output_directory, video.default_filename), 'Video downloaded successfully.'
|
| 56 |
+
except Exception as e:
|
| 57 |
+
message = f'An error occurred: {e}'
|
| 58 |
+
return None, message
|
| 59 |
+
|
| 60 |
+
# Convert video to audio
|
| 61 |
+
def convert_to_audio(video_path, output_directory='./converted_audio'):
|
| 62 |
+
try:
|
| 63 |
+
video = VideoFileClip(video_path)
|
| 64 |
+
audio_filename = f"{os.path.basename(video_path).split('.')[0]}.wav"
|
| 65 |
+
audio_path = os.path.join(output_directory, audio_filename)
|
| 66 |
+
if not os.path.exists(output_directory):
|
| 67 |
+
os.makedirs(output_directory)
|
| 68 |
+
video.audio.write_audiofile(audio_path)
|
| 69 |
+
message = 'Audio converted successfully.'
|
| 70 |
+
return audio_path, message
|
| 71 |
+
except Exception as e:
|
| 72 |
+
message = f"An error occurred: {e}"
|
| 73 |
+
return None, message
|
| 74 |
+
|
| 75 |
+
# Transcribe audio
|
| 76 |
+
# Take WAV file from downloads and save to converted audio folder
|
| 77 |
+
import os
|
| 78 |
+
from dotenv import load_dotenv, find_dotenv
|
| 79 |
+
import openai
|
| 80 |
+
import eyed3
|
| 81 |
+
import pyaudio
|
| 82 |
+
import wave
|
| 83 |
+
import json
|
| 84 |
+
|
| 85 |
+
# Load API key from .env file
|
| 86 |
+
load_dotenv(find_dotenv())
|
| 87 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 88 |
+
|
| 89 |
+
# Split long audio files into clips to be processed by Whisper API
|
| 90 |
+
def split_audio_pyaudio(audio_path, clip_duration_sec=30, overlap_duration_sec=3, output_folder='converted_audio/clips'):
|
| 91 |
+
clip_list = []
|
| 92 |
+
file_name = os.path.basename(audio_path)[:-4]
|
| 93 |
+
|
| 94 |
+
# Determine the total duration of the audio file
|
| 95 |
+
if audio_path.endswith('.mp3'):
|
| 96 |
+
audio_file = eyed3.load(audio_path)
|
| 97 |
+
total_duration = audio_file.info.time_secs
|
| 98 |
+
elif audio_path.endswith('.wav'):
|
| 99 |
+
with wave.open(audio_path, 'rb') as wf:
|
| 100 |
+
n_frames = wf.getnframes()
|
| 101 |
+
framerate = wf.getframerate()
|
| 102 |
+
total_duration = n_frames / framerate
|
| 103 |
+
else:
|
| 104 |
+
raise ValueError("Unsupported audio format")
|
| 105 |
+
|
| 106 |
+
if not os.path.exists(output_folder):
|
| 107 |
+
os.makedirs(output_folder)
|
| 108 |
+
|
| 109 |
+
CHUNK = 1024
|
| 110 |
+
FORMAT = pyaudio.paInt16
|
| 111 |
+
CHANNELS = 2
|
| 112 |
+
RATE = 44100
|
| 113 |
+
clip_duration_samples = clip_duration_sec * RATE
|
| 114 |
+
overlap_samples = overlap_duration_sec * RATE
|
| 115 |
+
|
| 116 |
+
wf = wave.open(audio_path, 'rb')
|
| 117 |
+
p = pyaudio.PyAudio()
|
| 118 |
+
|
| 119 |
+
clip_number = 1
|
| 120 |
+
for start_sample in range(0, int(total_duration * RATE), clip_duration_samples - overlap_samples):
|
| 121 |
+
frames = []
|
| 122 |
+
|
| 123 |
+
for i in range(0, int(RATE / CHUNK * clip_duration_sec)):
|
| 124 |
+
data = wf.readframes(CHUNK)
|
| 125 |
+
if not data:
|
| 126 |
+
break
|
| 127 |
+
frames.append(data)
|
| 128 |
+
|
| 129 |
+
clip_path = f"{output_folder}/{file_name}_clip_{clip_number}.wav"
|
| 130 |
+
wf_clip = wave.open(clip_path, 'wb')
|
| 131 |
+
wf_clip.setnchannels(CHANNELS)
|
| 132 |
+
wf_clip.setsampwidth(p.get_sample_size(FORMAT))
|
| 133 |
+
wf_clip.setframerate(RATE)
|
| 134 |
+
wf_clip.writeframes(b''.join(frames))
|
| 135 |
+
wf_clip.close()
|
| 136 |
+
|
| 137 |
+
clip_list.append(clip_path)
|
| 138 |
+
clip_number += 1
|
| 139 |
+
|
| 140 |
+
wf.close()
|
| 141 |
+
p.terminate()
|
| 142 |
+
|
| 143 |
+
return clip_list
|
| 144 |
+
|
| 145 |
+
# Takes WAV audio clips and transcribes them and saves them to JSON
|
| 146 |
+
def transcribe(audio_path):
|
| 147 |
+
clip_path_list = split_audio_pyaudio(audio_path)
|
| 148 |
+
file_name = os.path.basename(audio_path)[:-4]
|
| 149 |
+
transcribed_clips = []
|
| 150 |
+
# Ensure the transcript file is empty to start with
|
| 151 |
+
with open(f'{file_name}.txt', 'w') as txt_file:
|
| 152 |
+
pass
|
| 153 |
+
|
| 154 |
+
for clip in clip_path_list:
|
| 155 |
+
with wave.open(clip, 'rb') as wf:
|
| 156 |
+
n_frames = wf.getnframes()
|
| 157 |
+
framerate = wf.getframerate()
|
| 158 |
+
clip_duration = n_frames / framerate
|
| 159 |
+
|
| 160 |
+
if clip_duration < 0.1:
|
| 161 |
+
print(f"Skipping short clip (less than 0.1 sec): {clip}")
|
| 162 |
+
continue # Skip short clips
|
| 163 |
+
|
| 164 |
+
with open(clip, 'rb') as audio_file:
|
| 165 |
+
transcript = openai.Audio.transcribe(
|
| 166 |
+
file=audio_file,
|
| 167 |
+
model="whisper-1",
|
| 168 |
+
response_format='text',
|
| 169 |
+
temperature=0.0
|
| 170 |
+
)
|
| 171 |
+
transcribed_clips.append(transcript + '\n')
|
| 172 |
+
# with open(f'transcript/{file_name}.text', 'a') as txt_file:
|
| 173 |
+
# txt_file.write(transcript + '\n')
|
| 174 |
+
full_transcript_str = ''.join(transcribed_clips)
|
| 175 |
+
|
| 176 |
+
messages=[
|
| 177 |
+
{'role':'system', 'content':'''You are a robot that is specifically designed to figure out what language a transcript is in.
|
| 178 |
+
When given a transcript, ONLY return the ISO-639-1 language code. Take your time and think this through.'''},
|
| 179 |
+
{'role': 'user', 'content': 'je suis amΓ©ricain'},
|
| 180 |
+
{'role': 'assistant', 'content': 'fr'},
|
| 181 |
+
{'role': 'user', 'content': full_transcript_str}
|
| 182 |
+
]
|
| 183 |
+
|
| 184 |
+
response = openai.ChatCompletion.create(
|
| 185 |
+
model='gpt-3.5-turbo-0613',
|
| 186 |
+
messages=messages,
|
| 187 |
+
temperature=0
|
| 188 |
+
)
|
| 189 |
+
language = response['choices'][0]['message']['content']
|
| 190 |
+
|
| 191 |
+
transcript_json = {'title': os.path.basename(audio_path)[:-4], 'transcript': full_transcript_str, 'language' : language}
|
| 192 |
+
|
| 193 |
+
with open(f'transcript/{file_name}.json', 'w') as json_file:
|
| 194 |
+
json.dump(transcript_json, json_file, indent=4)
|
| 195 |
+
|
| 196 |
+
message = "Transcription process completed!"
|
| 197 |
+
return transcript_json, message
|
| 198 |
+
# def transcribe_audio(audio_path):
|
| 199 |
+
# try:
|
| 200 |
+
# # audio_file = open(audio_path, 'rb')
|
| 201 |
+
# # v1_transcript = openai.Audio.transcribe(
|
| 202 |
+
# # file=audio_file,
|
| 203 |
+
# # model="whisper-1",
|
| 204 |
+
# # response_format='json',
|
| 205 |
+
# # temperature=0.2
|
| 206 |
+
# # )
|
| 207 |
+
|
| 208 |
+
# # Detect language
|
| 209 |
+
# messages = [
|
| 210 |
+
# {'role': 'system', 'content': 'You are a robot that is specifically designed to figure out what language a transcript is in. When given a transcript, ONLY return the ISO-639-1 language code. Take your time and think this through.'},
|
| 211 |
+
# {'role': 'user', 'content': v1_transcript['text'][:100]}
|
| 212 |
+
# ]
|
| 213 |
+
# response = openai.ChatCompletion.create(
|
| 214 |
+
# model='gpt-3.5-turbo-0613',
|
| 215 |
+
# messages=messages,
|
| 216 |
+
# temperature=0
|
| 217 |
+
# )
|
| 218 |
+
# language = response['choices'][0]['message']['content']
|
| 219 |
+
# v1_transcript['language'] = language
|
| 220 |
+
|
| 221 |
+
# # Display in chat box
|
| 222 |
+
# message = "Transcription successful."
|
| 223 |
+
# return v1_transcript, message
|
| 224 |
+
# except Exception as e:
|
| 225 |
+
# message = f"An error occurred: {e}"
|
| 226 |
+
# return None, message
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
# Save the transcript
|
| 230 |
+
# def save_transcript(transcript, audio_path, output_directory='./transcripts'):
|
| 231 |
+
# try:
|
| 232 |
+
# transcript_filename = f"{os.path.basename(audio_path).split('.')[0]}"
|
| 233 |
+
# if not os.path.exists(output_directory):
|
| 234 |
+
# os.makedirs(output_directory)
|
| 235 |
+
# json_path = os.path.join(output_directory, f'{transcript_filename}.json')
|
| 236 |
+
# with open(json_path, 'w') as json_file:
|
| 237 |
+
# json.dump(transcript, json_file)
|
| 238 |
+
# message = 'Transcript saved successfully.'
|
| 239 |
+
# return json_path, message
|
| 240 |
+
# except Exception as e:
|
| 241 |
+
# message = f"An error occurred: {e}"
|
| 242 |
+
# return None, message
|
| 243 |
+
|
| 244 |
+
#############--------------- Teacher ------------########################
|
| 245 |
+
# Function to get plain English word for language code
|
| 246 |
+
def get_language_word(language, openai_api_key=''):
|
| 247 |
+
llm = OpenAI(model_name='gpt-3.5-turbo-0613', openai_api_key=openai_api_key, temperature=0)
|
| 248 |
+
template = '''Convert the ISO-639-1 language code into the plain english word for the language. ONLY return the english word for that language, nothing more.
|
| 249 |
+
Here is the language code: {language}
|
| 250 |
+
Take your time and think this through. Remember only respond with one word, the english word for the language.'''
|
| 251 |
+
prompt = PromptTemplate(
|
| 252 |
+
input_variables=['language'],
|
| 253 |
+
template=template,
|
| 254 |
+
)
|
| 255 |
+
final_prompt = prompt.format(language=language)
|
| 256 |
+
return llm(final_prompt)
|
| 257 |
+
|
| 258 |
+
# Function to create lesson outline
|
| 259 |
+
def create_lesson_outline(transcript_json, learning_goal='learn new languague', num_words='5', openai_api_key=''):
|
| 260 |
+
try:
|
| 261 |
+
with open('lesson_format.txt', 'r') as txt_file:
|
| 262 |
+
lesson_format = txt_file.read()
|
| 263 |
+
except FileNotFoundError:
|
| 264 |
+
return "Error: 'lesson_format.txt' not found. Please make sure it's in the current working directory."
|
| 265 |
+
|
| 266 |
+
chat = ChatOpenAI(temperature=0.2, model='gpt-3.5-turbo-0613', openai_api_key=openai_api_key)
|
| 267 |
+
template_string = '''Create a lesson based on this title ```{title}```, following this transcript ```{transcript_text}```, and following this format ```{lesson_format}```. Keep in mind the student's learning goal ```{learning_goal}``` and the number of words they want to learn```{num_words}```. For context you are making a lesson plan based on the title of an audio clip taken from a youtube video. Again the title of the video is {title}. Take this into account when making the title of the lesson plan and teaching the concept.
|
| 268 |
+
Only output the lesson plan, nothing more'''
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
prompt_template = ChatPromptTemplate.from_template(template_string)
|
| 272 |
+
messages = prompt_template.format_messages(
|
| 273 |
+
lesson_format=lesson_format,
|
| 274 |
+
transcript_text=transcript_json['transcript'],
|
| 275 |
+
title=transcript_json['title'],
|
| 276 |
+
learning_goal=learning_goal,
|
| 277 |
+
num_words=num_words
|
| 278 |
+
)
|
| 279 |
+
response = chat(messages)
|
| 280 |
+
message = 'Lesson outline created successfully.'
|
| 281 |
+
return response.content, message
|
| 282 |
+
|
| 283 |
+
#############--------------- Chat bot ------------########################
|
| 284 |
+
|
| 285 |
+
# Initialize the chatbox state
|
| 286 |
+
def initialize_chatbox():
|
| 287 |
+
if "messages" not in st.session_state:
|
| 288 |
+
st.session_state["messages"] = []
|
| 289 |
+
|
| 290 |
+
# Add a message to the chatbox
|
| 291 |
+
def add_to_chatbox(role, message):
|
| 292 |
+
st.session_state.messages.append({"role": role, "content": message})
|
| 293 |
+
|
| 294 |
+
if role == "user": # If the message is from the user
|
| 295 |
+
response = openai.ChatCompletion.create(
|
| 296 |
+
model="gpt-3.5-turbo-0613",
|
| 297 |
+
prompt=message,
|
| 298 |
+
max_tokens=150 # Limit the response to 150 tokens
|
| 299 |
+
)
|
| 300 |
+
teacher_response = response.choices[0] # Extract the bot's response text
|
| 301 |
+
st.session_state.messages.append({"role": "assistant", "content": teacher_response})
|
| 302 |
+
|
| 303 |
+
# Display the chatbox
|
| 304 |
+
def display_chatbox():
|
| 305 |
+
st.markdown("<div id='chatbox-container'>", unsafe_allow_html=True)
|
| 306 |
+
for msg in st.session_state.messages:
|
| 307 |
+
st.chat_message(msg["role"]).write(msg["content"])
|
| 308 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
############################## Main Streamlit app #################################
|
| 314 |
+
# Main function
|
| 315 |
+
def main():
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
# Initialize all session_state variables
|
| 319 |
+
for key, default_value in {
|
| 320 |
+
'access_granted': False,
|
| 321 |
+
'survey_done': False,
|
| 322 |
+
'unique_id': '',
|
| 323 |
+
'show_chat_window': False,
|
| 324 |
+
'video_url': '',
|
| 325 |
+
'chat_history': [],
|
| 326 |
+
'messages': [],
|
| 327 |
+
'transcribe_clicked': False,
|
| 328 |
+
}.items():
|
| 329 |
+
if key not in st.session_state:
|
| 330 |
+
st.session_state[key] = default_value
|
| 331 |
+
|
| 332 |
+
st.title('Language Learning AI Tutor')
|
| 333 |
+
st.text('Please wait a few mins after hitting the "Create Lesson" button')
|
| 334 |
+
|
| 335 |
+
# Access Control
|
| 336 |
+
# Check if the API key is already in the session state
|
| 337 |
+
if "api_key" not in st.session_state or not st.session_state.api_key:
|
| 338 |
+
# If the API key is not in the session state, display the input field
|
| 339 |
+
entered_api_key = st.text_input("Enter your API key:", type='password')
|
| 340 |
+
openai.api_key = entered_api_key
|
| 341 |
+
openai_api_key = entered_api_key
|
| 342 |
+
|
| 343 |
+
# Update the session state with the entered API key
|
| 344 |
+
if entered_api_key:
|
| 345 |
+
st.session_state.api_key = entered_api_key
|
| 346 |
+
else:
|
| 347 |
+
st.write("API key loaded successfully!")
|
| 348 |
+
# Load the API key:
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
if not st.session_state['access_granted']:
|
| 358 |
+
entered_id = st.text_input('Enter your unique ID to access the app:')
|
| 359 |
+
|
| 360 |
+
if st.button('Submit ID'):
|
| 361 |
+
unique_ids = load_unique_ids()
|
| 362 |
+
if entered_id in unique_ids:
|
| 363 |
+
st.session_state['access_granted'] = True
|
| 364 |
+
st.session_state['survey_done'] = True
|
| 365 |
+
st.session_state['unique_id'] = entered_id
|
| 366 |
+
st.success("Access granted.")
|
| 367 |
+
st.experimental_rerun()
|
| 368 |
+
else:
|
| 369 |
+
st.warning('Invalid ID. Access denied.')
|
| 370 |
+
|
| 371 |
+
if st.button('Generate New ID'):
|
| 372 |
+
new_id = generate_unique_id()
|
| 373 |
+
save_unique_id(new_id)
|
| 374 |
+
st.session_state['access_granted'] = True
|
| 375 |
+
st.session_state['unique_id'] = new_id
|
| 376 |
+
st.session_state['survey_done'] = False
|
| 377 |
+
st.success(f"New ID generated: {new_id}")
|
| 378 |
+
|
| 379 |
+
else:
|
| 380 |
+
if not st.session_state['survey_done']:
|
| 381 |
+
st.subheader('Survey Questions')
|
| 382 |
+
learning_goal = st.text_input("What's your daily learning goal?")
|
| 383 |
+
num_words = st.text_input('How many words do you want to learn?')
|
| 384 |
+
|
| 385 |
+
if st.button('Submit Survey'):
|
| 386 |
+
answers = {'learning_goal': learning_goal, 'num_words': num_words}
|
| 387 |
+
save_survey_answers(st.session_state['unique_id'], answers)
|
| 388 |
+
st.session_state['learning_goal'] = learning_goal
|
| 389 |
+
st.session_state['num_words'] = num_words
|
| 390 |
+
st.session_state['survey_done'] = True
|
| 391 |
+
st.success('Survey answers submitted!')
|
| 392 |
+
st.experimental_rerun()
|
| 393 |
+
|
| 394 |
+
# Sidebar for Video Upload
|
| 395 |
+
if st.session_state['access_granted'] and st.session_state['survey_done']:
|
| 396 |
+
with st.sidebar:
|
| 397 |
+
st.title('Video Upload')
|
| 398 |
+
video_url = st.text_input('Paste your YouTube video link here')
|
| 399 |
+
if st.button('Create Lesson'):
|
| 400 |
+
st.session_state.video_url = video_url
|
| 401 |
+
st.session_state.show_chat_window = True
|
| 402 |
+
st.session_state.transcribe_clicked = True
|
| 403 |
+
# st.sidebar.video(video_url)
|
| 404 |
+
# Save to session state that video should be displayed
|
| 405 |
+
st.session_state.display_video = True
|
| 406 |
+
|
| 407 |
+
# Check if video should be displayed in the sidebar
|
| 408 |
+
if 'display_video' in st.session_state and st.session_state.display_video:
|
| 409 |
+
st.sidebar.video(video_url)
|
| 410 |
+
|
| 411 |
+
# Clears state/screen
|
| 412 |
+
if st.button("Clear Messages"):
|
| 413 |
+
if 'messages' in st.session_state:
|
| 414 |
+
st.session_state['messages']=[]
|
| 415 |
+
|
| 416 |
+
# Main chat interface
|
| 417 |
+
if st.session_state.get('show_chat_window', False):
|
| 418 |
+
# Display previous chat messages
|
| 419 |
+
for message in st.session_state.messages:
|
| 420 |
+
with st.chat_message(message["role"]):
|
| 421 |
+
st.markdown(message["content"])
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
user_input = st.chat_input("begin lesson here and ask questions...")
|
| 426 |
+
if user_input:
|
| 427 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 428 |
+
|
| 429 |
+
# Ensure that st.session_state.messages is a list with the correct structure
|
| 430 |
+
if not isinstance(st.session_state.messages, list):
|
| 431 |
+
st.session_state.messages = []
|
| 432 |
+
|
| 433 |
+
response = openai.ChatCompletion.create(
|
| 434 |
+
model="gpt-3.5-turbo-0613",
|
| 435 |
+
messages=st.session_state.messages,
|
| 436 |
+
max_tokens=500 # Limit the response to 150 tokens
|
| 437 |
+
)
|
| 438 |
+
teacher_response = response.choices[0].message['content'].strip() # Extract the teacher's response text correctly
|
| 439 |
+
st.session_state.messages.append({"role": "assistant", "content": teacher_response})
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
# Perform transcription if Transcribe button is clicked
|
| 443 |
+
if st.session_state.get('transcribe_clicked', False):
|
| 444 |
+
st.session_state.transcribe_clicked = False
|
| 445 |
+
|
| 446 |
+
# Download video
|
| 447 |
+
video_path, video_message = download_video(st.session_state['video_url'])
|
| 448 |
+
st.session_state.messages.append({"role": "assistant", "content": video_message})
|
| 449 |
+
|
| 450 |
+
if video_path:
|
| 451 |
+
# Convert to audio
|
| 452 |
+
audio_path, audio_message = convert_to_audio(video_path)
|
| 453 |
+
st.session_state.messages.append({"role": "assistant", "content": audio_message})
|
| 454 |
+
|
| 455 |
+
if audio_path:
|
| 456 |
+
# Transcribe audio
|
| 457 |
+
transcript_data, transcript_message = transcribe(audio_path)
|
| 458 |
+
st.session_state.messages.append({"role": "assistant", "content": transcript_message})
|
| 459 |
+
|
| 460 |
+
# if transcript_data is not None:
|
| 461 |
+
# Detect language
|
| 462 |
+
language = get_language_word(transcript_data['language'])
|
| 463 |
+
st.session_state.messages.append({"role": "assistant", "content": f"Detected language is {language}"})
|
| 464 |
+
|
| 465 |
+
# Create lesson from transcript
|
| 466 |
+
lesson_content, lesson_message = create_lesson_outline(transcript_data)
|
| 467 |
+
st.session_state.messages.append({"role": "assistant", "content": "Here's the transcript and the lesson plan"})
|
| 468 |
+
st.session_state.messages.append({"role": "assistant", "content": '**Transcript: **' + transcript_data['transcript']})
|
| 469 |
+
st.session_state.messages.append({"role": "assistant", "content": '**Lesson plan: **' + lesson_content})
|
| 470 |
+
# st.session_state.messages.append({"role": "assistant", "content": lesson_content})
|
| 471 |
+
st.session_state.messages.append(
|
| 472 |
+
{"role": "system", "content": f'Follow the lesson plan as outlined: {lesson_content} and try your best not to deviate. Teach each word one at at time and explain in detail, including writing system or other relavent details for a firt time learner. Think this out step by step'})
|
| 473 |
+
st.experimental_rerun()
|
| 474 |
+
|
| 475 |
+
# Entry point
|
| 476 |
+
if __name__ == '__main__':
|
| 477 |
+
main()
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
|
ai_lang_teacher/converted_audio/Birthday Party Mobile Suit Gundam Wing.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fb54526a51565aa33d3e66c823fc199787e69165bfc88e5c02fc78d3809ed1bb
|
| 3 |
+
size 14553078
|
ai_lang_teacher/converted_audio/Gurren Lagann - Giga Drill Break.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fb6ff234f1468f6f6ddfdab89463f3828011a4737231e0f8d098c5d2ddf3e75c
|
| 3 |
+
size 26710566
|
ai_lang_teacher/converted_audio/Kamina - Believe in me who believes in you.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a41560695c59cc756ee5a3f2340059a95b3b0322491533fa808df55f584a3c76
|
| 3 |
+
size 2196258
|
ai_lang_teacher/converted_audio/clips/Birthday Party Mobile Suit Gundam Wing_clip_1.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d231b3d2d5547a223330260f413601272e7fa205d91868cb4388ea02f2ff630d
|
| 3 |
+
size 5287980
|
ai_lang_teacher/converted_audio/clips/Birthday Party Mobile Suit Gundam Wing_clip_2.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0a42d0bb0adcd0be83a46801bf3461a1aa293c370161d87dcebd07a5d486d45d
|
| 3 |
+
size 5287980
|
ai_lang_teacher/converted_audio/clips/Birthday Party Mobile Suit Gundam Wing_clip_3.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b1742860891b2ba30ef3ba69423ab36328d93238cf190c3e5b9d57980430ca81
|
| 3 |
+
size 3977172
|
ai_lang_teacher/converted_audio/clips/Birthday Party Mobile Suit Gundam Wing_clip_4.wav
ADDED
|
Binary file (44 Bytes). View file
|
|
|
ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_1.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:37c2bdd3cc4c8852f2615087ef6fcbd6f176951e40ee70756c38aad5390e4e35
|
| 3 |
+
size 5287980
|
ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_2.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d47c6208307abaf9ddc343db32c1fbfe7fc5651aa92097577720e9b8fac3465b
|
| 3 |
+
size 5287980
|
ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_3.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:211e7f2d7120ac0ff002adc91880e24bca3e9f1317a3629b61449663978ff0be
|
| 3 |
+
size 5287980
|
ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_4.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:423e3685fc64e3e07d15235041985cd059813008ca6ad75388fecdac7462d0f9
|
| 3 |
+
size 5287980
|
ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_5.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a69b96ded1dd5c38d5ee85b4d955fceb787ad96d5920d5ee07f6ee797bd5b64
|
| 3 |
+
size 5287980
|
ai_lang_teacher/converted_audio/clips/Gurren Lagann - Giga Drill Break_clip_6.wav
ADDED
|
Binary file (271 kB). View file
|
|
|
ai_lang_teacher/downloads/Birthday Party Mobile Suit Gundam Wing.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c0b3712590ff8181b02a2c45a25766b270fedd09780e5085532062c6004008a6
|
| 3 |
+
size 11760440
|
ai_lang_teacher/downloads/Gurren Lagann - Giga Drill Break.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:115ebae9e3e5d478e4a1398efb3dd35067969264236c0c44449ae796bfbd5a5d
|
| 3 |
+
size 9474742
|
ai_lang_teacher/downloads/Kamina - Believe in me who believes in you.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a89ab1e38b071f6d70fb739faed0ffa42bc55cf4c8a91077a5aa6b4a005c3f3e
|
| 3 |
+
size 2385815
|
ai_lang_teacher/lesson_format.txt
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
**Lesson Title:** << create and insert a lesson title based on what the transcript is about >>
|
| 2 |
+
|
| 3 |
+
**Objective:** By the end of this lesson, learners will be able to understand << design a lesson that is based on the words in the transcript >>
|
| 4 |
+
|
| 5 |
+
**Lesson Structure:**
|
| 6 |
+
|
| 7 |
+
**1. Introduction (2 minutes):**
|
| 8 |
+
- Greet the learners and briefly introduce the purpose of the lesson: to learn basic Japanese phrases related << topic of the transcript>>.
|
| 9 |
+
|
| 10 |
+
**2. Audio Listening (5 minutes):**
|
| 11 |
+
- Ask the student (refer to their name) to play the audio clip of the transcript once to allow learners to listen and get a feel for the pronunciation and intonation.
|
| 12 |
+
|
| 13 |
+
**3. Vocabulary Building (5 minutes):**
|
| 14 |
+
- Introduce and explain the key phrases:
|
| 15 |
+
- Pronounce each phrase clearly and encourage learners to repeat after you.
|
| 16 |
+
|
| 17 |
+
**4. Practice (2 minutes):**
|
| 18 |
+
- Ask learners to repeat each phrase after you to practice pronunciation.
|
| 19 |
+
|
| 20 |
+
**5. Summary (1 minute):**
|
| 21 |
+
- Summarize what was learned in the lesson: the meanings and pronunciations of the three phrases.
|
| 22 |
+
|
| 23 |
+
**6. Closing Remarks (1 minute):**
|
| 24 |
+
- Encourage learners to continue practicing these phrases on their own and use them to encourage themselves and others.
|
| 25 |
+
|
| 26 |
+
**7. Homework (optional, 1 minute):**
|
| 27 |
+
- If desired, assign optional homework: Have learners find a friend or family member to share the phrases they've learned and encourage them in Japanese.
|
| 28 |
+
|
| 29 |
+
**8. Q&A:**
|
| 30 |
+
- Open the floor for any questions learners may have.
|
ai_lang_teacher/lesson_plan
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
**Lesson Title:** Building Confidence and Trust in Japanese
|
| 2 |
+
|
| 3 |
+
**Objective:** By the end of this lesson, learners will be able to understand and use basic Japanese phrases related to building confidence and trust in oneself and others.
|
| 4 |
+
|
| 5 |
+
**Lesson Structure:**
|
| 6 |
+
|
| 7 |
+
**1. Introduction (2 minutes):**
|
| 8 |
+
- Greet the learners and briefly introduce the purpose of the lesson: to learn basic Japanese phrases related to building confidence and trust.
|
| 9 |
+
|
| 10 |
+
**2. Audio Listening (5 minutes):**
|
| 11 |
+
- Ask the student (refer to their name) to play the audio clip of the transcript once to allow learners to listen and get a feel for the pronunciation and intonation.
|
| 12 |
+
|
| 13 |
+
**3. Vocabulary Building (5 minutes):**
|
| 14 |
+
- Introduce and explain the key phrases:
|
| 15 |
+
- γγγγ·γ’γ³ (ii ka shimon) - Listen up, Simon.
|
| 16 |
+
- εΏγγγͺ (wasurenna) - Don't forget.
|
| 17 |
+
- γεγδΏ‘γγ (omae o shinjiro) - Believe in yourself.
|
| 18 |
+
- δΏΊγδΏ‘γγγεγ§γγͺγ (ore ga shinjiru omae demo nai) - It's not about you believing in me.
|
| 19 |
+
- γεγδΏ‘γγδΏΊγ§γγͺγ (omae ga shinjiru ore demo nai) - It's not about me believing in you.
|
| 20 |
+
- γεγδΏ‘γγγεγδΏ‘γγ (omae ga shinjiru omae o shinjiro) - Believe in the version of yourself that you believe in.
|
| 21 |
+
- Pronounce each phrase clearly and encourage learners to repeat after you.
|
| 22 |
+
|
| 23 |
+
**4. Practice (2 minutes):**
|
| 24 |
+
- Ask learners to repeat each phrase after you to practice pronunciation.
|
| 25 |
+
|
| 26 |
+
**5. Summary (1 minute):**
|
| 27 |
+
- Summarize what was learned in the lesson: the meanings and pronunciations of the three phrases.
|
| 28 |
+
|
| 29 |
+
**6. Closing Remarks (1 minute):**
|
| 30 |
+
- Encourage learners to continue practicing these phrases on their own and use them to encourage themselves and others.
|
| 31 |
+
|
| 32 |
+
**7. Homework (optional, 1 minute):**
|
| 33 |
+
- If desired, assign optional homework: Have learners find a friend or family member to share the phrases they've learned and encourage them in Japanese.
|
| 34 |
+
|
| 35 |
+
**8. Q&A:**
|
| 36 |
+
- Open the floor for any questions learners may have.
|
ai_lang_teacher/survey_answers.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"0616fcd8-84b9-4149-8fe0-e7675821d223": {"learning_goal": "learn japanese", "num_words": "5"}}
|
ai_lang_teacher/teacher_script.txt
ADDED
|
File without changes
|
ai_lang_teacher/transcript/.ipynb_checkpoints/Kamina - Believe in me who believes in you-checkpoint.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"\u3044\u3044\u304b\u30b7\u30e2\u30f3\u3001\u5fd8\u308c\u3093\u306a \u304a\u524d\u3092\u4fe1\u3058\u308d \u4ffa\u304c\u4fe1\u3058\u308b\u304a\u524d\u3067\u3082\u306a\u3044 \u304a\u524d\u304c\u4fe1\u3058\u308b\u4ffa\u3067\u3082\u306a\u3044 \u304a\u524d\u304c\u4fe1\u3058\u308b \u304a\u524d\u3092\u4fe1\u3058\u308d"
|
ai_lang_teacher/transcript/.ipynb_checkpoints/Kamina - Believe in me who believes in you-checkpoint.vtt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
WEBVTT
|
| 2 |
+
|
| 3 |
+
00:00:00.000 --> 00:00:02.000
|
| 4 |
+
γγγγ·γ’γ³γεΏγγγͺ
|
| 5 |
+
|
| 6 |
+
00:00:02.000 --> 00:00:04.000
|
| 7 |
+
γεγδΏ‘γγ
|
| 8 |
+
|
| 9 |
+
00:00:04.000 --> 00:00:06.000
|
| 10 |
+
δΏΊγδΏ‘γγγεγ§γγͺγ
|
| 11 |
+
|
| 12 |
+
00:00:06.000 --> 00:00:08.000
|
| 13 |
+
γεγδΏ‘γγδΏΊγ§γγͺγ
|
| 14 |
+
|
| 15 |
+
00:00:08.000 --> 00:00:10.000
|
| 16 |
+
γεγδΏ‘γγ
|
| 17 |
+
|
| 18 |
+
00:00:10.000 --> 00:00:12.000
|
| 19 |
+
γεγδΏ‘γγ
|
| 20 |
+
|
ai_lang_teacher/transcript/.ipynb_checkpoints/Kobeni Goes Berserk Chainsaw Man-checkpoint.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"transcript": "\u3053\u306e\u5f8c\u3001\u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002 \u79c1\u306f\u5f7c\u3089\u3092\u8ffd\u3044\u304b\u3051\u307e\u3057\u305f\u3002\n\n\u3053\u306e\u5f8c\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\u3001\u6575\u306e\u653b\u6483\u3092\u6b62\u3081\u308b\u305f\u3081\u306b\n\nyou\n\n",
|
| 3 |
+
"language": "ja"
|
| 4 |
+
}
|
ai_lang_teacher/transcript/.ipynb_checkpoints/simple-checkpoint.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Alright, so here's the app idea. You make, so you take the transcript, you make a lesson plan. The lesson plan is simple. It just explains the words, explains the words, the structure of what's going on, and then it just creates flashcards, and then the next part is it creates flashcards and asks you to go practice. It gives you the flashcards.
|
| 2 |
+
|
| 3 |
+
Maybe that we create a way for you to look through and flip through the flashcards, or maybe it outputs an Anki file or something, some kind of file, some kind of Anki something. I think there's actually a Python Anki library. So it outputs an Anki file. Maybe I can have her work on that part. I'll put Anki.
|
| 4 |
+
|
| 5 |
+
file that that card can have the video segment of where the word or phrase came from and then maybe you can test what does it mean and how to how to even spell the words you can do Romaji and then maybe the hiragana katakana kanji
|
| 6 |
+
|
| 7 |
+
if you want to learn how to write it as well. And then the most important thing is accountability feature. So this is beyond what we submit to the Streamlit. This is more about how to create a community of learners and fans who are enthusiastic about this stuff. And they hold each other accountable. There's got to be some type of goal towards the end, maybe.
|
| 8 |
+
|
| 9 |
+
You guys are all gonna go on a trip somewhere. You guys are all gonna go to Japan or something, or you're all gonna go watch this movie. And you're gonna try and watch it without subtitles. I mean, you can connect it to events. You're gonna go to a concert. Hey, let's all learn the lyrics to this song so that when we go to the concert, we can all sing along, you know? Yeah, it can be something like that. Like, just connect it to fun events that are coming around.
|
| 10 |
+
|
| 11 |
+
And that just goes to the whole idea of what this application, this website, this social media community that I'm going to build, it's just about how to connect people. Yeah. How to connect people and make anime, Japanese media, a way to connect people. Yeah.
|
| 12 |
+
|
ai_lang_teacher/transcript/Birthday Party Mobile Suit Gundam Wing.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"title": "Birthday Party Mobile Suit Gundam Wing",
|
| 3 |
+
"transcript": "\u3042\u306e\u3001\u30ea\u30ea\u30fc\u30ca\u69d8 \u306f\u3044\u3001\u3053\u308c \u660e\u65e5\u3001\u79c1\u306e\u8a95\u751f\u65e5\u306a\u306e \u3082\u3061\u308d\u3093\u3001\u3044\u3089\u3057\u3066\u304f\u3060\u3055\u3044\u307e\u3059\u308f\u306d \u306f\u3044\u3001\u3053\u308c \u660e\u65e5\u3001\u79c1\u306e\u8a95\u751f\u65e5\u306a\u306e \u3082\u3061\u308d\u3093\u3001\u3044\u3089\u3057\u3066\u304f\u3060\u3055\u3044\u307e\u3059\u308f\u306d\n\n\u3048\u3063\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\u3048\ufffd\n\n\u4f55\u306a\u306e?\u3053\u306e\u4eba\n\n",
|
| 4 |
+
"language": "ja"
|
| 5 |
+
}
|
ai_lang_teacher/transcript/FFU EP-1 Wonderland Journey into the Darkness.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"title": "FFU EP-1 Wonderland Journey into the Darkness",
|
| 3 |
+
"transcript": "We're excited to have you here today. It's the first game for the Japanese. There are two of the best pick-list this year. Both of us...\n\nOh, God. The sensory seismic level is 2, but all of our observation measurements are showing a level 8. I can't believe this is happening. Would you look at that? It's crazy! It's just not right!\n\nMary, you shouldn't be out here in your condition. But Joe, this is the first phenomenon like this in all of history. I'm well aware of that, but... We've got to see it so we can write about it.\n\n\u7ad9\u4f4f\n\nI'm going to kill you, you son of a bitch!\n\n\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\u3067\u30dc\u30bf\u30f3PUSH\n\n\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\ufffd\n\n\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\u3042\ufffd\n\n\u591c\u660e\u3051 \u65c5\u7acb\u3064\u6642\u3092\u544a\u3052\u308b \u672a\u6765\u3092\u76ee\u6307\u3057 \u99c6\u3051\u3066\u3086\u304f\u98a8 \u3053\u306e\u8155\u306b\u5438\u3044\u8fbc\u3093\u3060\n\n\u5922\u3060\u3051\u3092\u523b\u307f\u3064\u3051\u305f\u77b3 \u50d5\u3089\u306b\u884c\u304f\u9053\u3092\u4e0e\u3048\u308b Love the Neverland \u9650\u308a\u306a\u3044 \u52c7\u6c17\u3092\u76ee\u899a\u3081\u3055\u305b\u3066\n\nGood Invited Guests, do come in. Welcome to the Night of Wonderland. I am Fabula. The Conjunction. Yes, twelve years ago, that was the day when the Pillar of the Darkness of Chaos first appeared. But now, a new journey. A new beginning.\n\nA wandering is about to begin. A wandering in a new place. Wonderland. Seems like even the tortoise can stop coming in such big numbers.\n\nIt's no wonder, because I heard another ship disappeared. See? I'm sure the pillar is somehow connected to Wonderland. And all the subway workers are constantly disappearing too, so... It's been closed for a while now, hasn't it? What if we don't end up being able to come back either? What do we do? We'll be fine. We know that Mom and Dad made it back at least once.\n\nSee anything we still got two or three minutes to go so hey sis aren't you even scared we're going to look for mom and dad you know there's no time to be scared right now well yeah I guess you're right\n\nIt's coming. I know it. It's really true. Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! Ah! \n\nWhat do we do, sis? It's dark. You think? Getting in? Of course! I mean, that's why we came here, right? Listen! That sounds like the departure bell! It must be getting ready to leave! Hurry!\n\n\u3042\u3042\u3042\u3042\u3042\u3042\u3042\n\nIt's just a normal subway train, but mom and dad took this train, didn't they? This is pacifist reporting. I am currently on- Someone else is here, you!\n\nWell, good evening. Don't play nicey with us. Who are you and how'd you get on? I... Watch your manners, sis. I'm real sorry, miss. It's fine. Who are you? A couple of ghosts that live on this train? You're the one who's a ghost here. Cut it out already, sis. Huh. We were hoping we were on the train to Wonderland now. You see, we're searching for our missing mom and dad. Wonderland? Yeah. They say that the pillar...\n\ndarkness is in some way connected to the magical world of Wonderland. At least that's what my dad wrote in his book here. Day of Conjunction, the book from Professor Hayakawa famous for research on the physics of Wonderland. They wrote in there that when they went to Wonderland they took a subway train. We checked it out online. We found out about a rumor that said you could get on the train at precisely 13 seconds past 1213 a.m. on a full moon night. I'm Yu Hayakawa and this\n\nover here is my older sister and I'm I he calls me his older sister but we're twins oh I'm Lisa so why are you on the subway well I don't know\n\nit looks like we've stopped it's about time mom and dad should be here somewhere it looks like we can climb up well let's get climbing that's why we came here isn't it well that's why we came here isn't it I think I see an exit up there hey miss are you also looking for someone\n\nwho's disappeared in Wonderland I'm sure it's her boyfriend huh you know you can call me Lisa if you want to hmm ah finally is this the place this it what is this place is it really wonderland\n\nlooks like a normal place to me except for the sky you guys try and stick close to me I have a bad feeling here this is just a regular slide just like any other\n\nWhat happened? I should have known better. This place isn't normal! It's Wonderland! Whee! Huh? Who's over there? Huh. Huh. Huh. Huh. Huh. Huh. Huh. Well hi there.\n\nthere hey look what I've got for you hold on it's all right here you go it's a joke a joke a joke a joke a chocolate for you excuse me what do you think you're doing with our food supply well\n\nAre you okay? Look at the pretty stars! Maybe that was one of those birds of happiness that live in Wonderland. See? Like in the book that mom and dad wrote. Mr. Birdie! Come back! Wait a minute, you! Mr. Birdie! Do you think you might have seen our parents? Well, where do you think he disappeared to?\n\nOh, oh, what? Hey! What happened? Look, there's someone stuck in there. Do you think he's dead? Ah! Where is this place?\n\nWe were gonna ask you the same thing too, mister. Did you just wander into Wonderland also? Wonderland? So, is that scoundrel here too? I don't know who you mean, but are you looking for someone too, scoundrel? Who are you anyway? I have forgotten my name and who I am.\n\nThat's not good. Huh? What is that thing? Some kind of flying machine. You think there's someone in it? I don't think so. I feel a real bad flow of energy from it. It can't be human. That can't be good. Everyone run!\n\nKeep running! A mushroom? It's looking at us!\n\nI think he's bad. Do you think he's going to attack now? Probably so. Just a minute. Just a minute.\n\noh wow that was incredible i knew there was something weird about you no that was only a little keegan hart's move i know just a small trick it's sort of kind of like a martial art keegan arts huh\n\nI'm doing your trick on that one! But I can't, he's too big! Better run. It's catching up with us! Try and find a place where you can hide! It's a glimpse!\n\nYou guys okay? Yeah, for now. Now this really doesn't look good. \n\nIt's that man from before. He survived that blast? Hey, help us! It has moved. Soil is my power.\n\nThe Magan has thawed. Magan? Magan? \n\nA soil charge triad to use on you has been decided. The origin of all things, Mother Black. A heat that will scorch all creation, Fire Red. And finally, the Red.\n\ncritical point of everything. Burning gold. What an amazing energy. Burn up! I summon you! Phoenix!\n\n\u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \u0905\u092a\u0930 \ufffd\n\n\u5feb\u8d70\n\nAmazing! He is Kaze! I am... Unlimited! Unlimited. Here is my prophecy. His name is Kaze. Amazing! He is Unlimited!\n\nA destroyer. A man with a single-minded mission. Those who withsword him will be defeated with the power of soil. Magan, Man of the Black Wind. Next time you'll have my unlimited guidance.\n\n",
|
| 4 |
+
"language": "en"
|
| 5 |
+
}
|
ai_lang_teacher/transcript/Kamina - Believe in me who believes in you.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"text": "\u3044\u3044\u304b\u30b7\u30e2\u30f3 \u5fd8\u308c\u3093\u306a \u304a\u524d\u3092\u4fe1\u3058\u308d \u4ffa\u304c\u4fe1\u3058\u308b\u304a\u524d\u3067\u3082\u306a\u3044 \u304a\u524d\u304c\u4fe1\u3058\u308b\u4ffa\u3067\u3082\u306a\u3044 \u304a\u524d\u304c\u4fe1\u3058\u308b\u304a\u524d\u3092\u4fe1\u3058\u308d", "language": "ja"}
|
ai_lang_teacher/transcript/Kamina - Believe in me who believes in you.vtt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
WEBVTT
|
| 2 |
+
|
| 3 |
+
00:00:00.000 --> 00:00:04.760
|
| 4 |
+
γγγγγ·γ’γ³γεΏγγγͺγγεγδΏ‘γγγ
|
| 5 |
+
|
| 6 |
+
00:00:04.760 --> 00:00:09.740
|
| 7 |
+
δΏΊγδΏ‘γγγεγ§γγͺγγγεγδΏ‘γγδΏΊγ§γγͺγγ
|
| 8 |
+
|
| 9 |
+
00:00:09.740 --> 00:00:12.320
|
| 10 |
+
γεγδΏ‘γγγγεγδΏ‘γγγ
|
| 11 |
+
|
ai_lang_teacher/transcript/Kobeni Goes Berserk Chainsaw Man.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"title": "Kobeni Goes Berserk Chainsaw Man",
|
| 3 |
+
"transcript": "\u6b21\u306e\u6226\u3044\u3078\u306e\u6e96\u5099\u3092\u3057\u306a\u3055\u3044\n\n\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\u3001\u4e00\u5fdc\n\nyou\n\n",
|
| 4 |
+
"language": "ja"
|
| 5 |
+
}
|
ai_lang_teacher/transcript/simple.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"transcript": "Alright, so here's the app idea. You make, so you take the transcript, you make a lesson plan. The lesson plan is simple. It just explains the words, explains the words, the structure of what's going on, and then it just creates flashcards, and then the next part is it creates flashcards and asks you to go practice. It gives you the flashcards.\n\nMaybe that we create a way for you to look through and flip through the flashcards, or maybe it outputs an Anki file or something, some kind of file, some kind of Anki something. I think there's actually a Python Anki library. So it outputs an Anki file. Maybe I can have her work on that part. I'll put Anki.\n\nfile that that card can have the video segment of where the word or phrase came from and then maybe you can test what does it mean and how to how to even spell the words you can do romaji and then maybe the hiragana katakana kanji\n\nif you want to learn how to write it as well. And then the most important thing is accountability feature. So this is beyond what we submit to the Streamlit. This is more about how to create a community of learners and fans who are enthusiastic about this stuff, and they hold each other accountable. There's got to be some type of goal towards the end, maybe. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there. And I think we're going to get there.\n\nYou guys are all gonna go on a trip somewhere. You guys are all gonna go to Japan or something, or you're all gonna go watch this movie, and you're gonna try and watch it without subtitles. I mean, you can connect it to events. You're gonna go to a concert. Hey, let's all learn the lyrics to this song so that when we go to the concert, we can all sing along, you know? Yeah, it can be something like that. Like, just connect it to fun events that are coming around.\n\nAnd that just goes to the whole idea of what this application, this website, this social media community that I'm going to build, it's just about how to connect people. Yeah, how to connect people and make anime, Japanese media, a way to connect people. Yeah.\n\n",
|
| 3 |
+
"language": "en"
|
| 4 |
+
}
|