Moving from matplotlib to pillow for score
parent
f43c296e8a
commit
e703662d9e
|
|
@ -103,6 +103,8 @@ import io
|
||||||
import shutil
|
import shutil
|
||||||
from pdf2image import convert_from_path
|
from pdf2image import convert_from_path
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
import matplotlib
|
||||||
|
matplotlib.use('Agg') # Force headless rendering
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
# plt.rcParams.update({ "text.usetex": True,
|
# plt.rcParams.update({ "text.usetex": True,
|
||||||
|
|
@ -302,8 +304,6 @@ def color(score):
|
||||||
def render_score_text(label, score, error, width_px, fontsize=18,
|
def render_score_text(label, score, error, width_px, fontsize=18,
|
||||||
bg_color=(255, 255, 255, 255),
|
bg_color=(255, 255, 255, 255),
|
||||||
with_error=True, id=None):
|
with_error=True, id=None):
|
||||||
# 1. Calculate Color Gradient
|
|
||||||
|
|
||||||
# 2. Build highlight-text String & Properties
|
# 2. Build highlight-text String & Properties
|
||||||
# Wrap colored parts in < >
|
# Wrap colored parts in < >
|
||||||
score_str = f"{label} Note : <{score}>"
|
score_str = f"{label} Note : <{score}>"
|
||||||
|
|
@ -321,8 +321,6 @@ def render_score_text(label, score, error, width_px, fontsize=18,
|
||||||
fig_width = width_px / dpi
|
fig_width = width_px / dpi
|
||||||
chars_per_line = int(fig_width * 10)
|
chars_per_line = int(fig_width * 10)
|
||||||
|
|
||||||
# wrapped_text = textwrap.fill(score_str, width=chars_per_line)
|
|
||||||
|
|
||||||
# fig_height = 0.4 + 0.2
|
# fig_height = 0.4 + 0.2
|
||||||
fig_height = 0.8
|
fig_height = 0.8
|
||||||
|
|
||||||
|
|
@ -561,6 +559,7 @@ def process_student(student_id, labels_data, root_dir, all_labels, overwrite):
|
||||||
|
|
||||||
|
|
||||||
def process_correction(root_dir, data, all_labels, overwrite=False):
|
def process_correction(root_dir, data, all_labels, overwrite=False):
|
||||||
|
|
||||||
# with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
# with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
||||||
# # Create a list of futures
|
# # Create a list of futures
|
||||||
# futures = []
|
# futures = []
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ def render_item(item):
|
||||||
student_id, label, content = item
|
student_id, label, content = item
|
||||||
pdf_path = content['pdf_path']
|
pdf_path = content['pdf_path']
|
||||||
if not os.path.exists(pdf_path):
|
if not os.path.exists(pdf_path):
|
||||||
|
print("no pdf path")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
base_img, _, _ = annotating.make_base_image(pdf_path)
|
base_img, _, _ = annotating.make_base_image(pdf_path)
|
||||||
|
|
@ -135,7 +136,7 @@ def main():
|
||||||
os.makedirs(bgnot_dir, exist_ok=True)
|
os.makedirs(bgnot_dir, exist_ok=True)
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
labels = [l.replace(":", "").strip() for l in line.split(',') if l.strip()]
|
labels = [l.strip() for l in line.split(',') if l.strip()]
|
||||||
if not labels:
|
if not labels:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -154,7 +155,6 @@ def main():
|
||||||
annotating_with_checks.natural_key(x[0]),
|
annotating_with_checks.natural_key(x[0]),
|
||||||
annotating_with_checks.natural_key(x[1])
|
annotating_with_checks.natural_key(x[1])
|
||||||
))
|
))
|
||||||
|
|
||||||
# Render images in parallel using the pre-existing lock & render function
|
# Render images in parallel using the pre-existing lock & render function
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
||||||
rendered = list(executor.map(render_item, items_to_render))
|
rendered = list(executor.map(render_item, items_to_render))
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import img2pdf
|
||||||
from reportlab.pdfgen import canvas
|
from reportlab.pdfgen import canvas
|
||||||
|
|
||||||
# Fix for Matplotlib in threads: Set backend to non-interactive 'Agg'
|
# Fix for Matplotlib in threads: Set backend to non-interactive 'Agg'
|
||||||
# import matplotlib
|
import matplotlib
|
||||||
# matplotlib.use('Agg')
|
matplotlib.use('Agg')
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
import annotating
|
import annotating
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue