Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,12 @@
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import subprocess
|
3 |
-
import sys
|
4 |
|
5 |
def install_playwright_dependencies():
|
6 |
try:
|
7 |
-
#
|
8 |
-
os.system('apt-get update -y')
|
9 |
-
|
10 |
-
# Install required dependencies including GTK
|
11 |
dependencies = [
|
12 |
'libnss3',
|
13 |
'libnspr4',
|
@@ -16,28 +15,23 @@ def install_playwright_dependencies():
|
|
16 |
'libcups2',
|
17 |
'libxcomposite1',
|
18 |
'libxdamage1',
|
19 |
-
'libatspi2.0-0'
|
20 |
-
'libgtk-3-0', # Add GTK dependencies
|
21 |
-
'libgdk-3-0'
|
22 |
]
|
23 |
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
# Install
|
28 |
-
|
29 |
-
os.system('python -m playwright install')
|
30 |
|
31 |
-
st.success("Successfully installed Playwright dependencies")
|
32 |
except Exception as e:
|
33 |
st.error(f"Error installing dependencies: {e}")
|
34 |
-
st.error("Please
|
35 |
-
st.code("apt-get
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
st.set_page_config(page_title="Advanced File Downloader", layout="wide")
|
41 |
|
42 |
# Import other required packages
|
43 |
import spacy
|
@@ -137,16 +131,37 @@ def dummy_roberta_transformer(nlp, name):
|
|
137 |
return dummy
|
138 |
|
139 |
@st.cache_resource
|
140 |
-
def
|
141 |
try:
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
# Also load SentenceTransformer for semantic re-ranking.
|
152 |
from sentence_transformers import SentenceTransformer, util
|
|
|
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',
|
|
|
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
|
|
|
131 |
return dummy
|
132 |
|
133 |
@st.cache_resource
|
134 |
+
def load_models():
|
135 |
try:
|
136 |
+
# Load spaCy model
|
137 |
+
try:
|
138 |
+
nlp = spacy.load("en_core_web_sm")
|
139 |
+
except OSError:
|
140 |
+
st.info("Downloading spaCy model...")
|
141 |
+
spacy.cli.download("en_core_web_sm")
|
142 |
+
nlp = spacy.load("en_core_web_sm")
|
143 |
+
|
144 |
+
# Load SentenceTransformer
|
145 |
+
try:
|
146 |
+
from sentence_transformers import SentenceTransformer
|
147 |
+
semantic_model = SentenceTransformer('all-MiniLM-L6-v2')
|
148 |
+
except Exception as e:
|
149 |
+
st.error(f"Error loading SentenceTransformer: {e}")
|
150 |
+
semantic_model = None
|
151 |
+
|
152 |
+
# Load Transformers pipeline with correct import
|
153 |
+
try:
|
154 |
+
from transformers import pipeline, AutoModelForSeq2SeqGenerationWithLMHead, AutoTokenizer
|
155 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
156 |
+
except Exception as e:
|
157 |
+
st.error(f"Error loading Transformers: {e}")
|
158 |
+
summarizer = None
|
159 |
+
|
160 |
+
return nlp, semantic_model, summarizer
|
161 |
+
|
162 |
+
except Exception as e:
|
163 |
+
st.error(f"Error loading models: {e}")
|
164 |
+
return None, None, None
|
165 |
|
166 |
# Also load SentenceTransformer for semantic re-ranking.
|
167 |
from sentence_transformers import SentenceTransformer, util
|