Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 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
|
| 20 |
f"{{\n"
|
| 21 |
-
f" \"title\": \"[
|
| 22 |
f" \"sections\": [\n"
|
| 23 |
f" {{\n"
|
| 24 |
-
f" \"subheading\": \"[A clear subheading
|
| 25 |
-
f" \"content\": \"[Detailed
|
| 26 |
f" }}\n"
|
| 27 |
f" ]\n"
|
| 28 |
f"}}\n\n"
|
| 29 |
f"### Important Guidelines:\n"
|
| 30 |
-
f"1. Return only
|
| 31 |
-
f"2.
|
| 32 |
-
f"3. Ensure
|
| 33 |
-
f"4.
|
| 34 |
-
f"5.
|
| 35 |
-
f"### Example Output:\n"
|
| 36 |
f"{{\n"
|
| 37 |
-
f" \"title\": \"Understanding
|
| 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
|
| 42 |
f" }},\n"
|
| 43 |
f" {{\n"
|
| 44 |
-
f" \"subheading\": \"The
|
| 45 |
-
f" \"content\": \"The
|
| 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
|