Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -43,33 +43,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet")) as demo:
|
|
43 |
|
44 |
demo.launch()
|
45 |
|
46 |
-
scarper.py:
|
47 |
-
import requests
|
48 |
-
from bs4 import BeautifulSoup
|
49 |
-
from urllib.parse import urljoin
|
50 |
-
|
51 |
-
def scrape_url(url):
|
52 |
-
"""Fetch text + image URLs from webpage."""
|
53 |
-
try:
|
54 |
-
res = requests.get(url, timeout=10)
|
55 |
-
res.raise_for_status()
|
56 |
-
soup = BeautifulSoup(res.text, 'html.parser')
|
57 |
-
|
58 |
-
# get text
|
59 |
-
text = soup.get_text(separator='\n', strip=True)
|
60 |
-
|
61 |
-
# get image URLs (absolute)
|
62 |
-
images = []
|
63 |
-
for img in soup.find_all('img'):
|
64 |
-
src = img.get('src')
|
65 |
-
if src:
|
66 |
-
images.append(urljoin(url, src))
|
67 |
-
|
68 |
-
return text, images
|
69 |
-
except Exception as e:
|
70 |
-
return f"[Error scraping {url}: {e}]", []
|
71 |
-
|
72 |
-
|
73 |
from googlesearch import search
|
74 |
|
75 |
def search_google(query, num_results=5):
|
|
|
43 |
|
44 |
demo.launch()
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
from googlesearch import search
|
47 |
|
48 |
def search_google(query, num_results=5):
|