Skip to content

Commit 5e0e0f7

Browse files
Fix #948 - don't try to install spaCy at runtime or require it
1 parent 9441f1f commit 5e0e0f7

File tree

3 files changed

+17
-84
lines changed

3 files changed

+17
-84
lines changed

docassemble/ALWeaver/data/questions/assembly_line.yml

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ code: |
5959
if yes_recognize_form_fields: # ask to add fields
6060
process_field_recognition
6161
if im_feeling_lucky:
62-
if not formfyxer_available() and user_logged_in() and user_has_privilege(["admin"]) and install_en_core_web_lg:
63-
install_spacy_background_task
64-
if not install_spacy_background_task.ready():
65-
install_spacy_background_waiting_screen
6662
nav.set_sections([
6763
{"nav_generate_interview": "Generate your interview"},
6864
{"nav_review": "Review your answers"},
@@ -1904,20 +1900,6 @@ subquestion: |
19041900
19051901
% endfor
19061902
1907-
% if not formfyxer_available():
1908-
<div class="alert alert-warning" role="alert">
1909-
Automatic field grouping isn't set up. To use it, you need:
1910-
1911-
<ol>
1912-
<li>The `en_core_web_lg` installed, or</li>
1913-
<li>An API token for tools.suffolklitlab.org installed in your configuration.</li>
1914-
</ol>
1915-
1916-
You can still use auto drafting mode but all questions will be
1917-
placed on one screen. You can edit them in your playground later.
1918-
</div>
1919-
% endif
1920-
19211903
fields:
19221904
- Do you want us to draft the interview for you?: im_feeling_lucky
19231905
datatype: radio
@@ -1947,40 +1929,6 @@ fields:
19471929
show if: interview.start_with_json
19481930
accept: |
19491931
"application/json"
1950-
- Try to install the `en_core_web_lg` package before using auto drafting mode: install_en_core_web_lg
1951-
help: |
1952-
Installing `en_core_web_lg` will allow you to use automatic field
1953-
grouping but it may use more memory on your server.
1954-
1955-
If you are a nonprofit, you can request an API token to use
1956-
auto field grouping without installing `en_core_web_lg`.
1957-
datatype: yesnoradio
1958-
show if:
1959-
variable: im_feeling_lucky
1960-
is: True
1961-
code: |
1962-
not formfyxer_available() and user_logged_in() and user_has_privilege(["admin"])
1963-
---
1964-
code: |
1965-
install_spacy_background_task = background_action("install_spacy_background_action")
1966-
---
1967-
code: |
1968-
install_spacy_model()
1969-
background_response()
1970-
install_spacy_background_action = True
1971-
---
1972-
event: install_spacy_background_waiting_screen
1973-
id: waiting screen
1974-
question: |
1975-
Installing `en_core_web_lg`
1976-
subquestion: |
1977-
Please wait while we install `en_core_web_lg`. This can take a
1978-
few minutes to complete.
1979-
1980-
<div class="spinner-border" role="status">
1981-
<span class="visually-hidden">Loading...</span>
1982-
</div>
1983-
reload: True
19841932
---
19851933
template: explain_auto_drafting
19861934
subject: |

docassemble/ALWeaver/interview_generator.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,12 @@
5858
import re
5959
import uuid
6060
import zipfile
61-
import spacy
6261
from dataclasses import dataclass
6362
import pycountry
6463

6564
mako.runtime.UNDEFINED = DAEmpty()
6665

6766

68-
def formfyxer_available():
69-
if get_config("assembly line", {}).get("tools.suffolklitlab.org api key"):
70-
return True
71-
return spacy.util.is_package("en_core_web_lg")
72-
73-
7467
TypeType = type(type(None))
7568

7669
__all__ = [
@@ -87,7 +80,6 @@ def formfyxer_available():
8780
"escape_quotes",
8881
"field_type_options",
8982
"fix_id",
90-
"formfyxer_available",
9183
"get_character_limit",
9284
"get_court_choices",
9385
"get_docx_validation_errors",
@@ -98,7 +90,6 @@ def formfyxer_available():
9890
"get_pdf_variable_name_matches",
9991
"get_variable_name_warnings",
10092
"indent_by",
101-
"install_spacy_model",
10293
"is_reserved_docx_label",
10394
"is_reserved_label",
10495
"is_url",
@@ -146,11 +137,6 @@ def formfyxer_available():
146137
remove_u = re.compile(r"^u")
147138

148139

149-
def install_spacy_model(model="en_core_web_lg"):
150-
if not spacy.util.is_package(model):
151-
spacy.cli.download(model)
152-
153-
154140
class ParsingException(Exception):
155141
"""Throws an error if we can't understand the labels somehow, so we can tell the user"""
156142

@@ -1803,23 +1789,22 @@ def _guess_categories(self, title) -> List[str]:
18031789
Returns:
18041790
List[str]: A list of categories
18051791
"""
1806-
if formfyxer_available():
1807-
# Get the full text of all templates
1808-
full_text = ""
1809-
for template in self.uploaded_templates:
1810-
if template.filename.lower().endswith(".pdf"):
1811-
full_text += extract_text(template.path())
1812-
elif template.filename.lower().endswith(".docx"):
1813-
docx_data = docx2python(
1814-
template.path()
1815-
) # Will error with invalid value
1816-
full_text += docx_data.text
1817-
categories = formfyxer.spot(
1818-
title + ": " + full_text,
1819-
token=get_config("assembly line", {}).get("spot api key", None),
1820-
)
1821-
if categories and not "401" in categories:
1822-
return categories
1792+
# Get the full text of all templates
1793+
full_text = ""
1794+
for template in self.uploaded_templates:
1795+
if template.filename.lower().endswith(".pdf"):
1796+
full_text += extract_text(template.path())
1797+
elif template.filename.lower().endswith(".docx"):
1798+
docx_data = docx2python(
1799+
template.path()
1800+
) # Will error with invalid value
1801+
full_text += docx_data.text
1802+
categories = formfyxer.spot(
1803+
title + ": " + full_text,
1804+
token=get_config("assembly line", {}).get("spot api key", None),
1805+
)
1806+
if categories and not "401" in categories:
1807+
return categories
18231808
# Top hits: Housing, Family, Consumer, Probate, Criminal, Traffic, Consumer, Health, Immigration, Employment
18241809
if any(
18251810
keyword in title.lower()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def find_package_data(where='.', package='', exclude=standard_exclude, exclude_d
5353
url='https://docassemble.org',
5454
packages=find_packages(),
5555
namespace_packages=['docassemble'],
56-
install_requires=['PyYAML>=5.1.2', 'beautifulsoup4>=4.11.1', 'docassemble.ALToolbox>=0.4.2', 'docassemble.AssemblyLine>=2.11.3', 'docx2python>=1.27.1', 'more-itertools>=8.6.0', 'numpy>=1.0.4', 'pikepdf>=5.1.1', 'scikit-learn>=0.0', 'spacy>=3.2.0', 'formfyxer>=0.3.0a1'],
56+
install_requires=['PyYAML>=5.1.2', 'beautifulsoup4>=4.11.1', 'docassemble.ALToolbox>=0.4.2', 'docassemble.AssemblyLine>=2.11.3', 'docx2python>=1.27.1', 'more-itertools>=8.6.0', 'numpy>=1.0.4', 'pikepdf>=5.1.1', 'formfyxer>=0.3.0a1'],
5757
zip_safe=False,
5858
package_data=find_package_data(where='docassemble/ALWeaver/', package='docassemble.ALWeaver'),
5959
)

0 commit comments

Comments
 (0)