Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Function for detecting language
|
5 |
+
def detect_language(text):
|
6 |
+
result = language_detector(text)
|
7 |
+
return result[0]['label']
|
8 |
+
|
9 |
+
# Define example inputs in multiple languages
|
10 |
+
|
11 |
+
examples = [
|
12 |
+
["Hello, how are you?"], # English
|
13 |
+
["Bonjour, comment ça va?"], # French
|
14 |
+
["Hola, ¿cómo estás?"], # Spanish
|
15 |
+
["مرحبًا كيف حالك؟"], # Arabic
|
16 |
+
]
|
17 |
+
|
18 |
+
|
19 |
+
# Gradio Interface
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=detect_language,
|
22 |
+
inputs=gr.Textbox(label="Enter Text"),
|
23 |
+
outputs=gr.Textbox(label="Detected Language"),
|
24 |
+
title="Language Detection",
|
25 |
+
description="Enter text in any language, and the model will identify the language.",
|
26 |
+
examples=examples
|
27 |
+
)
|
28 |
+
|
29 |
+
# Launch the Gradio app
|
30 |
+
if __name__ == "__main__":
|
31 |
+
iface.launch()
|