aiqtest2 / 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()