Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
-
#
|
3 |
st.set_page_config(page_title="Advanced File Downloader", layout="wide")
|
4 |
|
5 |
-
# Now
|
6 |
import os
|
7 |
import subprocess
|
8 |
from playwright.async_api import async_playwright, TimeoutError as PlaywrightTimeoutError
|
@@ -19,34 +19,42 @@ import zipfile
|
|
19 |
import tempfile
|
20 |
import mimetypes
|
21 |
import requests
|
22 |
-
|
23 |
-
# -------------------- spaCy Model Setup --------------------
|
24 |
import spacy
|
25 |
import spacy.cli
|
26 |
from spacy.language import Language
|
|
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
|
|
|
34 |
@st.cache_resource
|
35 |
-
def
|
|
|
36 |
try:
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
#
|
49 |
-
nlp_model = load_nlp_model()
|
50 |
|
51 |
|
52 |
|
|
|
1 |
import streamlit as st
|
2 |
+
# This MUST be the first Streamlit command
|
3 |
st.set_page_config(page_title="Advanced File Downloader", layout="wide")
|
4 |
|
5 |
+
# Now all other imports
|
6 |
import os
|
7 |
import subprocess
|
8 |
from playwright.async_api import async_playwright, TimeoutError as PlaywrightTimeoutError
|
|
|
19 |
import tempfile
|
20 |
import mimetypes
|
21 |
import requests
|
|
|
|
|
22 |
import spacy
|
23 |
import spacy.cli
|
24 |
from spacy.language import Language
|
25 |
+
from sentence_transformers import SentenceTransformer, util
|
26 |
+
from transformers import pipeline
|
27 |
|
28 |
+
# Initialize logging
|
29 |
+
logging.basicConfig(
|
30 |
+
filename='advanced_download_log.txt',
|
31 |
+
level=logging.INFO,
|
32 |
+
format='%(asctime)s - %(levelname)s - %(message)s'
|
33 |
+
)
|
34 |
+
logger = logging.getLogger()
|
35 |
|
36 |
+
# Model initialization with caching
|
37 |
@st.cache_resource
|
38 |
+
def initialize_models():
|
39 |
+
# spaCy
|
40 |
try:
|
41 |
+
nlp = spacy.load("en_core_web_sm")
|
42 |
+
except OSError:
|
43 |
+
spacy.cli.download("en_core_web_sm")
|
44 |
+
nlp = spacy.load("en_core_web_sm")
|
45 |
+
|
46 |
+
# SentenceTransformer
|
47 |
+
semantic_model = SentenceTransformer('all-MiniLM-L6-v2')
|
48 |
+
|
49 |
+
# Transformers
|
50 |
+
summarizer = pipeline("summarization")
|
51 |
+
|
52 |
+
return nlp, semantic_model, summarizer
|
53 |
+
|
54 |
+
# Initialize models
|
55 |
+
nlp_model, semantic_model, summarizer = initialize_models()
|
56 |
|
57 |
+
# Rest of your code...
|
|
|
58 |
|
59 |
|
60 |
|