Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from googlesearch import search
|
3 |
import requests
|
@@ -6,7 +8,7 @@ from bs4 import BeautifulSoup
|
|
6 |
# Function to perform Google search and return the first link
|
7 |
def google_search(query):
|
8 |
try:
|
9 |
-
query = query + "/t site:https://
|
10 |
# Perform the search and get an iterator of results
|
11 |
search_results = search(query, num_results=10) # Get up to 10 results
|
12 |
first_link = next(search_results, None) # Get the first result
|
@@ -39,7 +41,8 @@ def scrape_text(webpage_content):
|
|
39 |
# Break multi-headlines into a line each
|
40 |
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
|
41 |
# Drop blank lines
|
42 |
-
text = '
|
|
|
43 |
return text
|
44 |
except Exception as e:
|
45 |
st.error(f"Failed to scrape text from webpage content: {e}")
|
@@ -67,11 +70,12 @@ if st.button("Search"):
|
|
67 |
# Download button for the webpage content
|
68 |
st.download_button(
|
69 |
label="Download Webpage Content",
|
70 |
-
data=
|
71 |
-
file_name="webpage_content.
|
72 |
-
mime="text/
|
73 |
)
|
74 |
else:
|
75 |
st.warning("No results found")
|
76 |
else:
|
77 |
-
st.error("Please enter a query")
|
|
|
|
1 |
+
|
2 |
+
# app.py
|
3 |
import streamlit as st
|
4 |
from googlesearch import search
|
5 |
import requests
|
|
|
8 |
# Function to perform Google search and return the first link
|
9 |
def google_search(query):
|
10 |
try:
|
11 |
+
query = query + "/t site:https://medium.com/"
|
12 |
# Perform the search and get an iterator of results
|
13 |
search_results = search(query, num_results=10) # Get up to 10 results
|
14 |
first_link = next(search_results, None) # Get the first result
|
|
|
41 |
# Break multi-headlines into a line each
|
42 |
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
|
43 |
# Drop blank lines
|
44 |
+
text = '
|
45 |
+
'.join(chunk for chunk in chunks if chunk)
|
46 |
return text
|
47 |
except Exception as e:
|
48 |
st.error(f"Failed to scrape text from webpage content: {e}")
|
|
|
70 |
# Download button for the webpage content
|
71 |
st.download_button(
|
72 |
label="Download Webpage Content",
|
73 |
+
data=scraped_text,
|
74 |
+
file_name="webpage_content.txt",
|
75 |
+
mime="text/plain"
|
76 |
)
|
77 |
else:
|
78 |
st.warning("No results found")
|
79 |
else:
|
80 |
+
st.error("Please enter a query")
|
81 |
+
|