Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,34 +1,30 @@
|
|
| 1 |
|
| 2 |
# app.py
|
| 3 |
import streamlit as st
|
| 4 |
-
from
|
| 5 |
-
import requests
|
| 6 |
-
from urllib.parse import urljoin, urlparse
|
| 7 |
|
|
|
|
| 8 |
def google_search(query):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
for link in links:
|
| 14 |
-
href = link.get('href')
|
| 15 |
-
if href and href.startswith('/url?q='):
|
| 16 |
-
return href.split('&sa=U&ved=')[0].replace('/url?q=', '')
|
| 17 |
-
return None
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
return response.text
|
| 22 |
|
| 23 |
-
|
| 24 |
-
query = st.text_input("Enter
|
|
|
|
|
|
|
| 25 |
if st.button("Search"):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
st.
|
| 32 |
else:
|
| 33 |
-
st.
|
|
|
|
| 34 |
|
|
|
|
| 1 |
|
| 2 |
# app.py
|
| 3 |
import streamlit as st
|
| 4 |
+
from googlesearch import search
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# Function to perform Google search and return the first link
|
| 7 |
def google_search(query):
|
| 8 |
+
# Perform the search and get the first result
|
| 9 |
+
search_results = search(query, num=1, stop=1)
|
| 10 |
+
first_link = next(search_results, None)
|
| 11 |
+
return first_link
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Streamlit app UI
|
| 14 |
+
st.title("Google Search First Link Finder")
|
|
|
|
| 15 |
|
| 16 |
+
# Input field for search query
|
| 17 |
+
query = st.text_input("Enter search query", "")
|
| 18 |
+
|
| 19 |
+
# Button to trigger search
|
| 20 |
if st.button("Search"):
|
| 21 |
+
if query:
|
| 22 |
+
first_link = google_search(query)
|
| 23 |
+
if first_link:
|
| 24 |
+
st.success(f"First link: [Click here]({first_link})")
|
| 25 |
+
else:
|
| 26 |
+
st.warning("No results found")
|
| 27 |
else:
|
| 28 |
+
st.error("Please enter a query")
|
| 29 |
+
|
| 30 |
|