honey90 commited on
Commit
693e2e0
โ€ข
1 Parent(s): 176d00f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
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()