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