Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from serpapi import GoogleSearch
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def search_images(query):
|
5 |
+
params = {
|
6 |
+
"engine": "google",
|
7 |
+
"q": query,
|
8 |
+
"tbm": "isch", # ์ด๋ฏธ์ง ๊ฒ์์ ์ํ ํ๋ผ๋ฏธํฐ
|
9 |
+
"api_key": "56b76bc0db7f66e70958810f3486e99a7ad4fc9b4ad0719e34478b20d2f7ec4f"
|
10 |
+
}
|
11 |
+
|
12 |
+
search = GoogleSearch(params)
|
13 |
+
results = search.get_dict()
|
14 |
+
images_results = results.get("images_results", [])
|
15 |
+
|
16 |
+
# ์ด๋ฏธ์ง URL๋ง ์ถ์ถ
|
17 |
+
images_urls = [image["thumbnail"] for image in images_results]
|
18 |
+
|
19 |
+
return images_urls
|
20 |
+
|
21 |
+
# Gradio ์ธํฐํ์ด์ค ์ค์
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=search_images,
|
24 |
+
inputs=gr.Textbox(lines=2, placeholder="๊ฒ์ํ ํค์๋๋ฅผ ์
๋ ฅํ์ธ์..."),
|
25 |
+
outputs=gr.Gallery(label="๊ฒ์ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง"),
|
26 |
+
title="SerpAPI ์ด๋ฏธ์ง ๊ฒ์",
|
27 |
+
description="์
๋ ฅํ ํค์๋์ ๋ํ ์ด๋ฏธ์ง ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ค๋๋ค."
|
28 |
+
)
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
iface.launch()
|