Update app.py
Browse files
app.py
CHANGED
|
@@ -288,6 +288,11 @@ def answer_question(question):
|
|
| 288 |
logging.error(f"Error answering question: {str(e)}")
|
| 289 |
return f"Error generating answer: {str(e)}"
|
| 290 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
# Sidebar for navigation
|
| 292 |
st.sidebar.title("Navigation")
|
| 293 |
app_mode = st.sidebar.radio("Choose a mode", ["Web Scraping", "Chat with Content", "About"])
|
|
@@ -296,7 +301,7 @@ if app_mode == "Web Scraping":
|
|
| 296 |
st.header("🌐 Web Scraping")
|
| 297 |
url = st.text_input("Enter URL to scrape", "https://example.com")
|
| 298 |
if st.button("Scrape Website"):
|
| 299 |
-
if url:
|
| 300 |
with st.spinner("Scraping website..."):
|
| 301 |
result = scrape_website(url)
|
| 302 |
if result:
|
|
@@ -314,7 +319,7 @@ if app_mode == "Web Scraping":
|
|
| 314 |
else:
|
| 315 |
st.error("Failed to scrape the website. Check logs for details.")
|
| 316 |
else:
|
| 317 |
-
st.warning("Please enter a valid URL.")
|
| 318 |
|
| 319 |
elif app_mode == "Chat with Content":
|
| 320 |
st.header("💬 Chat with Scraped Content")
|
|
@@ -399,4 +404,4 @@ if st.sidebar.checkbox("Show Debug Logs"):
|
|
| 399 |
except PermissionError:
|
| 400 |
st.sidebar.error("Cannot read log file due to permission issues.")
|
| 401 |
except FileNotFoundError:
|
| 402 |
-
st.sidebar.warning("Log file not found.")
|
|
|
|
| 288 |
logging.error(f"Error answering question: {str(e)}")
|
| 289 |
return f"Error generating answer: {str(e)}"
|
| 290 |
|
| 291 |
+
def is_valid_url(url):
|
| 292 |
+
"""Validate URL format."""
|
| 293 |
+
pattern = r'^https?://[\w\-\.]+(?:\:\d+)?(?:/[\w\-\./]*)*$'
|
| 294 |
+
return bool(re.match(pattern, url))
|
| 295 |
+
|
| 296 |
# Sidebar for navigation
|
| 297 |
st.sidebar.title("Navigation")
|
| 298 |
app_mode = st.sidebar.radio("Choose a mode", ["Web Scraping", "Chat with Content", "About"])
|
|
|
|
| 301 |
st.header("🌐 Web Scraping")
|
| 302 |
url = st.text_input("Enter URL to scrape", "https://example.com")
|
| 303 |
if st.button("Scrape Website"):
|
| 304 |
+
if url and is_valid_url(url):
|
| 305 |
with st.spinner("Scraping website..."):
|
| 306 |
result = scrape_website(url)
|
| 307 |
if result:
|
|
|
|
| 319 |
else:
|
| 320 |
st.error("Failed to scrape the website. Check logs for details.")
|
| 321 |
else:
|
| 322 |
+
st.warning("Please enter a valid URL (e.g., https://example.com).")
|
| 323 |
|
| 324 |
elif app_mode == "Chat with Content":
|
| 325 |
st.header("💬 Chat with Scraped Content")
|
|
|
|
| 404 |
except PermissionError:
|
| 405 |
st.sidebar.error("Cannot read log file due to permission issues.")
|
| 406 |
except FileNotFoundError:
|
| 407 |
+
st.sidebar.warning("Log file not found.")
|