vinsensius13 commited on
Commit
8cc2b5c
·
1 Parent(s): 13ddba0

komit terbakar

Browse files
Files changed (3) hide show
  1. .gitignore +53 -0
  2. __pycache__/main.cpython-310.pyc +0 -0
  3. main.py +26 -9
.gitignore ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.so
5
+ *.egg
6
+ *.egg-info/
7
+ dist/
8
+ build/
9
+ *.log
10
+
11
+ # Env & Secrets
12
+ .env
13
+ *.env
14
+ venv/
15
+ .venv/
16
+ env/
17
+ ENV/
18
+ *.sqlite3
19
+ *.db
20
+ *.pkl
21
+
22
+ # macOS
23
+ .DS_Store
24
+
25
+ # VSCode
26
+ .vscode/
27
+ .history/
28
+
29
+ # System Files
30
+ Thumbs.db
31
+ desktop.ini
32
+
33
+ # Audio & TTS Output
34
+ *.mp3
35
+ *.wav
36
+ *.ogg
37
+
38
+ # Temporary
39
+ *.tmp
40
+ *.bak
41
+ *.swp
42
+ *.swo
43
+ *.old
44
+ *.zip
45
+ *.tar.gz
46
+ *.tar
47
+ *.rar
48
+
49
+ # PyInstaller
50
+ *.spec
51
+
52
+ # Jupyter Notebook
53
+ .ipynb_checkpoints/
__pycache__/main.cpython-310.pyc DELETED
Binary file (2.24 kB)
 
main.py CHANGED
@@ -54,6 +54,14 @@ def force_teinei_form(japanese_text: str) -> str:
54
  def convert_to_string(text) -> str:
55
  return str(text) if not isinstance(text, str) else text
56
 
 
 
 
 
 
 
 
 
57
  @app.post("/translate_and_analyze")
58
  async def translate_and_analyze(request: TranslateRequest):
59
  text = convert_to_string(request.text)
@@ -83,17 +91,26 @@ async def translate_and_analyze(request: TranslateRequest):
83
 
84
  romaji_list = []
85
  breakdown = []
 
86
  for token in tokenizer_obj.tokenize(japanese_text, tokenizer.Tokenizer.SplitMode.C):
87
  surface = token.surface()
88
- reading = token.reading_form()
89
- hira = jaconv.kata2hira(reading)
90
- romaji = jaconv.kana2alphabet(hira)
91
- romaji_list.append(romaji)
92
- breakdown.append({
93
- "surface": surface,
94
- "furigana": hira,
95
- "romaji": romaji
96
- })
 
 
 
 
 
 
 
 
97
 
98
  romaji_output = " ".join(romaji_list)
99
 
 
54
  def convert_to_string(text) -> str:
55
  return str(text) if not isinstance(text, str) else text
56
 
57
+ # 🧠 Cek numerik (buat filtering furigana/romaji)
58
+ def is_number(text):
59
+ try:
60
+ float(text.replace(",", "").replace(".", ".").replace("・", ".")) # handle 15.00 dan simbol aneh
61
+ return True
62
+ except ValueError:
63
+ return False
64
+
65
  @app.post("/translate_and_analyze")
66
  async def translate_and_analyze(request: TranslateRequest):
67
  text = convert_to_string(request.text)
 
91
 
92
  romaji_list = []
93
  breakdown = []
94
+
95
  for token in tokenizer_obj.tokenize(japanese_text, tokenizer.Tokenizer.SplitMode.C):
96
  surface = token.surface()
97
+ if is_number(surface):
98
+ breakdown.append({
99
+ "surface": surface,
100
+ "furigana": "",
101
+ "romaji": ""
102
+ })
103
+ romaji_list.append(surface)
104
+ else:
105
+ reading = token.reading_form()
106
+ hira = jaconv.kata2hira(reading)
107
+ romaji = jaconv.kana2alphabet(hira)
108
+ breakdown.append({
109
+ "surface": surface,
110
+ "furigana": hira,
111
+ "romaji": romaji
112
+ })
113
+ romaji_list.append(romaji)
114
 
115
  romaji_output = " ".join(romaji_list)
116