Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
st.set_page_config(page_title="Advanced File Downloader", layout="wide")
|
3 |
|
4 |
-
import os
|
5 |
-
import subprocess
|
6 |
-
|
7 |
-
def install_playwright_dependencies():
|
8 |
-
try:
|
9 |
-
# Install system dependencies using apt-get
|
10 |
-
dependencies = [
|
11 |
-
'libnss3',
|
12 |
-
'libnspr4',
|
13 |
-
'libatk1.0-0',
|
14 |
-
'libatk-bridge2.0-0',
|
15 |
-
'libcups2',
|
16 |
-
'libxcomposite1',
|
17 |
-
'libxdamage1',
|
18 |
-
'libatspi2.0-0'
|
19 |
-
]
|
20 |
-
|
21 |
-
subprocess.run(['apt-get', 'update', '-y'], check=True)
|
22 |
-
subprocess.run(['apt-get', 'install', '-y'] + dependencies, check=True)
|
23 |
-
|
24 |
-
# Install Playwright browser
|
25 |
-
subprocess.run(['playwright', 'install', 'chromium'], check=True)
|
26 |
-
|
27 |
-
except Exception as e:
|
28 |
-
st.error(f"Error installing dependencies: {e}")
|
29 |
-
st.error("Please install the following dependencies manually:")
|
30 |
-
st.code("apt-get install -y " + " ".join(dependencies))
|
31 |
|
32 |
-
# Call installation function
|
33 |
-
with st.spinner("Installing required dependencies..."):
|
34 |
-
install_playwright_dependencies()
|
35 |
|
36 |
# Import other required packages
|
37 |
import spacy
|
@@ -118,6 +88,45 @@ import zipfile
|
|
118 |
import tempfile
|
119 |
import mimetypes
|
120 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
# -------------------- spaCy Model Setup --------------------
|
123 |
import spacy
|
|
|
1 |
import streamlit as st
|
2 |
st.set_page_config(page_title="Advanced File Downloader", layout="wide")
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
|
|
|
|
|
|
5 |
|
6 |
# Import other required packages
|
7 |
import spacy
|
|
|
88 |
import tempfile
|
89 |
import mimetypes
|
90 |
import requests
|
91 |
+
# -------------------- Playwright Setup --------------------
|
92 |
+
def install_playwright_dependencies():
|
93 |
+
os.environ['PLAYWRIGHT_BROWSERS_PATH'] = os.path.expanduser("~/.cache/ms-playwright")
|
94 |
+
os.environ['LD_LIBRARY_PATH'] = '/usr/lib/playwright:/usr/lib/x86_64-linux-gnu'
|
95 |
+
try:
|
96 |
+
subprocess.run(['apt-get', 'update', '-y'], check=True)
|
97 |
+
packages = [
|
98 |
+
'libnss3', 'libnss3-tools', 'libnspr4', 'libatk1.0-0',
|
99 |
+
'libatk-bridge2.0-0', 'libatspi2.0-0', 'libcups2', 'libxcomposite1',
|
100 |
+
'libxdamage1', 'libdrm2', 'libgbm1', 'libpango-1.0-0'
|
101 |
+
]
|
102 |
+
subprocess.run(['apt-get', 'install', '-y', '--no-install-recommends'] + packages, check=True)
|
103 |
+
os.makedirs('/usr/lib/playwright', exist_ok=True)
|
104 |
+
symlinks = {
|
105 |
+
'libnss3.so': '/usr/lib/x86_64-linux-gnu/libnss3.so',
|
106 |
+
'libnssutil3.so': '/usr/lib/x86_64-linux-gnu/libnssutil3.so',
|
107 |
+
'libsmime3.so': '/usr/lib/x86_64-linux-gnu/libsmime3.so',
|
108 |
+
'libnspr4.so': '/usr/lib/x86_64-linux-gnu/libnspr4.so',
|
109 |
+
'libatk-1.0.so.0': '/usr/lib/x86_64-linux-gnu/libatk-1.0.so.0',
|
110 |
+
'libatk-bridge-2.0.so.0': '/usr/lib/x86_64-linux-gnu/libatk-bridge-2.0.so.0',
|
111 |
+
'libcups.so.2': '/usr/lib/x86_64-linux-gnu/libcups.so.2',
|
112 |
+
'libatspi.so.0': '/usr/lib/x86_64-linux-gnu/libatspi.so.0',
|
113 |
+
'libXcomposite.so.1': '/usr/lib/x86_64-linux-gnu/libXcomposite.so.1',
|
114 |
+
'libXdamage.so.1': '/usr/lib/x86_64-linux-gnu/libXdamage.so.1'
|
115 |
+
}
|
116 |
+
for link_name, target in symlinks.items():
|
117 |
+
link_path = os.path.join('/usr/lib/playwright', link_name)
|
118 |
+
if not os.path.exists(link_path):
|
119 |
+
os.symlink(target, link_path)
|
120 |
+
subprocess.run(['python3', '-m', 'playwright', 'install', 'chromium'], check=True)
|
121 |
+
browser_path = os.path.expanduser("~/.cache/ms-playwright")
|
122 |
+
os.makedirs(browser_path, exist_ok=True)
|
123 |
+
subprocess.run(['chmod', '-R', '755', browser_path], check=True)
|
124 |
+
except subprocess.CalledProcessError as e:
|
125 |
+
print(f"Error installing dependencies: {e}")
|
126 |
+
except Exception as e:
|
127 |
+
print(f"Error: {e}")
|
128 |
+
|
129 |
+
install_playwright_dependencies()
|
130 |
|
131 |
# -------------------- spaCy Model Setup --------------------
|
132 |
import spacy
|