abhiimanyu commited on
Commit
64c0450
·
verified ·
1 Parent(s): 8908f31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -12,34 +12,35 @@ def format_prompt(topic, description, difficulty):
12
  f"You are an expert educator. Generate structured, highly engaging, and educational content on the topic '{topic}'. "
13
  f"Use the following description as context: '{description}'. "
14
  f"The content should be suitable for a '{difficulty}' difficulty level and MUST strictly follow this JSON structure:\n\n"
15
- f"{{\n"
16
  f" \"title\": \"[The title of the topic]\",\n"
17
  f" \"sections\": [\n"
18
- f" {{\n"
19
  f" \"subheading\": \"[A clear and concise subheading summarizing the section]\",\n"
20
  f" \"content\": \"[A detailed, engaging explanation of the section content, written in simple and accessible language.]\"\n"
21
- f" }}\n"
22
  f" ]\n"
23
- f"}}\n\n"
24
  f"### Strict Rules:\n"
25
  f"1. Output must be a **valid JSON object** and nothing else.\n"
26
  f"2. Do not include any additional text, comments, formatting instructions, or explanations.\n"
27
  f"3. Ensure proper syntax:\n"
28
  f" - All keys and string values must be enclosed in double quotes (\"\").\n"
29
  f" - No trailing commas.\n"
30
- f" - Properly close all braces (`}`) and brackets (`]`).\n"
31
  f"4. Validate the JSON before returning it to ensure it is syntactically correct and complete.\n"
32
  f"5. Do not include any extra characters, such as ◀, ▶, or ```.\n"
33
  f"6. If there is insufficient data to generate meaningful content, generate a placeholder JSON object with empty values, e.g.,\n"
34
- f"{{\n"
35
  f" \"title\": \"\",\n"
36
  f" \"sections\": []\n"
37
- f"}}\n"
38
  f"7. The response must always conform to this exact JSON structure, with no deviations."
39
  )
40
  return prompt
41
 
42
 
 
43
  # Function to clean and format the AI output
44
  def clean_and_format_learning_content(output):
45
  """
 
12
  f"You are an expert educator. Generate structured, highly engaging, and educational content on the topic '{topic}'. "
13
  f"Use the following description as context: '{description}'. "
14
  f"The content should be suitable for a '{difficulty}' difficulty level and MUST strictly follow this JSON structure:\n\n"
15
+ f"{{{{\n" # Escaped opening curly brace
16
  f" \"title\": \"[The title of the topic]\",\n"
17
  f" \"sections\": [\n"
18
+ f" {{{{\n" # Escaped opening curly brace
19
  f" \"subheading\": \"[A clear and concise subheading summarizing the section]\",\n"
20
  f" \"content\": \"[A detailed, engaging explanation of the section content, written in simple and accessible language.]\"\n"
21
+ f" }}}}\n" # Escaped closing curly brace
22
  f" ]\n"
23
+ f"}}}}\n\n" # Escaped closing curly brace
24
  f"### Strict Rules:\n"
25
  f"1. Output must be a **valid JSON object** and nothing else.\n"
26
  f"2. Do not include any additional text, comments, formatting instructions, or explanations.\n"
27
  f"3. Ensure proper syntax:\n"
28
  f" - All keys and string values must be enclosed in double quotes (\"\").\n"
29
  f" - No trailing commas.\n"
30
+ f" - Properly close all braces (`}}`) and brackets (`]]`).\n"
31
  f"4. Validate the JSON before returning it to ensure it is syntactically correct and complete.\n"
32
  f"5. Do not include any extra characters, such as ◀, ▶, or ```.\n"
33
  f"6. If there is insufficient data to generate meaningful content, generate a placeholder JSON object with empty values, e.g.,\n"
34
+ f"{{{{\n"
35
  f" \"title\": \"\",\n"
36
  f" \"sections\": []\n"
37
+ f"}}}}\n"
38
  f"7. The response must always conform to this exact JSON structure, with no deviations."
39
  )
40
  return prompt
41
 
42
 
43
+
44
  # Function to clean and format the AI output
45
  def clean_and_format_learning_content(output):
46
  """