Update src/streamlit_app.py
Browse files- src/streamlit_app.py +5 -19
src/streamlit_app.py
CHANGED
@@ -1,35 +1,21 @@
|
|
1 |
import streamlit as st
|
2 |
-
import os
|
3 |
-
import subprocess
|
4 |
import nltk
|
5 |
import spacy
|
6 |
import benepar
|
7 |
from nltk import Tree
|
8 |
|
9 |
-
#
|
10 |
nltk_data_path = "/tmp/nltk_data"
|
11 |
nltk.data.path.append(nltk_data_path)
|
12 |
-
|
13 |
-
# Download safely
|
14 |
nltk.download('punkt', download_dir=nltk_data_path)
|
15 |
|
16 |
-
# Load spaCy model
|
17 |
-
|
18 |
-
nlp = spacy.load("en_core_web_sm")
|
19 |
-
except:
|
20 |
-
subprocess.run(["python", "-m", "pip", "install", "--user", "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl"])
|
21 |
-
import importlib
|
22 |
-
importlib.invalidate_caches()
|
23 |
-
nlp = spacy.load("en_core_web_sm")
|
24 |
|
25 |
-
#
|
26 |
if "benepar" not in nlp.pipe_names:
|
27 |
-
|
28 |
-
benepar.download('benepar_en3') # safe internal method
|
29 |
-
except:
|
30 |
-
subprocess.run(["python", "-m", "benepar.download", "benepar_en3"])
|
31 |
nlp.add_pipe("benepar", config={"model": "benepar_en3"})
|
32 |
-
|
33 |
# Streamlit UI
|
34 |
st.set_page_config(page_title="Syntax Parser Comparison", layout="wide")
|
35 |
st.title("π Syntax Parser Comparison Tool")
|
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
import nltk
|
3 |
import spacy
|
4 |
import benepar
|
5 |
from nltk import Tree
|
6 |
|
7 |
+
# Configure nltk to use /tmp
|
8 |
nltk_data_path = "/tmp/nltk_data"
|
9 |
nltk.data.path.append(nltk_data_path)
|
|
|
|
|
10 |
nltk.download('punkt', download_dir=nltk_data_path)
|
11 |
|
12 |
+
# Load installed spaCy model
|
13 |
+
nlp = spacy.load("en_core_web_sm")
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# Add benepar parser
|
16 |
if "benepar" not in nlp.pipe_names:
|
17 |
+
benepar.download("benepar_en3")
|
|
|
|
|
|
|
18 |
nlp.add_pipe("benepar", config={"model": "benepar_en3"})
|
|
|
19 |
# Streamlit UI
|
20 |
st.set_page_config(page_title="Syntax Parser Comparison", layout="wide")
|
21 |
st.title("π Syntax Parser Comparison Tool")
|