Aujjima commited on
Commit
0aa480b
·
verified ·
1 Parent(s): d59add1

Create app.py

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