ishworrsubedii commited on
Commit
e289f8d
ยท
1 Parent(s): 160c3d7

update: prompt and response refinement

Browse files
app.py CHANGED
@@ -1,12 +1,10 @@
1
  import streamlit as st
2
 
3
  from src.pipeline.main import LearnableAI
4
- import streamlit as st
5
- from src.pipeline.main import LearnableAI
6
 
7
 
8
  def main():
9
- st.title("LearnableAI Interface")
10
 
11
  learnable_ai = LearnableAI()
12
 
@@ -14,14 +12,15 @@ def main():
14
  interest = st.text_input("Enter your interest:", "")
15
  difficulty = st.selectbox(
16
  "Select difficulty level:",
17
- ("very simple", "simple", "hard", "very hard")
 
18
  )
19
 
20
  if st.button("Process with LearnableAI"):
21
  if words and interest: # Only show warning if fields are empty
22
  try:
23
  result = learnable_ai.word_to_sentence(
24
- words=list(words),
25
  interest=interest,
26
  difficulties=difficulty
27
  )
@@ -36,4 +35,4 @@ def main():
36
 
37
 
38
  if __name__ == "__main__":
39
- main()
 
1
  import streamlit as st
2
 
3
  from src.pipeline.main import LearnableAI
 
 
4
 
5
 
6
  def main():
7
+ st.title("LearnableAI Interface(Use Case 1)")
8
 
9
  learnable_ai = LearnableAI()
10
 
 
12
  interest = st.text_input("Enter your interest:", "")
13
  difficulty = st.selectbox(
14
  "Select difficulty level:",
15
+ ("Beginner", "Easy", "Challenging", "Expert",
16
+ "Starter", "Basic", "Tough", "Master")
17
  )
18
 
19
  if st.button("Process with LearnableAI"):
20
  if words and interest: # Only show warning if fields are empty
21
  try:
22
  result = learnable_ai.word_to_sentence(
23
+ words=list(words.split(",")),
24
  interest=interest,
25
  difficulties=difficulty
26
  )
 
35
 
36
 
37
  if __name__ == "__main__":
38
+ main()
src/services/use_case_one/word_to_sentence.py CHANGED
@@ -3,9 +3,11 @@ project @ LearnableAI
3
  created @ 2025-01-16
4
  author @ github.com/ishworrsubedii
5
  """
6
- import json
7
  from typing import List, Dict
8
 
 
 
9
 
10
  class UseCaseOne:
11
  def __init__(self, client):
@@ -13,54 +15,74 @@ class UseCaseOne:
13
 
14
  def generate_educational_content(self, interest: str, difficulties: str, words: List[str]) -> Dict:
15
  prompt = f"""
16
- As an educational content specialist for children with ADHD, create engaging learning material that adapts to different difficulty levels.
17
-
18
- Interest area: {interest}
19
- Difficulty level: {difficulties} (simple/hard)
20
- Words to use: {', '.join(words)}
21
-
22
- Please provide the following in a JSON format:
23
- {{
24
- "sentences": {{
25
- "{difficulties}": [
26
- "Three very simple sentences using the provided words, focused on basic understanding",
27
- "Each sentence should be short and use straightforward language",
28
- "Connect each sentence to the interest area"
29
- ],
30
- }},
31
- "learning_objectives": [
32
- "Three clear objectives that match the chosen difficulty level",
33
- "Focus on word usage and comprehension",
34
- "Include measurable outcomes"
35
- ],
36
- "activities": [
37
- "Two interactive activities that maintain attention",
38
- "Activities should match the difficulty level",
39
- "Include clear instructions"
40
- ]
41
- }}
42
-
43
- Ensure all content is:
44
- - Clear and direct
45
- - Highly visual and descriptive
46
- - Strongly connected to the interest area
47
- - Appropriate for the chosen difficulty level
48
- - ADHD-friendly (engaging, focused, and interactive)
49
- - Uses concrete examples and real-world connections
50
-
51
- For simple difficulty:
52
- - Use basic sentence structures
53
- - Limit to 5-7 words per sentence
54
- - Focus on direct cause and effect
55
- - Use familiar contexts
56
-
57
- For hard difficulty:
58
- - Use compound sentences
59
- - Include 8-12 words per sentence
60
- - Add descriptive details
61
- - Introduce new contexts within the interest area
62
-
63
- Return ONLY a valid JSON object with the structure shown above. Do not include any additional text or explanations.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  """
65
 
66
  try:
@@ -75,14 +97,12 @@ class UseCaseOne:
75
  }],
76
  model="mixtral-8x7b-32768",
77
  temperature=1.0, # if increase temperature, it will generate more creative content
78
- max_tokens=1000,
79
  top_p=1,
80
  stream=False
81
  )
82
- print(completion.choices[0].message.content)
83
 
84
- content = json.loads(completion.choices[0].message.content)
85
- return content
86
 
87
  except Exception as e:
88
  return {
@@ -90,18 +110,14 @@ class UseCaseOne:
90
  "status": "failed"
91
  }
92
 
93
- def format_response(self, content: Dict) -> Dict:
94
- return {
95
- "educational_content": {
96
- "sentences": content.get("sentences", []),
97
- "image_prompts": content.get("image_prompts", []),
98
- "learning_objectives": content.get("learning_objectives", []),
99
- "difficulty_level": content.get("difficulty_level", ""),
100
- "activities": content.get("attention_maintaining_activities", [])
101
- },
102
- "metadata": {
103
- "status": "success",
104
- "model": "mixtral-8x7b-32768",
105
- "version": "1.0"
106
- }
107
- }
 
3
  created @ 2025-01-16
4
  author @ github.com/ishworrsubedii
5
  """
