utkarsh1797 commited on
Commit
991956b
Β·
verified Β·
1 Parent(s): f83e225

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +20 -7
src/streamlit_app.py CHANGED
@@ -1,28 +1,41 @@
 
1
  import os
2
  import subprocess
3
  import nltk
4
  import spacy
 
 
5
 
6
- # Setup NLTK
7
  nltk_data_path = "/tmp/nltk_data"
8
- nltk.download('punkt', download_dir=nltk_data_path)
9
- nltk.download('benepar_en3', download_dir=nltk_data_path)
10
  nltk.data.path.append(nltk_data_path)
11
 
12
- # Load spaCy model with fallback
 
 
 
13
  try:
14
  nlp = spacy.load("en_core_web_sm")
15
  except:
16
- subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
 
 
17
  nlp = spacy.load("en_core_web_sm")
18
-
 
19
  if "benepar" not in nlp.pipe_names:
 
 
 
 
20
  nlp.add_pipe("benepar", config={"model": "benepar_en3"})
21
 
22
- st.set_page_config(page_title="Syntax Parser Comparison Tool", layout="wide")
 
23
  st.title("🌐 Syntax Parser Comparison Tool")
24
  st.write("This tool compares Dependency Parsing, Constituency Parsing, and a simulated Abstract Syntax Representation (ASR).")
25
 
 
26
  sentence = st.text_input("Enter a sentence:", "John eats an apple.")
27
 
28
  if sentence:
 
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
+ # Set NLTK path to writable /tmp
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 with fallback install
17
  try:
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
+ # Load benepar model safely
26
  if "benepar" not in nlp.pipe_names:
27
+ try:
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")
36
  st.write("This tool compares Dependency Parsing, Constituency Parsing, and a simulated Abstract Syntax Representation (ASR).")
37
 
38
+ # Input
39
  sentence = st.text_input("Enter a sentence:", "John eats an apple.")
40
 
41
  if sentence: