copy / app.py
seawolf2357's picture
Update app.py
950f87c verified
raw
history blame
1.1 kB
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()