Spaces:
Sleeping
Sleeping
Commit
ยท
e289f8d
1
Parent(s):
160c3d7
update: prompt and response refinement
Browse files- app.py +5 -6
- src/services/use_case_one/word_to_sentence.py +84 -68
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 |
-
("
|
|
|
|
| 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
|
| 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 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
-
|
| 45 |
-
-
|
| 46 |
-
-
|
| 47 |
-
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
-
|
| 60 |
-
-
|
| 61 |
-
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=
|
| 79 |
top_p=1,
|
| 80 |
stream=False
|
| 81 |
)
|
| 82 |
-
print(completion.choices[0].message.content)
|
| 83 |
|
| 84 |
-
|
| 85 |
-
return content
|
| 86 |
|
| 87 |
except Exception as e:
|
| 88 |
return {
|
|
@@ -90,18 +110,14 @@ class UseCaseOne:
|
|
| 90 |
"status": "failed"
|
| 91 |
}
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|