seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,24 @@
|
|
1 |
-
import
|
2 |
-
from google.cloud import translate_v2 as translate
|
3 |
-
from google.oauth2 import service_account
|
4 |
-
from nltk import download
|
5 |
-
from nltk.tokenize import word_tokenize
|
6 |
-
from nltk.corpus import stopwords
|
7 |
-
from nltk import pos_tag
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
tokens = [word for word in tokens if word.isalnum() and word.lower() not in stopwords.words('english')]
|
19 |
-
# 품사 태깅
|
20 |
-
tagged = pos_tag(tokens)
|
21 |
-
# 명사, 고유명사, 동사 중요 키워드 추출
|
22 |
-
keywords = [word for word, tag in tagged if tag in ['NN', 'NNP', 'NNS', 'VB', 'VBD', 'VBG', 'VBN', 'VBP', 'VBZ']]
|
23 |
-
return ' '.join(keywords)
|
24 |
-
|
25 |
-
def translate_and_extract_keywords(text, api_key):
|
26 |
-
# 클라이언트 설정
|
27 |
-
credentials_info = {'type': 'service_account', 'project_id': 'your-project-id', 'private_key_id': 'your-private-key-id', 'private_key': api_key, 'client_email': 'your-service-account-email', 'client_id': 'your-client-id', 'auth_uri': 'https://accounts.google.com/o/oauth2/auth', 'token_uri': 'https://oauth2.googleapis.com/token', 'auth_provider_x509_cert_url': 'https://www.googleapis.com/oauth2/v1/certs', 'client_x509_cert_url': 'your-cert-url'}
|
28 |
-
credentials = service_account.Credentials.from_service_account_info(credentials_info)
|
29 |
-
translate_client = translate.Client(credentials=credentials)
|
30 |
-
# 입력받은 한글 문장을 영어로 번역
|
31 |
-
result = translate_client.translate(text, target_language='en')
|
32 |
-
translated_text = result['translatedText']
|
33 |
-
# 키워드 추출
|
34 |
-
return extract_keywords(translated_text)
|
35 |
-
|
36 |
-
# Gradio 인터페이스 정의
|
37 |
-
interface = gr.Interface(
|
38 |
-
fn=translate_and_extract_keywords,
|
39 |
-
inputs=[
|
40 |
-
gr.Textbox(lines=2, placeholder="한글 문장을 입력하세요..."),
|
41 |
-
gr.Textbox(label="Google Cloud API 키")
|
42 |
-
],
|
43 |
-
outputs="text",
|
44 |
-
title="한글 문장을 영어 키워드로 번역 및 추출",
|
45 |
-
description="한글 문장과 Google Cloud API 키를 입력하면, 그 의미가 포함된 영어 키워드를 추출하여 출력합니다."
|
46 |
-
)
|
47 |
-
|
48 |
-
# 애플리케이션 실행
|
49 |
-
interface.launch(share=True)
|
|
|
1 |
+
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
def fetch_high_quality_images(api_key, query, per_page=80):
|
4 |
+
url = "https://api.pexels.com/v1/search"
|
5 |
+
headers = {
|
6 |
+
"Authorization": api_key
|
7 |
+
}
|
8 |
+
params = {
|
9 |
+
"query": query,
|
10 |
+
"per_page": per_page,
|
11 |
+
"size": "large"
|
12 |
+
}
|
13 |
+
response = requests.get(url, headers=headers, params=params)
|
14 |
+
if response.status_code == 200:
|
15 |
+
images = response.json()['photos']
|
16 |
+
for image in images:
|
17 |
+
print(image['src']['original'])
|
18 |
+
else:
|
19 |
+
print("Error:", response.status_code)
|
20 |
|
21 |
+
if __name__ == "__main__":
|
22 |
+
api_key = "5woz23MGx1QrSY0WHFb0BRi29JvbXPu97Hg0xnklYgHUI8G0w23FKH62" # 여기에 Pexels API 키를 입력하세요.
|
23 |
+
query = input("검색할 이미지의 키워드를 입력하세요: ")
|
24 |
+
fetch_high_quality_images(api_key, query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|