Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
classifier = pipeline("text-classification", model="production_model")
|
| 5 |
+
|
| 6 |
+
def detect_language(text):
|
| 7 |
+
result = classifier(text)[0]
|
| 8 |
+
|
| 9 |
+
label = result['label']
|
| 10 |
+
score = result['score']
|
| 11 |
+
|
| 12 |
+
if label == "en":
|
| 13 |
+
return f"English 🇬🇧 ({score:.1%} confidence)"
|
| 14 |
+
elif label == "fr":
|
| 15 |
+
return f"French 🇫🇷 ({score:.1%} confidence)"
|
| 16 |
+
elif label == "es":
|
| 17 |
+
return f"Spanish 🇪🇸 ({score:.1%} confidence)"
|
| 18 |
+
elif label == "de":
|
| 19 |
+
return f"German 🇩🇪 ({score:.1%} confidence)"
|
| 20 |
+
else:
|
| 21 |
+
return f"{label} ({score:.1%} confidence)"
|
| 22 |
+
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=detect_language,
|
| 25 |
+
inputs=gr.Textbox(label="Input Text", placeholder="Type a sentence (e.g., 'Guten Morgen')..."),
|
| 26 |
+
outputs=gr.Textbox(label="Analysis Result"),
|
| 27 |
+
title="Language Detector (4 Languages)",
|
| 28 |
+
description="This model was fine-tuned on the 'papluca/language-identification' dataset. It can now detect English, French, Spanish, and German."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
demo.launch()
|