euler314 commited on
Commit
d17208b
·
verified ·
1 Parent(s): dc00770

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -23
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
- # First method: using playwright install-deps
11
- try:
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
- install_command = ['sudo', 'apt-get', 'install', '-y'] + dependencies
35
- subprocess.run(install_command, check=True)
36
 
37
- # Install playwright browsers
38
- subprocess.run(['playwright', 'install'], check=True)
 
39
 
40
- st.success("Successfully installed Playwright dependencies using apt-get")
41
- except subprocess.CalledProcessError as e:
42
  st.error(f"Error installing dependencies: {e}")
43
- st.error("Please run the following commands manually:")
44
- st.code("sudo apt-get update")
45
- st.code("sudo apt-get install -y libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libxcomposite1 libxdamage1 libatspi2.0-0")
46
  st.code("playwright install")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  except Exception as e:
48
- st.error(f"Unexpected error: {e}")
 
49
 
50
- # Call the installation function
51
- with st.spinner("Installing Playwright dependencies..."):
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