abhiimanyu commited on
Commit
b7bdedd
·
verified ·
1 Parent(s): c2cc992

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -9,28 +9,36 @@ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
9
  # Function to format the input into a strict JSON-based prompt
10
  def format_prompt(topic, description, difficulty):
11
  prompt = (
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. The output **must be a valid JSON object**.\n"
26
- f"2. Do not include any comments, extra text, or trailing commas.\n"
27
- f"3. Ensure all brackets and braces are properly closed.\n"
28
- f"4. Validate the JSON before returning it to ensure it is correct and complete.\n"
 
 
 
 
 
 
 
29
  )
30
  return prompt
31
 
32
 
33
 
 
34
  # Function to clean and format the AI output
35
  def clean_and_format_learning_content(output):
36
  """
 
9
  # Function to format the input into a strict JSON-based prompt
10
  def format_prompt(topic, description, difficulty):
11
  prompt = (
12
+ f"You are an expert educator. Generate a structured, highly engaging, and educational JSON object on the topic '{topic}'. "
13
  f"Use the following description as context: '{description}'. "
14
+ f"The content must be suitable for a '{difficulty}' difficulty level and strictly adhere to the following JSON structure:\n\n"
15
  f"{{\n"
16
+ f" \"title\": \"[A descriptive and concise title for 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 clear, accessible language.]\"\n"
21
  f" }}\n"
22
  f" ]\n"
23
  f"}}\n\n"
24
+ f"### Strict Output Rules:\n"
25
+ f"1. The output **must be a valid JSON object** and nothing else.\n"
26
+ f"2. All keys and string values must be enclosed in double quotes (\"\").\n"
27
+ f"3. The `sections` field must be a non-empty list of objects, each containing `subheading` and `content`.\n"
28
+ f"4. Avoid extra characters, trailing commas, or malformed syntax.\n"
29
+ f"5. Close all brackets and braces properly.\n"
30
+ f"6. If there is insufficient information, return a JSON object with empty placeholders, e.g.,\n"
31
+ f"{{\n"
32
+ f" \"title\": \"\",\n"
33
+ f" \"sections\": []\n"
34
+ f"}}\n"
35
+ f"7. Validate the output to ensure it complies with the required JSON structure.\n"
36
  )
37
  return prompt
38
 
39
 
40
 
41
+
42
  # Function to clean and format the AI output
43
  def clean_and_format_learning_content(output):
44
  """