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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
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
- 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:
 
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: