| | import gradio as gr |
| | import requests |
| | from bs4 import BeautifulSoup |
| | import re |
| |
|
| | def search_image(query): |
| | |
| | url = f"https://www.google.com/search?hl=en&tbm=isch&q={query}" |
| | headers = { |
| | "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" |
| | } |
| | response = requests.get(url, headers=headers) |
| |
|
| | |
| | soup = BeautifulSoup(response.text, 'html.parser') |
| |
|
| | |
| | image_tags = soup.find_all("img") |
| |
|
| | |
| | image_urls = [] |
| | for img in image_tags: |
| | img_url = img.get("src") |
| | if img_url and img_url.startswith("http"): |
| | |
| | image_urls.append(img_url) |
| |
|
| | |
| | return image_urls[:5] |
| |
|
| | |
| | iface = gr.Interface( |
| | fn=search_image, |
| | inputs=gr.Textbox(placeholder="Type something to search for..."), |
| | outputs=gr.Gallery(label="Search Results", show_label=True), |
| | title="HD Image Search", |
| | description="Type in a search term to find HD images." |
| | ) |
| |
|
| | |
| | iface.launch() |
| |
|