Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
β’
bb2db31
1
Parent(s):
21048e8
Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,32 @@
|
|
1 |
-
# gradio λΌμ΄λΈλ¬λ¦¬λ₯Ό gr λ³μΉμΌλ‘ μν¬νΈν©λλ€.
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
import
|
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 |
-
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|