File size: 958 Bytes
693e2e0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from serpapi import GoogleSearch
import gradio as gr
def search_images(query):
params = {
"engine": "google",
"q": query,
"tbm": "isch", # ์ด๋ฏธ์ง ๊ฒ์์ ์ํ ํ๋ผ๋ฏธํฐ
"api_key": "56b76bc0db7f66e70958810f3486e99a7ad4fc9b4ad0719e34478b20d2f7ec4f"
}
search = GoogleSearch(params)
results = search.get_dict()
images_results = results.get("images_results", [])
# ์ด๋ฏธ์ง URL๋ง ์ถ์ถ
images_urls = [image["thumbnail"] for image in images_results]
return images_urls
# Gradio ์ธํฐํ์ด์ค ์ค์
iface = gr.Interface(
fn=search_images,
inputs=gr.Textbox(lines=2, placeholder="๊ฒ์ํ ํค์๋๋ฅผ ์
๋ ฅํ์ธ์..."),
outputs=gr.Gallery(label="๊ฒ์ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง"),
title="SerpAPI ์ด๋ฏธ์ง ๊ฒ์",
description="์
๋ ฅํ ํค์๋์ ๋ํ ์ด๋ฏธ์ง ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ค๋๋ค."
)
if __name__ == "__main__":
iface.launch() |