Spaces:
Sleeping
Sleeping
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() |