|
import gradio as gr |
|
from huggingface_hub import InferenceClient |
|
|
|
|
|
client = InferenceClient() |
|
|
|
|
|
def generate_stream(selected_topic, input_text): |
|
""" |
|
Generates a dynamic math lesson with LaTeX-rendered equations and explanations. |
|
""" |
|
prompt = ( |
|
f"Create a detailed lesson on solving the following system of equations using the elimination method: {input_text}. " |
|
"Include step-by-step explanations and render all equations in LaTeX format." |
|
if input_text.strip() |
|
else f"Create a beginner-level lesson for solving systems of equations with examples in LaTeX format." |
|
) |
|
messages = [{"role": "user", "content": prompt}] |
|
|
|
try: |
|
|
|
stream = client.chat.completions.create( |
|
model="Qwen/Qwen2.5-Coder-32B-Instruct", |
|
messages=messages, |
|
temperature=0.5, |
|
max_tokens=1024, |
|
top_p=0.7, |
|
stream=True, |
|
) |
|
|
|
|
|
generated_content = "" |
|
for chunk in stream: |
|
generated_content += chunk.choices[0].delta.content |
|
yield generated_content |
|
|
|
except Exception as e: |
|
yield f"Error: {e}" |
|
|
|
|
|
|
|
with gr.Blocks() as app: |
|
gr.Markdown("## π Solve Systems of Linear Equations with LaTeX") |
|
gr.Markdown( |
|
"Generate dynamic lessons on solving systems of equations step-by-step. " |
|
"The content includes explanations and LaTeX-rendered equations for better understanding!" |
|
) |
|
|
|
with gr.Row(): |
|
|
|
with gr.Column(): |
|
selected_topic = gr.Radio( |
|
choices=["Math"], |
|
label="Select a Topic", |
|
value="Math" |
|
) |
|
input_text = gr.Textbox( |
|
lines=2, |
|
label="Input Equations", |
|
placeholder="Enter the system of equations (e.g., '4x + 3y = 56, 7x + 6y = 54')" |
|
) |
|
generate_button = gr.Button("Generate Lesson") |
|
|
|
|
|
with gr.Column(): |
|
gr.Markdown("### Generated Content") |
|
output_stream = gr.Markdown() |
|
|
|
|
|
generate_button.click( |
|
fn=generate_stream, |
|
inputs=[selected_topic, input_text], |
|
outputs=output_stream, |
|
) |
|
|
|
|
|
app.launch() |
|
|