Update app.py
Browse files
app.py
CHANGED
@@ -4,20 +4,12 @@ st.set_page_config(page_title="Advanced File Downloader", layout="wide")
|
|
4 |
|
5 |
import os
|
6 |
import subprocess
|
|
|
7 |
|
8 |
def install_playwright_dependencies():
|
9 |
try:
|
10 |
-
#
|
11 |
-
|
12 |
-
subprocess.run(['sudo', 'playwright', 'install-deps'], check=True)
|
13 |
-
st.success("Successfully installed Playwright dependencies using playwright install-deps")
|
14 |
-
return
|
15 |
-
except subprocess.CalledProcessError:
|
16 |
-
st.warning("Failed to install using playwright install-deps, trying apt-get method...")
|
17 |
-
|
18 |
-
# Second method: using apt-get
|
19 |
-
# Update package list
|
20 |
-
subprocess.run(['sudo', 'apt-get', 'update', '-y'], check=True)
|
21 |
|
22 |
# Install required dependencies
|
23 |
dependencies = [
|
@@ -31,26 +23,61 @@ def install_playwright_dependencies():
|
|
31 |
'libatspi2.0-0'
|
32 |
]
|
33 |
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
# Install playwright browsers
|
38 |
-
|
|
|
39 |
|
40 |
-
st.success("Successfully installed Playwright dependencies
|
41 |
-
except
|
42 |
st.error(f"Error installing dependencies: {e}")
|
43 |
-
st.error("Please run
|
44 |
-
st.code("
|
45 |
-
st.code("
|
46 |
st.code("playwright install")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
except Exception as e:
|
48 |
-
st.error(f"
|
|
|
49 |
|
50 |
-
#
|
51 |
-
with st.spinner("
|
52 |
install_playwright_dependencies()
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# Rest of your code...
|
55 |
|
56 |
import os
|
|
|
4 |
|
5 |
import os
|
6 |
import subprocess
|
7 |
+
import sys
|
8 |
|
9 |
def install_playwright_dependencies():
|
10 |
try:
|
11 |
+
# Use apt-get directly without sudo
|
12 |
+
os.system('apt-get update -y')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Install required dependencies
|
15 |
dependencies = [
|
|
|
23 |
'libatspi2.0-0'
|
24 |
]
|
25 |
|
26 |
+
dependency_command = f"apt-get install -y {' '.join(dependencies)}"
|
27 |
+
os.system(dependency_command)
|
28 |
|
29 |
+
# Install playwright and its browsers
|
30 |
+
os.system('playwright install')
|
31 |
+
os.system('python -m playwright install')
|
32 |
|
33 |
+
st.success("Successfully installed Playwright dependencies")
|
34 |
+
except Exception as e:
|
35 |
st.error(f"Error installing dependencies: {e}")
|
36 |
+
st.error("Please run these commands manually in your terminal:")
|
37 |
+
st.code("apt-get update")
|
38 |
+
st.code(f"apt-get install -y {' '.join(dependencies)}")
|
39 |
st.code("playwright install")
|
40 |
+
|
41 |
+
# Import other required packages
|
42 |
+
import spacy
|
43 |
+
import spacy.cli
|
44 |
+
|
45 |
+
@st.cache_resource
|
46 |
+
def load_models():
|
47 |
+
try:
|
48 |
+
# Try to load spaCy model
|
49 |
+
try:
|
50 |
+
nlp = spacy.load("en_core_web_sm")
|
51 |
+
except OSError:
|
52 |
+
st.info("Downloading spaCy model...")
|
53 |
+
spacy.cli.download("en_core_web_sm")
|
54 |
+
nlp = spacy.load("en_core_web_sm")
|
55 |
+
|
56 |
+
# Load other models
|
57 |
+
from sentence_transformers import SentenceTransformer
|
58 |
+
semantic_model = SentenceTransformer('all-MiniLM-L6-v2')
|
59 |
+
|
60 |
+
from transformers import pipeline
|
61 |
+
summarizer = pipeline("summarization")
|
62 |
+
|
63 |
+
return nlp, semantic_model, summarizer
|
64 |
except Exception as e:
|
65 |
+
st.error(f"Error loading models: {e}")
|
66 |
+
return None, None, None
|
67 |
|
68 |
+
# Initialize dependencies and models
|
69 |
+
with st.spinner("Setting up dependencies..."):
|
70 |
install_playwright_dependencies()
|
71 |
|
72 |
+
with st.spinner("Loading models..."):
|
73 |
+
nlp_model, semantic_model, summarizer = load_models()
|
74 |
+
|
75 |
+
if not all([nlp_model, semantic_model, summarizer]):
|
76 |
+
st.error("Failed to load required models. Please check the error messages above.")
|
77 |
+
st.stop()
|
78 |
+
|
79 |
+
# Rest of your imports and code here...
|
80 |
+
|
81 |
# Rest of your code...
|
82 |
|
83 |
import os
|