Update app.py
Browse files
app.py
CHANGED
|
@@ -32,6 +32,12 @@ def langdetect(input_text):
|
|
| 32 |
langecode_probabilities: list[Language] = detect_langs(input_text)
|
| 33 |
return langcode, round(number=langecode_probabilities[0].prob * 100, ndigits=2)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
@timer
|
| 36 |
def detect_language(input_text: str, used_libraries: list[str]) -> tuple[str, str]:
|
| 37 |
"""
|
|
@@ -53,10 +59,12 @@ def detect_language(input_text: str, used_libraries: list[str]) -> tuple[str, st
|
|
| 53 |
detections = []
|
| 54 |
if 'langdetect' in used_libraries:
|
| 55 |
langcode, confidence_score = langdetect(input_text)
|
| 56 |
-
|
|
|
|
| 57 |
if 'langid' in used_libraries:
|
| 58 |
-
langcode, confidence_score =
|
| 59 |
-
|
|
|
|
| 60 |
return detections
|
| 61 |
|
| 62 |
with gr.Blocks() as interface:
|
|
|
|
| 32 |
langecode_probabilities: list[Language] = detect_langs(input_text)
|
| 33 |
return langcode, round(number=langecode_probabilities[0].prob * 100, ndigits=2)
|
| 34 |
|
| 35 |
+
def langid(self) -> tuple[str, float]:
|
| 36 |
+
import langid
|
| 37 |
+
result: tuple[str, float] = langid.classify(self.text)
|
| 38 |
+
langcode, langecode_probabilities = result
|
| 39 |
+
return langcode, round(number=langecode_probabilities * 10, ndigits=2)
|
| 40 |
+
|
| 41 |
@timer
|
| 42 |
def detect_language(input_text: str, used_libraries: list[str]) -> tuple[str, str]:
|
| 43 |
"""
|
|
|
|
| 59 |
detections = []
|
| 60 |
if 'langdetect' in used_libraries:
|
| 61 |
langcode, confidence_score = langdetect(input_text)
|
| 62 |
+
tupletoappend = langcode, confidence_score
|
| 63 |
+
detections.append(tupletoappend)
|
| 64 |
if 'langid' in used_libraries:
|
| 65 |
+
langcode, confidence_score = langid(input_text)
|
| 66 |
+
tupletoappend = langcode, confidence_score
|
| 67 |
+
detections.append(tupletoappend)
|
| 68 |
return detections
|
| 69 |
|
| 70 |
with gr.Blocks() as interface:
|