seawolf2357 commited on
Commit
199b1c7
β€’
1 Parent(s): 3faab38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -13
app.py CHANGED
@@ -1,26 +1,48 @@
1
  import gradio as gr
2
  import requests
3
  import os
 
 
 
 
 
 
4
  # Google Custom Search API 정보
5
  API_KEY = "b1f91174137fc40bdcc7b443aebaa75b985a9f57"
6
  CX = "c01abc75e1b95483d" # μ‚¬μš©μž μ»€μŠ€ν…€ 검색 엔진 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(
@@ -32,4 +54,6 @@ iface = gr.Interface(
32
  )
33
 
34
  # μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
35
- iface.launch()
 
 
 
1
  import gradio as gr
2
  import requests
3
  import os
4
+ import logging
5
+
6
+ # λ‘œκΉ… μ„€μ •
7
+ logging.basicConfig(level=logging.DEBUG)
8
+ logger = logging.getLogger(__name__)
9
+
10
  # Google Custom Search API 정보
11
  API_KEY = "b1f91174137fc40bdcc7b443aebaa75b985a9f57"
12
  CX = "c01abc75e1b95483d" # μ‚¬μš©μž μ»€μŠ€ν…€ 검색 엔진 ID
13
 
14
  def google_search(query):
15
+ logger.info(f"Searching for query: {query}")
16
  url = f"https://www.googleapis.com/customsearch/v1?key={API_KEY}&cx={CX}&q={query}"
17
+ logger.debug(f"Request URL: {url}")
 
18
 
19
+ try:
20
+ response = requests.get(url)
21
+ response.raise_for_status() # HTTP 였λ₯˜κ°€ 있으면 μ˜ˆμ™Έλ₯Ό λ°œμƒμ‹œν‚΅λ‹ˆλ‹€.
22
+ search_results = response.json()
23
+ logger.debug(f"API Response: {search_results}")
24
+
25
+ results = []
26
+ if 'items' in search_results:
27
+ for item in search_results['items']:
28
+ title = item['title']
29
+ link = item['link']
30
+ snippet = item.get('snippet', '')
31
+ results.append(f"Title: {title}\nLink: {link}\nSnippet: {snippet}\n\n")
32
+ else:
33
+ logger.warning("No items found in search results")
34
+ if 'error' in search_results:
35
+ error_message = search_results['error']['message']
36
+ logger.error(f"API Error: {error_message}")
37
+ results.append(f"Error: {error_message}")
38
+ else:
39
+ results.append("No results found")
40
+
41
+ return '\n'.join(results)
42
 
43
+ except requests.exceptions.RequestException as e:
44
+ logger.error(f"Request failed: {e}")
45
+ return f"An error occurred: {e}"
46
 
47
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
48
  iface = gr.Interface(
 
54
  )
55
 
56
  # μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
57
+ if __name__ == "__main__":
58
+ logger.info("Starting Gradio interface")
59
+ iface.launch()