seawolf2357 commited on
Commit
bb2db31
β€’
1 Parent(s): 21048e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -45
app.py CHANGED
@@ -1,46 +1,32 @@
1
- # gradio 라이브러리λ₯Ό gr λ³„μΉ­μœΌλ‘œ μž„ν¬νŠΈν•©λ‹ˆλ‹€.
2
  import gradio as gr
3
- from gradio_client import Client
4
- import httpx
5
-
6
- # Client 객체 생성 μ‹œ timeout λ§€κ°œλ³€μˆ˜ 제거
7
- client = Client("seawolf2357/sajuice")
8
-
9
-
10
-
11
-
12
- # νƒ€μž„μ•„μ›ƒ 값을 초 λ‹¨μœ„λ‘œ μ„€μ •ν•©λ‹ˆλ‹€. 예: 읽기 νƒ€μž„μ•„μ›ƒμ„ 30초둜 μ„€μ •
13
- timeout_config = httpx.Timeout(5.0, read=30.0)
14
-
15
- try:
16
- # μˆ˜μ •λœ νƒ€μž„μ•„μ›ƒ 섀정을 μ μš©ν•˜μ—¬ ν΄λΌμ΄μ–ΈνŠΈλ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
17
- client = Client("arxivgpt/sajutest", timeout=timeout_config)
18
- print("ν΄λΌμ΄μ–ΈνŠΈκ°€ μ„±κ³΅μ μœΌλ‘œ μƒμ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
19
- except httpx.ReadTimeout:
20
- print("μš”μ²­ μ‹œκ°„ 초과: μ„œλ²„κ°€ μ§€μ •λœ μ‹œκ°„ 내에 μ‘λ‹΅ν•˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.")
21
- except Exception as e:
22
- print(f"μ˜ˆμƒμΉ˜ λͺ»ν•œ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}")
23
-
24
-
25
- def call_api(생년, 생월, 생일, μƒμ‹œ):
26
- # APIλ₯Ό ν˜ΈμΆœν•˜κ³  응닡값을 λ°›μŠ΅λ‹ˆλ‹€.
27
- result = client.predict(
28
- 생년, # '생년(예: 1990)'에 λŒ€ν•œ μž…λ ₯κ°’
29
- 생월, # '생월(예: 01)'에 λŒ€ν•œ μž…λ ₯κ°’
30
- 생일, # '생일(예: 31)'에 λŒ€ν•œ μž…λ ₯κ°’
31
- μƒμ‹œ, # 'μƒμ‹œ(μ˜ˆμ‹œ: 1030)'에 λŒ€ν•œ μž…λ ₯κ°’
32
- api_name="/get_lunar_info"
33
- )
34
- return result
35
-
36
- # Gradio μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ •μ˜ν•©λ‹ˆλ‹€.
37
- inputs = [
38
- gr.Textbox(label="생년(예: 1990)"),
39
- gr.Textbox(label="생월(예: 01)"),
40
- gr.Textbox(label="생일(예: 31)"),
41
- gr.Textbox(label="μƒμ‹œ(μ˜ˆμ‹œ: 1030)")
42
- ]
43
- outputs = gr.Textbox(label="κ²°κ³Ό")
44
-
45
- # μΈν„°νŽ˜μ΄μŠ€λ₯Ό μƒμ„±ν•˜κ³  μ‹€ν–‰ν•©λ‹ˆλ‹€.
46
- gr.Interface(fn=call_api, inputs=inputs, outputs=outputs, title="Get Lunar Info").launch()
 
 
1
  import gradio as gr
2
+ import requests
3
+ from PIL import Image
4
+ from io import BytesIO
5
+
6
+ # ꡬ글 이미지 검색 ν•¨μˆ˜
7
+ def google_image_search(query):
8
+ API_KEY = 'AIzaSyDUz3wkGal0ewRtPlzeMit88bV4hS4ZIVY'
9
+ CX = '여기에_λ‹Ήμ‹ μ˜_μ»€μŠ€ν…€_검색엔진_IDλ₯Ό_μž…λ ₯ν•˜μ„Έμš”'
10
+ URL = f"https://www.googleapis.com/customsearch/v1?q={query}&cx={CX}&searchType=image&key={API_KEY}"
11
+
12
+ response = requests.get(URL)
13
+ results = response.json()
14
+ images = []
15
+
16
+ for item in results.get('items', []):
17
+ image_url = item['link']
18
+ response = requests.get(image_url)
19
+ img = Image.open(BytesIO(response.content))
20
+ images.append(img)
21
+
22
+ return images
23
+
24
+ # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
25
+ iface = gr.Interface(fn=google_image_search,
26
+ inputs=gr.inputs.Textbox(lines=2, placeholder="검색할 μ΄λ―Έμ§€μ˜ ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜μ„Έμš”..."),
27
+ outputs=gr.outputs.Image(type="pil", label="검색 κ²°κ³Ό"),
28
+ title="ꡬ글 이미지 검색",
29
+ description="ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜λ©΄ ꡬ글 이미지 검색 κ²°κ³Όλ₯Ό λ³΄μ—¬μ€λ‹ˆλ‹€.")
30
+
31
+ # μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
32
+ iface.launch()