Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,8 @@ import dash_bootstrap_components as dbc
|
|
13 |
from dash import html, dcc, Input, Output, State, ctx, dash_table
|
14 |
import google.generativeai as genai
|
15 |
from docx import Document
|
|
|
|
|
16 |
from PyPDF2 import PdfReader
|
17 |
|
18 |
# Initialize Dash app
|
@@ -428,9 +430,49 @@ def update_r_review_output(n_clicks, contents, filename, red_doc, requirements):
|
|
428 |
compliance_report = evaluate_compliance(document, requirements)
|
429 |
return dcc.Markdown(compliance_report)
|
430 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
431 |
def create_docx(content):
|
432 |
doc = Document()
|
433 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
return doc
|
435 |
|
436 |
@app.callback(
|
|
|
13 |
from dash import html, dcc, Input, Output, State, ctx, dash_table
|
14 |
import google.generativeai as genai
|
15 |
from docx import Document
|
16 |
+
from docx.shared import Pt
|
17 |
+
from docx.enum.style import WD_STYLE_TYPE
|
18 |
from PyPDF2 import PdfReader
|
19 |
|
20 |
# Initialize Dash app
|
|
|
430 |
compliance_report = evaluate_compliance(document, requirements)
|
431 |
return dcc.Markdown(compliance_report)
|
432 |
|
433 |
+
def parse_markdown(doc, content):
|
434 |
+
# Split content into paragraphs
|
435 |
+
paragraphs = content.split('\n\n')
|
436 |
+
|
437 |
+
for para in paragraphs:
|
438 |
+
# Check for headers
|
439 |
+
header_match = re.match(r'^(#{1,6})\s+(.+)$', para)
|
440 |
+
if header_match:
|
441 |
+
level = len(header_match.group(1))
|
442 |
+
text = header_match.group(2)
|
443 |
+
doc.add_heading(text, level=level)
|
444 |
+
else:
|
445 |
+
p = doc.add_paragraph()
|
446 |
+
# Split paragraph into runs
|
447 |
+
runs = re.split(r'(\*\*|\*|__|\~\~)', para)
|
448 |
+
is_bold = is_italic = is_underline = is_strikethrough = False
|
449 |
+
for run in runs:
|
450 |
+
if run == '**' or run == '__':
|
451 |
+
is_bold = not is_bold
|
452 |
+
elif run == '*':
|
453 |
+
is_italic = not is_italic
|
454 |
+
elif run == '~~':
|
455 |
+
is_strikethrough = not is_strikethrough
|
456 |
+
else:
|
457 |
+
r = p.add_run(run)
|
458 |
+
r.bold = is_bold
|
459 |
+
r.italic = is_italic
|
460 |
+
r.underline = is_underline
|
461 |
+
r.font.strike = is_strikethrough
|
462 |
+
|
463 |
def create_docx(content):
|
464 |
doc = Document()
|
465 |
+
|
466 |
+
# Add styles
|
467 |
+
styles = doc.styles
|
468 |
+
style_names = [style.name for style in styles]
|
469 |
+
if 'Code' not in style_names:
|
470 |
+
code_style = styles.add_style('Code', WD_STYLE_TYPE.PARAGRAPH)
|
471 |
+
code_font = code_style.font
|
472 |
+
code_font.name = 'Courier New'
|
473 |
+
code_font.size = Pt(10)
|
474 |
+
|
475 |
+
parse_markdown(doc, content)
|
476 |
return doc
|
477 |
|
478 |
@app.callback(
|