6
+ import os
7
  from typing import List, Dict
8
 
9
+ from groq import Groq
10
+
11
 
12
  class UseCaseOne:
13
  def __init__(self, client):
 
15
 
16
  def generate_educational_content(self, interest: str, difficulties: str, words: List[str]) -> Dict:
17
  prompt = f"""
18
+ # ๐ŸŽฏ Learning Content Generator
19
+
20
+ ## ๐Ÿ“ Input Parameters
21
+ - **Interest Area:** {interest}
22
+ - **Target Words:** {', '.join(words)}
23
+ - **Difficulty Level:** {difficulties}
24
+
25
+ ## โœจ Content Requirements
26
+
27
+ ### 1. ๐Ÿ“– Creative Sentences
28
+ - Must use target words naturally
29
+ - Must relate to {interest}
30
+ - Must match {difficulties} difficulty level
31
+ - Should be engaging and educational
32
+
33
+ ### 2. ๐Ÿค” Quiz Questions
34
+ - Must test word understanding
35
+ - Must be multiple choice
36
+ - Must have clear correct answers
37
+ - Must relate to {interest}
38
+
39
+ ### 3. ๐ŸŽจ Image Generation Prompt
40
+ - Must incorporate target words
41
+ - Must be detailed for AI generation
42
+ - Must be creative and engaging
43
+ - Must relate to {interest}
44
+
45
+ ### 4. ๐ŸŽฎ Activities
46
+ - Must be simple and engaging
47
+ - Must reinforce target words
48
+ - Must match {difficulties} level
49
+ - Must relate to {interest}
50
+
51
+ ## ๐ŸŽ Output Format
52
+
53
+ ### ๐Ÿ“š Sentences
54
+ 1. [First creative sentence]
55
+ 2. [Second creative sentence]
56
+ 3. [Third creative sentence]
57
+
58
+ ### โ“ Quiz
59
+ **Question 1**
60
+ [Question text]
61
+ - A) [Option]
62
+ - B) [Option]
63
+ - C) [Option]
64
+ - D) [Option]
65
+
66
+ *Correct Answer: [A/B/C/D]*
67
+
68
+ **Question 2**
69
+ [Question text]
70
+ - A) [Option]
71
+ - B) [Option]
72
+ - C) [Option]
73
+ - D) [Option]
74
+
75
+ *Correct Answer: [A/B/C/D]*
76
+
77
+ ### ๐ŸŽฏ Activities
78
+ 1. [Detailed description of first activity]
79
+ 2. [Detailed description of second activity]
80
+
81
+ ### ๐Ÿ–ผ๏ธ Image Generation Prompt
82
+ [Detailed scene description incorporating target words]
83
+
84
+ ---
85
+ *Note: All content should be accessible and engaging for children with learning difficulties.* โœจ
86
  """
87
 
88
  try:
 
97
  }],
98
  model="mixtral-8x7b-32768",
99
  temperature=1.0, # if increase temperature, it will generate more creative content
100
+ max_tokens=2000,
101
  top_p=1,
102
  stream=False
103
  )
 
104
 
105
+ return completion.choices[0].message.content
 
106
 
107
  except Exception as e:
108
  return {
 
110
  "status": "failed"
111
  }
112
 
113
+
114
+ if __name__ == '__main__':
115
+ client = Groq(api_key=os.getenv
116
+ ('GROQ_API_KEY'))
117
+ use_case_one = UseCaseOne(client=client)
118
+ result = use_case_one.generate_educational_content(
119
+ interest="spiderman",
120
+ difficulties="simple",
121
+ words=["apple", "banana", "orange"]
122
+ )
123
+ print(result)