TNK21 commited on
Commit
3a73faa
·
1 Parent(s): a4beeaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -1,23 +1,27 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Define the text classification pipeline
5
- classifier = pipeline("text-classification", model="bert-base-multilingual-uncased")
6
 
7
  # Define the Gradio interface
8
- def classify_text(text):
9
- results = classifier(text)
10
- label = results[0]['label']
11
- score = results[0]['score']
12
- return f"Label: {label}, Score: {score}"
13
 
14
  iface = gr.Interface(
15
- fn=classify_text,
16
- inputs=gr.components.Textbox(label="Input Text"),
17
- outputs=gr.components.Textbox(label="Classification Result"),
 
 
 
 
 
 
18
  live=True,
19
- title="Multilingual Text Classification",
20
- description="Classify text into categories using BERT-based model.",
21
  )
22
 
23
  # Start the Gradio interface
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Define the translation pipeline
5
+ translator = pipeline("translation", model="facebook/mbart-large-50-many-to-many-mmt")
6
 
7
  # Define the Gradio interface
8
+ def translate_text(text, target_language):
9
+ translated_text = translator(text, target_language)[0]['translation_text']
10
+ return translated_text
 
 
11
 
12
  iface = gr.Interface(
13
+ fn=translate_text,
14
+ inputs=[
15
+ gr.inputs.Textbox(label="Input Text"),
16
+ gr.inputs.Dropdown(
17
+ label="Target Language",
18
+ choices=["es", "fr", "de", "it"], # Add more languages as needed
19
+ ),
20
+ ],
21
+ outputs=gr.outputs.Textbox(label="Translated Text"),
22
  live=True,
23
+ title="Multilingual Translation Tool",
24
+ description="Translate text into multiple languages using facebook/mbart-large-50-many-to-many-mmt model.",
25
  )
26
 
27
  # Start the Gradio interface