File size: 1,097 Bytes
145ad7d
bb2db31
 
 
 
 
3bd6490
bb2db31
 
 
 
be3c345
bb2db31
 
 
be3c345
bb2db31
950f87c
 
bb2db31
 
 
69c569f
950f87c
bb2db31
950f87c
bb2db31
 
 
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
import gradio as gr
import requests

# ๊ตฌ๊ธ€ ์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰ ํ•จ์ˆ˜
def google_image_search(query):
    API_KEY = 'AIzaSyDUz3wkGal0ewRtPlzeMit88bV4hS4ZIVY'
    CX = '56b34994f47704ddd'
    URL = f"https://www.googleapis.com/customsearch/v1?q={query}&cx={CX}&searchType=image&key={API_KEY}"
    
    response = requests.get(URL)
    results = response.json()
    image_urls = []

    for item in results.get('items', []):
        image_url = item['link']
        image_urls.append(image_url)

    # ์ด๋ฏธ์ง€ URL ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜
    return "\n".join(image_urls)

# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
iface = gr.Interface(fn=google_image_search, 
                     inputs=gr.Textbox(lines=2, placeholder="๊ฒ€์ƒ‰ํ•  ์ด๋ฏธ์ง€์˜ ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”..."),
                     outputs=gr.Textbox(label="๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ URL"),              
                     title="๊ตฌ๊ธ€ ์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰",
                     description="ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ตฌ๊ธ€ ์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์˜ ์ด๋ฏธ์ง€ URL์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.")

# ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
iface.launch()