Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ all_langs = {iso[0]: (iso[1], iso[2], iso[3]) for iso in non_empty_isos} # {'Rom
|
|
| 10 |
iso1toall = {iso[1]: (iso[0], iso[2], iso[3]) for iso in non_empty_isos} # {'ro': ('Romanian', 'rum', 'ron')}
|
| 11 |
DEFAULTS = None
|
| 12 |
|
| 13 |
-
libraries = ["langdetect", "
|
| 14 |
|
| 15 |
def timer(func):
|
| 16 |
from time import time
|
|
@@ -21,7 +21,7 @@ def timer(func):
|
|
| 21 |
execution_time = end_time - start_time
|
| 22 |
# print(f"Function {func.__name__!r} executed in {execution_time:.2f} seconds.")
|
| 23 |
execution_times = f'Executed in {execution_time:.2f} seconds!'
|
| 24 |
-
return detected_lang, confidence, execution_times
|
| 25 |
return detection
|
| 26 |
|
| 27 |
class Detect():
|
|
@@ -58,7 +58,6 @@ def detect_language(input_text: str, used_libraries: list[str]) -> tuple[str, st
|
|
| 58 |
>>> detect_language("Hello world")
|
| 59 |
("en", 1.0)
|
| 60 |
"""
|
| 61 |
-
print(used_libraries)
|
| 62 |
detectinstance = Detect(input_text)
|
| 63 |
detections = []
|
| 64 |
if 'langdetect' in used_libraries:
|
|
@@ -69,6 +68,7 @@ def detect_language(input_text: str, used_libraries: list[str]) -> tuple[str, st
|
|
| 69 |
langcode, confidence_score = detectinstance.langid()
|
| 70 |
listtoappend = [langcode, confidence_score]
|
| 71 |
detections.append(listtoappend)
|
|
|
|
| 72 |
return detections
|
| 73 |
|
| 74 |
with gr.Blocks() as interface:
|
|
@@ -79,7 +79,7 @@ with gr.Blocks() as interface:
|
|
| 79 |
# detected_text = gr.Textbox(label="Detected language:", placeholder="Display field for detected language", interactive=False, buttons=["copy"], lines=1)
|
| 80 |
# confidence = gr.Textbox(label="Confidence:", placeholder="Display field for confidence score", interactive=False, buttons=["copy"], lines=1)
|
| 81 |
# execution_time = gr.Textbox(label="Execution time:", placeholder="Display field for execution time", interactive=False, lines=1)
|
| 82 |
-
used_libraries = gr.CheckboxGroup(choices=
|
| 83 |
dataframe = gr.Dataframe(
|
| 84 |
headers=["name", "age", "gender"],
|
| 85 |
datatype=["str", "float", "str"], # type: ignore
|
|
|
|
| 10 |
iso1toall = {iso[1]: (iso[0], iso[2], iso[3]) for iso in non_empty_isos} # {'ro': ('Romanian', 'rum', 'ron')}
|
| 11 |
DEFAULTS = None
|
| 12 |
|
| 13 |
+
libraries = ["langdetect", "langid", "Argos", "HPLT", "HPLT-OPUS", "Google"]
|
| 14 |
|
| 15 |
def timer(func):
|
| 16 |
from time import time
|
|
|
|
| 21 |
execution_time = end_time - start_time
|
| 22 |
# print(f"Function {func.__name__!r} executed in {execution_time:.2f} seconds.")
|
| 23 |
execution_times = f'Executed in {execution_time:.2f} seconds!'
|
| 24 |
+
return [detected_lang, confidence, execution_times]
|
| 25 |
return detection
|
| 26 |
|
| 27 |
class Detect():
|
|
|
|
| 58 |
>>> detect_language("Hello world")
|
| 59 |
("en", 1.0)
|
| 60 |
"""
|
|
|
|
| 61 |
detectinstance = Detect(input_text)
|
| 62 |
detections = []
|
| 63 |
if 'langdetect' in used_libraries:
|
|
|
|
| 68 |
langcode, confidence_score = detectinstance.langid()
|
| 69 |
listtoappend = [langcode, confidence_score]
|
| 70 |
detections.append(listtoappend)
|
| 71 |
+
print(detections)
|
| 72 |
return detections
|
| 73 |
|
| 74 |
with gr.Blocks() as interface:
|
|
|
|
| 79 |
# detected_text = gr.Textbox(label="Detected language:", placeholder="Display field for detected language", interactive=False, buttons=["copy"], lines=1)
|
| 80 |
# confidence = gr.Textbox(label="Confidence:", placeholder="Display field for confidence score", interactive=False, buttons=["copy"], lines=1)
|
| 81 |
# execution_time = gr.Textbox(label="Execution time:", placeholder="Display field for execution time", interactive=False, lines=1)
|
| 82 |
+
used_libraries = gr.CheckboxGroup(choices=libraries, label="Detection libraries", info="Detection libraries")
|
| 83 |
dataframe = gr.Dataframe(
|
| 84 |
headers=["name", "age", "gender"],
|
| 85 |
datatype=["str", "float", "str"], # type: ignore
|