File size: 958 Bytes
4db852d
f8426cc
 
4db852d
f8426cc
 
 
4db852d
501630f
f8426cc
 
 
 
4db852d
f8426cc
4db852d
 
f8426cc
4db852d
 
 
 
 
 
 
 
 
 
f8426cc
4db852d
 
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": "facc404e1b9394771101069c8ea6984719db4b437136cb33f7935e67dad7093f"
    }
    
    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()