Spaces:
Sleeping
Sleeping
File size: 1,198 Bytes
f8426cc 7559b37 f8426cc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import gradio as gr
from serpapi import GoogleSearch # μμ λ λΆλΆμ΄ μμΌλ, μ΄λ λ¬Έμ μ μμΈμ μ νν νμ
νκΈ° μν μμμ
λλ€.
# SERP API ν€ μ€μ
API_KEY = "facc404e1b9394771101069c8ea6984719db4b437136cb33f7935e67dad7093f"
def search_and_show_image(query):
params = {
"engine": "google",
"q": query,
"api_key": API_KEY,
"google_domain": "google.com",
"gl": "us",
"hl": "en"
}
search = GoogleSearch(params)
results = search.get_dict()
organic_results = results.get("organic_results", [])
if organic_results:
first_result = organic_results[0]
screenshot_url = first_result.get("screenshot", {}).get("src", "No screenshot available for this result.")
return screenshot_url
else:
return "No results found."
# Gradio μΈν°νμ΄μ€ ꡬμ±
with gr.Blocks() as demo:
with gr.Row():
query_input = gr.Textbox(label="κ²μμ΄ μ
λ ₯")
submit_button = gr.Button("κ²μ")
image_output = gr.Image()
submit_button.click(search_and_show_image, inputs=query_input, outputs=image_output)
# Gradio μ± μ€ν
demo.launch() |