Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from serpapi import GoogleSearch
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# SERP API 키 설정
|
5 |
+
API_KEY = "facc404e1b9394771101069c8ea6984719db4b437136cb33f7935e67dad7093f"
|
6 |
+
|
7 |
+
def search_and_show_image(query):
|
8 |
+
params = {
|
9 |
+
"engine": "google",
|
10 |
+
"q": query,
|
11 |
+
"api_key": API_KEY,
|
12 |
+
"google_domain": "google.com",
|
13 |
+
"gl": "us",
|
14 |
+
"hl": "en"
|
15 |
+
}
|
16 |
+
|
17 |
+
search = GoogleSearch(params)
|
18 |
+
results = search.get_dict()
|
19 |
+
organic_results = results.get("organic_results", [])
|
20 |
+
|
21 |
+
if organic_results:
|
22 |
+
# 첫 번째 검색 결과의 스크린샷 이미지 URL을 가져옵니다.
|
23 |
+
# 스크린샷 이미지가 없는 경우, 대체 텍스트를 반환합니다.
|
24 |
+
first_result = organic_results[0]
|
25 |
+
screenshot_url = first_result.get("screenshot", {}).get("src", "No screenshot available for this result.")
|
26 |
+
return screenshot_url
|
27 |
+
else:
|
28 |
+
return "No results found."
|
29 |
+
|
30 |
+
# Gradio 인터페이스 구성
|
31 |
+
with gr.Blocks() as demo:
|
32 |
+
with gr.Row():
|
33 |
+
query_input = gr.Textbox(label="검색어 입력")
|
34 |
+
submit_button = gr.Button("검색")
|
35 |
+
image_output = gr.Image()
|
36 |
+
|
37 |
+
submit_button.click(search_and_show_image, inputs=query_input, outputs=image_output)
|
38 |
+
|
39 |
+
# Gradio 앱 실행
|
40 |
+
demo.launch()
|