cmckinle commited on
Commit
b14f67e
·
verified ·
1 Parent(s): e1ddcb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -14,6 +14,7 @@ import base64
14
  from io import BytesIO
15
  from reportlab.lib.pagesizes import letter
16
  from reportlab.pdfgen import canvas
 
17
 
18
  MODEL_NAME = "cmckinle/sdxl-flux-detector"
19
  LABELS = ["AI", "Real"]
@@ -201,18 +202,26 @@ def generate_pdf(accuracy, roc_score, report_html, confusion_matrix_plot):
201
  buffer = BytesIO()
202
  c = canvas.Canvas(buffer, pagesize=letter)
203
 
 
204
  c.drawString(100, 750, f"Model Results")
205
  c.drawString(100, 730, f"Accuracy: {accuracy:.2f}")
206
  c.drawString(100, 710, f"ROC Score: {roc_score:.2f}")
207
 
208
  y_position = 690
209
- for line in report_html.replace("<br>", "\n").splitlines():
210
- if y_position < 50:
 
 
 
 
 
 
211
  c.showPage()
212
  y_position = 750
213
  c.drawString(100, y_position, line.strip())
214
  y_position -= 20
215
 
 
216
  img_buffer = BytesIO()
217
  confusion_matrix_plot.savefig(img_buffer, format="png")
218
  img_buffer.seek(0)
@@ -222,6 +231,7 @@ def generate_pdf(accuracy, roc_score, report_html, confusion_matrix_plot):
222
  buffer.seek(0)
223
  return buffer
224
 
 
225
  def load_url(url):
226
  try:
227
  urllib.request.urlretrieve(url, "temp_image.png")
 
14
  from io import BytesIO
15
  from reportlab.lib.pagesizes import letter
16
  from reportlab.pdfgen import canvas
17
+ import beautifulsoup4
18
 
19
  MODEL_NAME = "cmckinle/sdxl-flux-detector"
20
  LABELS = ["AI", "Real"]
 
202
  buffer = BytesIO()
203
  c = canvas.Canvas(buffer, pagesize=letter)
204
 
205
+ # Add content to PDF
206
  c.drawString(100, 750, f"Model Results")
207
  c.drawString(100, 730, f"Accuracy: {accuracy:.2f}")
208
  c.drawString(100, 710, f"ROC Score: {roc_score:.2f}")
209
 
210
  y_position = 690
211
+ # Convert report_html to plain text if it's HTML content
212
+ from bs4 import BeautifulSoup
213
+ soup = BeautifulSoup(report_html, "html.parser")
214
+ report_text = soup.get_text()
215
+
216
+ # Add each line of the report text
217
+ for line in report_text.splitlines():
218
+ if y_position < 50: # Create a new page if space runs out
219
  c.showPage()
220
  y_position = 750
221
  c.drawString(100, y_position, line.strip())
222
  y_position -= 20
223
 
224
+ # Save Confusion Matrix Plot as an Image and Add it to the PDF
225
  img_buffer = BytesIO()
226
  confusion_matrix_plot.savefig(img_buffer, format="png")
227
  img_buffer.seek(0)
 
231
  buffer.seek(0)
232
  return buffer
233
 
234
+
235
  def load_url(url):
236
  try:
237
  urllib.request.urlretrieve(url, "temp_image.png")