Ozgur Unlu
commited on
Commit
•
29bcda2
1
Parent(s):
052a382
some UI changes, region selection, using CPU
Browse files- analyzer.py +12 -5
- interface.py +50 -16
- requirements.txt +1 -0
analyzer.py
CHANGED
@@ -18,9 +18,16 @@ def extract_text_from_image(image):
|
|
18 |
print(f"Error in text extraction: {str(e)}")
|
19 |
return "Error extracting text from image"
|
20 |
|
21 |
-
def check_compliance(text):
|
22 |
-
"""Check text for compliance across
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
report = {
|
25 |
"compliant": True,
|
26 |
"violations": [],
|
@@ -128,13 +135,13 @@ def generate_html_report(compliance_report):
|
|
128 |
html += '</div></div>'
|
129 |
return html
|
130 |
|
131 |
-
def analyze_ad_copy(image):
|
132 |
"""Main function to analyze ad copy"""
|
133 |
# Extract text from image
|
134 |
text = extract_text_from_image(image)
|
135 |
|
136 |
# Check compliance
|
137 |
-
compliance_report = check_compliance(text)
|
138 |
|
139 |
# Generate HTML report
|
140 |
return generate_html_report(compliance_report)
|
|
|
18 |
print(f"Error in text extraction: {str(e)}")
|
19 |
return "Error extracting text from image"
|
20 |
|
21 |
+
def check_compliance(text, regions=None):
|
22 |
+
"""Check text for compliance across selected regions"""
|
23 |
+
all_rules = compliance_rules.get_all_rules()
|
24 |
+
|
25 |
+
# Filter rules based on selected regions
|
26 |
+
if regions is not None:
|
27 |
+
rules = {region: rules for region, rules in all_rules.items() if regions.get(region, True)}
|
28 |
+
else:
|
29 |
+
rules = all_rules
|
30 |
+
|
31 |
report = {
|
32 |
"compliant": True,
|
33 |
"violations": [],
|
|
|
135 |
html += '</div></div>'
|
136 |
return html
|
137 |
|
138 |
+
def analyze_ad_copy(image, regions=None):
|
139 |
"""Main function to analyze ad copy"""
|
140 |
# Extract text from image
|
141 |
text = extract_text_from_image(image)
|
142 |
|
143 |
# Check compliance
|
144 |
+
compliance_report = check_compliance(text, regions)
|
145 |
|
146 |
# Generate HTML report
|
147 |
return generate_html_report(compliance_report)
|
interface.py
CHANGED
@@ -26,6 +26,12 @@ def create_interface():
|
|
26 |
color: #6c757d;
|
27 |
text-align: center;
|
28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
"""
|
30 |
|
31 |
# Create a placeholder HTML
|
@@ -45,25 +51,53 @@ def create_interface():
|
|
45 |
</div>
|
46 |
"""
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
type="numpy",
|
53 |
label="Upload Marketing Material",
|
54 |
height=300,
|
55 |
width=400
|
56 |
)
|
57 |
-
|
58 |
-
|
59 |
-
gr.
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
return demo
|
|
|
26 |
color: #6c757d;
|
27 |
text-align: center;
|
28 |
}
|
29 |
+
.checkbox-group {
|
30 |
+
margin: 10px 0;
|
31 |
+
padding: 10px;
|
32 |
+
background-color: #f8f9fa;
|
33 |
+
border-radius: 5px;
|
34 |
+
}
|
35 |
"""
|
36 |
|
37 |
# Create a placeholder HTML
|
|
|
51 |
</div>
|
52 |
"""
|
53 |
|
54 |
+
def analyze_with_regions(image, us_sec, uk_fca, eu):
|
55 |
+
if not any([us_sec, uk_fca, eu]):
|
56 |
+
return """
|
57 |
+
<div class="report-container">
|
58 |
+
<div class="status non-compliant">⚠️ Please select at least one region for compliance checking.</div>
|
59 |
+
</div>
|
60 |
+
"""
|
61 |
+
return analyze_ad_copy(image, {"US_SEC": us_sec, "UK_FCA": uk_fca, "EU": eu})
|
62 |
+
|
63 |
+
def reset_interface():
|
64 |
+
return None, True, True, True, placeholder_html
|
65 |
+
|
66 |
+
with gr.Blocks(theme=gr.themes.Default(), css=css) as demo:
|
67 |
+
gr.Markdown("# Marketing Campaign Financial Compliance Checker")
|
68 |
+
gr.Markdown("Upload marketing material to check compliance with financial regulations.")
|
69 |
+
|
70 |
+
with gr.Row():
|
71 |
+
image_input = gr.Image(
|
72 |
type="numpy",
|
73 |
label="Upload Marketing Material",
|
74 |
height=300,
|
75 |
width=400
|
76 |
)
|
77 |
+
|
78 |
+
with gr.Row(elem_classes="checkbox-group"):
|
79 |
+
us_sec = gr.Checkbox(value=True, label="US - SEC", interactive=True)
|
80 |
+
uk_fca = gr.Checkbox(value=True, label="UK - FCA", interactive=True)
|
81 |
+
eu = gr.Checkbox(value=True, label="EU", interactive=True)
|
82 |
+
|
83 |
+
output = gr.HTML(value=placeholder_html, label="Compliance Report")
|
84 |
+
|
85 |
+
with gr.Row():
|
86 |
+
clear_btn = gr.ClearButton([image_input, us_sec, uk_fca, eu, output])
|
87 |
+
submit_btn = gr.Button("Submit")
|
88 |
+
|
89 |
+
# Set up the submit action
|
90 |
+
submit_btn.click(
|
91 |
+
fn=analyze_with_regions,
|
92 |
+
inputs=[image_input, us_sec, uk_fca, eu],
|
93 |
+
outputs=output
|
94 |
+
)
|
95 |
+
|
96 |
+
# Set up the clear action to reset to defaults
|
97 |
+
clear_btn.click(
|
98 |
+
fn=reset_interface,
|
99 |
+
inputs=[],
|
100 |
+
outputs=[image_input, us_sec, uk_fca, eu, output]
|
101 |
+
)
|
102 |
+
|
103 |
return demo
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
torch>=2.0.0
|
2 |
torchvision
|
3 |
gradio>=4.8.0
|
|
|
1 |
+
--extra-index-url https://download.pytorch.org/whl/cu113
|
2 |
torch>=2.0.0
|
3 |
torchvision
|
4 |
gradio>=4.8.0
|