seawolf2357 commited on
Commit
be9dc3f
β€’
1 Parent(s): abd53f3

Create app.py

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