seawolf2357 commited on
Commit
0c4b9a7
โ€ข
1 Parent(s): 91e1c1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -47
app.py CHANGED
@@ -1,49 +1,24 @@
1
- import gradio as gr
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
- # nltk ๋ฐ์ดํ„ฐ ๋‹ค์šด๋กœ๋“œ
10
- download('punkt')
11
- download('averaged_perceptron_tagger')
12
- download('stopwords')
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- def extract_keywords(text):
15
- # ์˜์–ด ํ…์ŠคํŠธ๋ฅผ ํ† ํฐํ™”
16
- tokens = word_tokenize(text)
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)