abhiimanyu commited on
Commit
1f217ac
·
verified ·
1 Parent(s): 2fb5642

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -20
app.py CHANGED
@@ -14,46 +14,40 @@ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
14
  # return prompt
15
  def format_prompt(topic, description, difficulty):
16
  prompt = (
17
- f"You are an expert educator. Generate highly engaging, educational, and structured content on the topic '{topic}'. "
18
  f"Use the following description as context: '{description}'. "
19
- f"The content should be suitable for a '{difficulty}' difficulty level and MUST strictly adhere to the following JSON structure:\n\n"
20
  f"{{\n"
21
- f" \"title\": \"[The title of the topic]\",\n"
22
  f" \"sections\": [\n"
23
  f" {{\n"
24
- f" \"subheading\": \"[A clear subheading summarizing the section]\",\n"
25
- f" \"content\": \"[Detailed explanation of the section content, written in simple and engaging language.]\"\n"
26
  f" }}\n"
27
  f" ]\n"
28
  f"}}\n\n"
29
  f"### Important Guidelines:\n"
30
- f"1. Return only a valid JSON object with no additional text, explanations, or symbols.\n"
31
- f"2. Do not include formatting like ```json or any other delimiters.\n"
32
- f"3. Ensure all keys and values are properly enclosed in double quotes.\n"
33
- f"4. Validate the JSON before returning it to ensure it is syntactically correct and complete.\n"
34
- f"5. Do not use any extra characters like ◀ or </s>.\n"
35
- f"### Example Output:\n"
36
  f"{{\n"
37
- f" \"title\": \"Understanding the Basics of Thermodynamics\",\n"
38
  f" \"sections\": [\n"
39
  f" {{\n"
40
  f" \"subheading\": \"What is Thermodynamics?\",\n"
41
- f" \"content\": \"Thermodynamics is the study of energy, heat, and how they interact. It explains phenomena like ice melting or engines running.\"\n"
42
  f" }},\n"
43
  f" {{\n"
44
- f" \"subheading\": \"The Four Laws of Thermodynamics\",\n"
45
- f" \"content\": \"The four laws govern how energy moves and changes. For example, the first law states that energy cannot be created or destroyed, only transformed.\"\n"
46
  f" }}\n"
47
  f" ]\n"
48
  f"}}"
49
  )
50
  return prompt
51
 
52
-
53
-
54
-
55
-
56
-
57
  # The function to generate learning content based on the inputs
58
  def generate_learning_content(topic, description, difficulty, temperature=0.9, max_new_tokens=2000, top_p=0.95, repetition_penalty=1.2):
59
  temperature = max(float(temperature), 1e-2) # Ensure minimum temperature
 
14
  # return prompt
15
  def format_prompt(topic, description, difficulty):
16
  prompt = (
17
+ f"You are an expert educator. Generate highly engaging, educational, and structured content for the topic '{topic}'. "
18
  f"Use the following description as context: '{description}'. "
19
+ f"The content should be suitable for a '{difficulty}' difficulty level and MUST strictly adhere to the following JSON format:\n\n"
20
  f"{{\n"
21
+ f" \"title\": \"[Title of the topic]\",\n"
22
  f" \"sections\": [\n"
23
  f" {{\n"
24
+ f" \"subheading\": \"[A clear subheading for the section]\",\n"
25
+ f" \"content\": \"[Detailed content explaining the subheading. Write in simple, engaging language suitable for young learners.]\"\n"
26
  f" }}\n"
27
  f" ]\n"
28
  f"}}\n\n"
29
  f"### Important Guidelines:\n"
30
+ f"1. Return only the JSON object and nothing else (no Markdown, code, or comments).\n"
31
+ f"2. Validate the JSON format. Ensure all fields are enclosed in double quotes, with no trailing commas or missing braces.\n"
32
+ f"3. Ensure the \"content\" field is fully completed without truncation.\n"
33
+ f"4. Do not include extraneous symbols, explanations, or artifacts (e.g., ◀, ```python).\n"
34
+ f"5. Example output:\n"
 
35
  f"{{\n"
36
+ f" \"title\": \"Understanding Thermodynamics\",\n"
37
  f" \"sections\": [\n"
38
  f" {{\n"
39
  f" \"subheading\": \"What is Thermodynamics?\",\n"
40
+ f" \"content\": \"Thermodynamics is the study of energy, heat, and how they work together. It explains everyday phenomena, like why ice melts in heat.\"\n"
41
  f" }},\n"
42
  f" {{\n"
43
+ f" \"subheading\": \"The First Law of Thermodynamics\",\n"
44
+ f" \"content\": \"The First Law states that energy cannot be created or destroyed. It can only change from one form to another, such as heat turning into motion.\"\n"
45
  f" }}\n"
46
  f" ]\n"
47
  f"}}"
48
  )
49
  return prompt
50
 
 
 
 
 
 
51
  # The function to generate learning content based on the inputs
52
  def generate_learning_content(topic, description, difficulty, temperature=0.9, max_new_tokens=2000, top_p=0.95, repetition_penalty=1.2):
53
  temperature = max(float(temperature), 1e-2) # Ensure minimum temperature