honey90 commited on
Commit
e66515a
โ€ข
1 Parent(s): 49a833b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from googletrans import Translator
3
+
4
+ # Hugging Face API ํ† ํฐ ์„ค์ •
5
+ hf_token = "YOUR_HUGGING_FACE_TOKEN"
6
+
7
+ # Google Translate ์ค€๋น„
8
+ translator = Translator()
9
+
10
+ # Hugging Face์—์„œ ์ธ๊ธฐ ์žˆ๋Š” space ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ
11
+ def fetch_popular_spaces():
12
+ headers = {"Authorization": f"Bearer {hf_token}"}
13
+ response = requests.get("HUGGING_FACE_API_ENDPOINT", headers=headers)
14
+ spaces_data = response.json()
15
+
16
+ # ์—ฌ๊ธฐ์„œ๋Š” ๊ฐ€์ƒ์˜ API ์—”๋“œํฌ์ธํŠธ์™€ ์‘๋‹ต ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
17
+ popular_spaces = spaces_data['spaces'][:20] # ์ƒ์œ„ 20๊ฐœ space ์„ ํƒ
18
+
19
+ translated_spaces = []
20
+ for space in popular_spaces:
21
+ # Space ์„ค๋ช…์„ ํ•œ๊ธ€๋กœ ๋ฒˆ์—ญ
22
+ translated_desc = translator.translate(space['description'], dest='ko').text
23
+ translated_spaces.append({
24
+ 'name': space['name'],
25
+ 'description_ko': translated_desc
26
+ })
27
+
28
+ return translated_spaces
29
+
30
+ # ๊ฒฐ๊ณผ ์ถœ๋ ฅ
31
+ if __name__ == "__main__":
32
+ popular_spaces = fetch_popular_spaces()
33
+ for space in popular_spaces:
34
+ print(f"Space ์ด๋ฆ„: {space['name']}, ์„ค๋ช…: {space['description_ko']}")