Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ 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.
|
| 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"
|
|
@@ -22,31 +22,30 @@ def format_prompt(topic, description, difficulty):
|
|
| 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
|
| 26 |
f" }}\n"
|
| 27 |
f" ]\n"
|
| 28 |
f"}}\n\n"
|
| 29 |
f"### Important Guidelines:\n"
|
| 30 |
-
f"1.
|
| 31 |
-
f"2.
|
| 32 |
-
f"3.
|
| 33 |
-
f"4.
|
| 34 |
-
f"5.
|
| 35 |
-
f"6. Validate the JSON structure before returning it to ensure it is error-free and compliant with the format.\n"
|
| 36 |
f"### Example Output:\n"
|
| 37 |
f"{{\n"
|
| 38 |
f" \"title\": \"Understanding the Basics of Thermodynamics\",\n"
|
| 39 |
f" \"sections\": [\n"
|
| 40 |
f" {{\n"
|
| 41 |
f" \"subheading\": \"What is Thermodynamics?\",\n"
|
| 42 |
-
f" \"content\": \"Thermodynamics is the study of energy, heat, and how they
|
| 43 |
f" }},\n"
|
| 44 |
f" {{\n"
|
| 45 |
-
f" \"subheading\": \"The
|
| 46 |
-
f" \"content\": \"The
|
| 47 |
f" }}\n"
|
| 48 |
f" ]\n"
|
| 49 |
-
f"}}
|
| 50 |
)
|
| 51 |
return prompt
|
| 52 |
|
|
@@ -54,6 +53,7 @@ def format_prompt(topic, description, difficulty):
|
|
| 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 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"
|
|
|
|
| 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 |
|
|
|
|
| 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
|