TiberiuCristianLeon commited on
Commit
426e257
·
verified ·
1 Parent(s): c30b240

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -24,6 +24,14 @@ def timer(func):
24
  return detected_lang, confidence, execution_times
25
  return detection
26
 
 
 
 
 
 
 
 
 
27
  @timer
28
  def detect_language(input_text: str, used_libraries: list[str]) -> tuple[str, str]:
29
  """
@@ -41,13 +49,15 @@ def detect_language(input_text: str, used_libraries: list[str]) -> tuple[str, st
41
  >>> detect_language("Hello world")
42
  ("en", 1.0)
43
  """
44
- from langdetect import detect, detect_langs
45
- from langdetect import DetectorFactory
46
  print(used_libraries)
47
- DetectorFactory.seed = 0
48
- langcode = detect(input_text)
49
- langecode_probabilities: list[Language] = detect_langs(input_text)
50
- return langcode, round(number=langecode_probabilities[0].prob * 100, ndigits=2)
 
 
 
 
51
 
52
  with gr.Blocks() as interface:
53
  gr.Markdown("### Language Detection with Gradio API and MCP Server")
@@ -57,7 +67,7 @@ with gr.Blocks() as interface:
57
  detected_text = gr.Textbox(label="Translated text:", placeholder="Display field for translation", interactive=False, buttons=["copy"], lines=1)
58
  confidence = gr.Textbox(label="Confidence:", placeholder="Display field for confidence score", interactive=False, buttons=["copy"], lines=1)
59
  execution_time = gr.Textbox(label="Execution time:", placeholder="Display field for execution time", interactive=False, lines=1)
60
- used_libraries = gr.CheckboxGroup(choices=["langdetect", "X", "XX"], label="Detection libraries", info="Detection libraries")
61
  input_text.submit(
62
  fn=detect_language,
63
  inputs=[input_text, used_libraries],
 
24
  return detected_lang, confidence, execution_times
25
  return detection
26
 
27
+ def langdetect(input_text):
28
+ from langdetect import detect, detect_langs
29
+ from langdetect import DetectorFactory
30
+ DetectorFactory.seed = 0
31
+ langcode = detect(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
  """
 
49
  >>> detect_language("Hello world")
50
  ("en", 1.0)
51
  """
 
 
52
  print(used_libraries)
53
+ detections = []
54
+ if 'langdetect' in used_libraries:
55
+ langcode, confidence_score = langdetect(input_text)
56
+ detections.append(langcode, confidence_score)
57
+ if 'langid' in used_libraries:
58
+ langcode, confidence_score = langdetect(input_text)
59
+ detections.append(langcode, round(number=confidence_score * 10, ndigits=2))
60
+ return detections
61
 
62
  with gr.Blocks() as interface:
63
  gr.Markdown("### Language Detection with Gradio API and MCP Server")
 
67
  detected_text = gr.Textbox(label="Translated text:", placeholder="Display field for translation", interactive=False, buttons=["copy"], lines=1)
68
  confidence = gr.Textbox(label="Confidence:", placeholder="Display field for confidence score", interactive=False, buttons=["copy"], lines=1)
69
  execution_time = gr.Textbox(label="Execution time:", placeholder="Display field for execution time", interactive=False, lines=1)
70
+ used_libraries = gr.CheckboxGroup(choices=["langdetect", "langid", "XX"], label="Detection libraries", info="Detection libraries")
71
  input_text.submit(
72
  fn=detect_language,
73
  inputs=[input_text, used_libraries],