Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
β’
be9dc3f
1
Parent(s):
abd53f3
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# Google Custom Search API μ 보
|
5 |
+
API_KEY = "b1f91174137fc40bdcc7b443aebaa75b985a9f57"
|
6 |
+
CX = "YOUR_CUSTOM_SEARCH_ENGINE_ID" # μ¬μ©μ 컀μ€ν
κ²μ μμ§ ID
|
7 |
+
|
8 |
+
def google_search(query):
|
9 |
+
url = f"https://www.googleapis.com/customsearch/v1?key={API_KEY}&cx={CX}&q={query}"
|
10 |
+
response = requests.get(url)
|
11 |
+
search_results = response.json()
|
12 |
+
|
13 |
+
results = []
|
14 |
+
if 'items' in search_results:
|
15 |
+
for item in search_results['items']:
|
16 |
+
title = item['title']
|
17 |
+
link = item['link']
|
18 |
+
snippet = item.get('snippet', '')
|
19 |
+
results.append(f"Title: {title}\nLink: {link}\nSnippet: {snippet}\n\n")
|
20 |
+
else:
|
21 |
+
results.append("No results found")
|
22 |
+
|
23 |
+
return '\n'.join(results)
|
24 |
+
|
25 |
+
# Gradio μΈν°νμ΄μ€ μ€μ
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=google_search,
|
28 |
+
inputs="text",
|
29 |
+
outputs="text",
|
30 |
+
title="Google Custom Search",
|
31 |
+
description="Enter a search query to get results from Google Custom Search API."
|
32 |
+
)
|
33 |
+
|
34 |
+
# μΈν°νμ΄μ€ μ€ν
|
35 |
+
iface.launch()
|