Darshan03 commited on
Commit
fdc1c33
·
verified ·
1 Parent(s): 249d2a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -34
app.py CHANGED
@@ -26,39 +26,23 @@ import os
26
  import sys
27
  import subprocess
28
 
29
- def install_playwright_dependencies():
30
- try:
31
- import playwright
32
- except ImportError:
33
- print("Playwright is not installed. Installing now...")
34
- subprocess.run([sys.executable, "-m", "pip", "install", "playwright"], check=True)
35
-
36
- print("Installing Playwright dependencies...")
37
- if sys.platform.startswith("linux"):
38
- try:
39
- subprocess.run(["apt-get", "update"], check=True)
40
- subprocess.run([
41
- "apt-get", "install", "-y",
42
- "libnss3", "libnspr4", "libatk1.0-0", "libatk-bridge2.0-0",
43
- "libcups2", "libxcomposite1", "libxdamage1", "libatspi2.0-0"
44
- ], check=True)
45
- except Exception as e:
46
- print(f"Warning: Failed to install dependencies. Try manually: {e}")
47
-
48
- elif sys.platform.startswith("win"):
49
- print("Ensure Windows has necessary dependencies (WSL may be required).")
50
-
51
- elif sys.platform.startswith("darwin"):
52
- try:
53
- subprocess.run(["brew", "install", "playwright"], check=True)
54
- except Exception as e:
55
- print(f"Warning: Failed to install Playwright on macOS. {e}")
56
-
57
- print("Installing Playwright browsers...")
58
- subprocess.run([sys.executable, "-m", "playwright", "install"], check=True)
59
- subprocess.run([sys.executable, "-m", "playwright", "install-deps"], check=True)
60
-
61
- install_playwright_dependencies()
62
 
63
  # Load environment variables from .env
64
  load_dotenv()
@@ -132,7 +116,8 @@ if uploaded_file is not None:
132
  # Market scenarios extraction
133
  url = "https://www.livemint.com/market/stock-market-news/page-7"
134
  st.write("Extracting market scenarios...")
135
- context_data = asyncio.run(extract_text_from_website(url))
 
136
  st.success("Market context extracted successfully!")
137
 
138
  # Generate scenario prompt
 
26
  import sys
27
  import subprocess
28
 
29
+
30
+ import requests
31
+ from bs4 import BeautifulSoup
32
+
33
+ def scrape_website(url):
34
+ headers = {
35
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
36
+ }
37
+
38
+ response = requests.get(url, headers=headers)
39
+
40
+ if response.status_code == 200:
41
+ soup = BeautifulSoup(response.text, "html.parser")
42
+ return soup.prettify() # Returns the full parsed HTML
43
+ else:
44
+ return f"Failed to retrieve page. Status code: {response.status_code}"
45
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  # Load environment variables from .env
48
  load_dotenv()
 
116
  # Market scenarios extraction
117
  url = "https://www.livemint.com/market/stock-market-news/page-7"
118
  st.write("Extracting market scenarios...")
119
+ # context_data = asyncio.run(extract_text_from_website(url))
120
+ context_data = scrape_website(url)
121
  st.success("Market context extracted successfully!")
122
 
123
  # Generate scenario prompt