Brad Duy
commited on
Commit
·
324e2af
1
Parent(s):
ac58be2
modify code for naver api
Browse files
app.py
CHANGED
|
@@ -1,7 +1,29 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
|
| 4 |
+
# Your Naver Papago API credentials
|
| 5 |
+
NAVER_CLIENT_ID = "YOUR_CLIENT_ID"
|
| 6 |
+
NAVER_CLIENT_SECRET = "YOUR_CLIENT_SECRET"
|
| 7 |
|
| 8 |
+
def translate_with_papago(text):
|
| 9 |
+
url = "https://openapi.naver.com/v1/papago/n2mt"
|
| 10 |
+
headers = {
|
| 11 |
+
"X-Naver-Client-Id": NAVER_CLIENT_ID,
|
| 12 |
+
"X-Naver-Client-Secret": NAVER_CLIENT_SECRET
|
| 13 |
+
}
|
| 14 |
+
data = {
|
| 15 |
+
"source": "en",
|
| 16 |
+
"target": "ko",
|
| 17 |
+
"text": text
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
response = requests.post(url, headers=headers, data=data)
|
| 21 |
+
result = response.json()
|
| 22 |
+
|
| 23 |
+
if "message" in result:
|
| 24 |
+
return result["message"]["result"]["translatedText"]
|
| 25 |
+
else:
|
| 26 |
+
return "❌ API Error: " + str(result)
|
| 27 |
+
|
| 28 |
+
demo = gr.Interface(fn=translate_with_papago, inputs="text", outputs="text")
|
| 29 |
demo.launch()
|