Spaces:
Sleeping
Sleeping
File size: 1,125 Bytes
145ad7d bb2db31 3bd6490 bb2db31 69c569f 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 30 31 32 |
import gradio as gr
import requests
from PIL import Image
from io import BytesIO
# 구글 이미지 검색 함수
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()
images = []
for item in results.get('items', []):
image_url = item['link']
response = requests.get(image_url)
img = Image.open(BytesIO(response.content))
images.append(img)
return images
# Gradio 인터페이스 정의
iface = gr.Interface(fn=google_image_search,
inputs=gr.Textbox(lines=2, placeholder="검색할 이미지의 텍스트를 입력하세요..."),
outputs=gr.outputs.Image(type="pil", label="검색 결과"),
title="구글 이미지 검색",
description="텍스트를 입력하면 구글 이미지 검색 결과를 보여줍니다.")
# 인터페이스 실행
iface.launch() |