Update app.py
Browse files
app.py
CHANGED
@@ -305,8 +305,8 @@ def generate_math_solution_openrouter(api_key, problem_text, history=None):
|
|
305 |
# Add the current problem
|
306 |
messages.append({"role": "user", "content": f"Solve this math problem step-by-step: {problem_text}"})
|
307 |
|
308 |
-
# Create the completion
|
309 |
-
|
310 |
model="deepseek/deepseek-r1-0528:free",
|
311 |
messages=messages,
|
312 |
stream=True,
|
@@ -316,7 +316,13 @@ def generate_math_solution_openrouter(api_key, problem_text, history=None):
|
|
316 |
}
|
317 |
)
|
318 |
|
319 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
|
321 |
# Convert to HTML
|
322 |
html_solution = markdown_to_html(markdown_solution, problem_text)
|
@@ -413,14 +419,20 @@ def generate_math_solution_together(api_key, problem_text, image_path=None, hist
|
|
413 |
"content": user_message_content
|
414 |
})
|
415 |
|
416 |
-
# Create the completion
|
417 |
-
|
418 |
model="meta-llama/Llama-Vision-Free",
|
419 |
messages=messages,
|
420 |
stream=True
|
421 |
)
|
422 |
|
423 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
424 |
|
425 |
# Convert to HTML
|
426 |
problem_display = problem_text if problem_text.strip() else "Image-based problem"
|
@@ -432,7 +444,7 @@ def generate_math_solution_together(api_key, problem_text, image_path=None, hist
|
|
432 |
# Convert to PDF
|
433 |
pdf_file_path = html_to_pdf(html_solution, "together_solution")
|
434 |
|
435 |
-
# Update history
|
436 |
if history is None:
|
437 |
history = []
|
438 |
history.append((problem_display, markdown_solution))
|
|
|
305 |
# Add the current problem
|
306 |
messages.append({"role": "user", "content": f"Solve this math problem step-by-step: {problem_text}"})
|
307 |
|
308 |
+
# Create the completion with streaming
|
309 |
+
stream = client.chat.completions.create(
|
310 |
model="deepseek/deepseek-r1-0528:free",
|
311 |
messages=messages,
|
312 |
stream=True,
|
|
|
316 |
}
|
317 |
)
|
318 |
|
319 |
+
# Collect streamed content
|
320 |
+
markdown_solution = ""
|
321 |
+
for chunk in stream:
|
322 |
+
if hasattr(chunk, 'choices') and chunk.choices:
|
323 |
+
delta = chunk.choices[0].delta
|
324 |
+
if hasattr(delta, 'content') and delta.content:
|
325 |
+
markdown_solution += delta.content
|
326 |
|
327 |
# Convert to HTML
|
328 |
html_solution = markdown_to_html(markdown_solution, problem_text)
|
|
|
419 |
"content": user_message_content
|
420 |
})
|
421 |
|
422 |
+
# Create the completion with streaming
|
423 |
+
stream = client.chat.completions.create(
|
424 |
model="meta-llama/Llama-Vision-Free",
|
425 |
messages=messages,
|
426 |
stream=True
|
427 |
)
|
428 |
|
429 |
+
# Collect streamed content
|
430 |
+
markdown_solution = ""
|
431 |
+
for chunk in stream:
|
432 |
+
if hasattr(chunk, 'choices') and chunk.choices:
|
433 |
+
delta = chunk.choices[0].delta
|
434 |
+
if hasattr(delta, 'content') and delta.content:
|
435 |
+
markdown_solution += delta.content
|
436 |
|
437 |
# Convert to HTML
|
438 |
problem_display = problem_text if problem_text.strip() else "Image-based problem"
|
|
|
444 |
# Convert to PDF
|
445 |
pdf_file_path = html_to_pdf(html_solution, "together_solution")
|
446 |
|
447 |
+
# Update history
|
448 |
if history is None:
|
449 |
history = []
|
450 |
history.append((problem_display, markdown_solution))
|