ivanlau commited on
Commit
81760af
1 Parent(s): aa0c704

modified app file

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -9,13 +9,12 @@ model = AutoModelForSequenceClassification.from_pretrained(model_ckpt)
9
  tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
10
 
11
 
12
-
13
  def detect_language(sentence):
14
- tokenized_sentence = tokenizer(sentence, return_tensors='pt')
15
- output = model(**tokenized_sentence)
16
- predictions = torch.nn.functional.softmax(output.logits, dim=-1)
17
- _, preds = torch.max(predictions, dim=-1)
18
- return LANGUANGE_MAP[preds.item()]
19
 
20
  examples = [
21
  "I've been waiting for a HuggingFace course my whole life.",
@@ -23,12 +22,14 @@ examples = [
23
  "Jumpa lagi, saya pergi kerja.",
24
  "你食咗飯未呀?",
25
  "もう食べましたか?",
26
- "as-tu mangé"
 
27
  ]
28
 
29
  inputs=gr.inputs.Textbox(placeholder="Enter your text here", label="Text content", lines=5)
30
- outputs=gr.outputs.Label(num_top_classes=3, label="Language detected:")
31
  article = """
 
32
  Supported languages:
33
  'Arabic', 'Basque', 'Breton', 'Catalan', 'Chinese_China', 'Chinese_Hongkong', 'Chinese_Taiwan', 'Chuvash', 'Czech',
34
  'Dhivehi', 'Dutch', 'English', 'Esperanto', 'Estonian', 'French', 'Frisian', 'Georgian', 'German', 'Greek', 'Hakha_Chin',
@@ -36,6 +37,7 @@ Supported languages:
36
  'Mangolian', 'Persian', 'Polish', 'Portuguese', 'Romanian', 'Romansh_Sursilvan', 'Russian', 'Sakha', 'Slovenian',
37
  'Spanish', 'Swedish', 'Tamil', 'Tatar', 'Turkish', 'Ukranian', 'Welsh'
38
  """
 
39
  gr.Interface(
40
  fn=detect_language,
41
  inputs=inputs,
@@ -43,7 +45,7 @@ gr.Interface(
43
  verbose=True,
44
  examples = examples,
45
  title="Language Detector",
46
- description="A simple language detector fine-tuned from xlm-roberta-base model which can detect 45 languages.",
47
  article=article,
48
  theme="huggingface"
49
  ).launch()
 
9
  tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
10
 
11
 
 
12
  def detect_language(sentence):
13
+ tokenized_sentence = tokenizer(sentence, return_tensors='pt')
14
+ output = model(**tokenized_sentence)
15
+ predictions = torch.nn.functional.softmax(output.logits, dim=-1)
16
+ _, preds = torch.max(predictions, dim=-1)
17
+ return LANGUANGE_MAP[preds.item()]
18
 
19
  examples = [
20
  "I've been waiting for a HuggingFace course my whole life.",
 
22
  "Jumpa lagi, saya pergi kerja.",
23
  "你食咗飯未呀?",
24
  "もう食べましたか?",
25
+ "as-tu mangé",
26
+ "أريد أن ألعب كرة الريشة"
27
  ]
28
 
29
  inputs=gr.inputs.Textbox(placeholder="Enter your text here", label="Text content", lines=5)
30
+ outputs=gr.outputs.Label(label="Language detected:")
31
  article = """
32
+ Fine-tuned from xlm-roberta-base model.
33
  Supported languages:
34
  'Arabic', 'Basque', 'Breton', 'Catalan', 'Chinese_China', 'Chinese_Hongkong', 'Chinese_Taiwan', 'Chuvash', 'Czech',
35
  'Dhivehi', 'Dutch', 'English', 'Esperanto', 'Estonian', 'French', 'Frisian', 'Georgian', 'German', 'Greek', 'Hakha_Chin',
 
37
  'Mangolian', 'Persian', 'Polish', 'Portuguese', 'Romanian', 'Romansh_Sursilvan', 'Russian', 'Sakha', 'Slovenian',
38
  'Spanish', 'Swedish', 'Tamil', 'Tatar', 'Turkish', 'Ukranian', 'Welsh'
39
  """
40
+
41
  gr.Interface(
42
  fn=detect_language,
43
  inputs=inputs,
 
45
  verbose=True,
46
  examples = examples,
47
  title="Language Detector",
48
+ description="A simple interface to detect 45 languages.",
49
  article=article,
50
  theme="huggingface"
51
  ).launch()