File size: 760 Bytes
2c824f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# script to load the model and make prediction
import joblib
import numpy as np
import gradio as gr

model = joblib.load("lang_detect_model.joblib")

def detect_lang(text: str) -> str:
    pred = model.predict([text])
    # pred_prob = model.predict_proba([text])
    # pred_prob = round(np.max(pred_prob) * 100, 2)
    lang_dict = {
        'ar': 'Arabic',
        'de': 'Deutsch',
        'en': 'English',
        'es': 'Spanish',
        'fr': 'France',
        'it': 'Italy',
        'ja': 'Japanese',
        'nl': 'Dutch',
        'pl': 'Polish',
        'pt': 'Portuguese',
        'ru': 'Russian'
    }
    lang_name = lang_dict[pred[0]]
    return lang_name


iface = gr.Interface(
        detect_lang,
        "text",
        "text"
)
iface.launch()