| 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() |