- app.py +8 -6
- requirements.txt +1 -2
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
from datasets import load_dataset
|
| 4 |
-
from
|
| 5 |
from huggingface_hub import login
|
| 6 |
import os
|
| 7 |
|
|
@@ -38,15 +38,17 @@ def load_and_process_data():
|
|
| 38 |
category_counts = pd.Series()
|
| 39 |
|
| 40 |
# --- 翻訳関数 ---
|
| 41 |
-
translator = Translator()
|
| 42 |
def translate_text(text, dest_lang='ja'):
|
|
|
|
| 43 |
if not text or not isinstance(text, str):
|
| 44 |
return ""
|
| 45 |
try:
|
| 46 |
-
#
|
| 47 |
-
|
|
|
|
| 48 |
except Exception as e:
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
# --- Gradioイベントハンドラ ---
|
| 52 |
def on_category_change(selected_category):
|
|
@@ -150,4 +152,4 @@ def create_demo():
|
|
| 150 |
# --- アプリケーション起動 ---
|
| 151 |
if __name__ == "__main__":
|
| 152 |
app = create_demo()
|
| 153 |
-
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
from datasets import load_dataset
|
| 4 |
+
from deep_translator import GoogleTranslator
|
| 5 |
from huggingface_hub import login
|
| 6 |
import os
|
| 7 |
|
|
|
|
| 38 |
category_counts = pd.Series()
|
| 39 |
|
| 40 |
# --- 翻訳関数 ---
|
|
|
|
| 41 |
def translate_text(text, dest_lang='ja'):
|
| 42 |
+
"""テキストを翻訳します"""
|
| 43 |
if not text or not isinstance(text, str):
|
| 44 |
return ""
|
| 45 |
try:
|
| 46 |
+
# GoogleTranslatorを使用(deep-translator)
|
| 47 |
+
translator = GoogleTranslator(source='auto', target=dest_lang)
|
| 48 |
+
return translator.translate(text)
|
| 49 |
except Exception as e:
|
| 50 |
+
print(f"翻訳エラー: {e}")
|
| 51 |
+
return f"翻訳エラー: {str(e)}"
|
| 52 |
|
| 53 |
# --- Gradioイベントハンドラ ---
|
| 54 |
def on_category_change(selected_category):
|
|
|
|
| 152 |
# --- アプリケーション起動 ---
|
| 153 |
if __name__ == "__main__":
|
| 154 |
app = create_demo()
|
| 155 |
+
app.launch()
|
requirements.txt
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
gradio
|
| 2 |
datasets
|
| 3 |
pandas
|
| 4 |
-
|
| 5 |
-
httpcore==0.18.0
|
| 6 |
huggingface_hub
|
|
|
|
| 1 |
gradio
|
| 2 |
datasets
|
| 3 |
pandas
|
| 4 |
+
deep-translator
|
|
|
|
| 5 |
huggingface_hub
|