Update app.py
Browse files
app.py
CHANGED
|
@@ -26,39 +26,23 @@ import os
|
|
| 26 |
import sys
|
| 27 |
import subprocess
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 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
|