File size: 1,037 Bytes
7789eaa
 
 
28db6e9
7789eaa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

classifier = pipeline("text-classification", model=".")

def detect_language(text):
    result = classifier(text)[0]
    
    label = result['label']
    score = result['score']
    
    if label == "en":
        return f"English 🇬🇧 ({score:.1%} confidence)"
    elif label == "fr":
        return f"French 🇫🇷 ({score:.1%} confidence)"
    elif label == "es":
        return f"Spanish 🇪🇸 ({score:.1%} confidence)"
    elif label == "de":
        return f"German 🇩🇪 ({score:.1%} confidence)"
    else:
        return f"{label} ({score:.1%} confidence)"

demo = gr.Interface(
    fn=detect_language,
    inputs=gr.Textbox(label="Input Text", placeholder="Type a sentence (e.g., 'Guten Morgen')..."),
    outputs=gr.Textbox(label="Analysis Result"),
    title="Language Detector (4 Languages)",
    description="This model was fine-tuned on the 'papluca/language-identification' dataset. It can now detect English, French, Spanish, and German."
)

demo.launch()