Shirish15 commited on
Commit
c4cfe6e
·
verified ·
1 Parent(s): e55a74f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -1,13 +1,23 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Initialize the summarization pipeline
5
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn") # You can choose other models
6
 
7
  def summarize_text(text):
8
- """Summarizes the given text using the pre-trained model."""
9
  try:
10
- summary = summarizer(text, max_length=150, min_length=30, do_sample=False)[0]['summary_text'] # Adjust max and min length as needed
 
 
 
 
 
 
 
 
 
 
11
  return summary
12
  except Exception as e:
13
  return f"Error during summarization: {str(e)}"
@@ -18,8 +28,8 @@ iface = gr.Interface(
18
  inputs=gr.Textbox(lines=5, label="Nepali Text to Summarize"),
19
  outputs=gr.Textbox(lines=5, label="Summary"),
20
  title="Nepali Text Summarizer",
21
- description="Enter Nepali text and get a concise summary using a pre-trained NLP model.",
22
- flagging_mode="never" # Changed this line
23
  )
24
 
25
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Initialize multilingual summarization pipeline
5
+ summarizer = pipeline("summarization", model="facebook/mbart-large-50")
6
 
7
  def summarize_text(text):
8
+ """Summarizes the given Nepali text using a multilingual model."""
9
  try:
10
+ if not text.strip():
11
+ return "Please enter some Nepali text to summarize"
12
+
13
+ summary = summarizer(
14
+ text,
15
+ max_length=150,
16
+ min_length=30,
17
+ do_sample=False,
18
+ truncation=True,
19
+ src_lang="ne_NP" # Nepali language code
20
+ )[0]['summary_text']
21
  return summary
22
  except Exception as e:
23
  return f"Error during summarization: {str(e)}"
 
28
  inputs=gr.Textbox(lines=5, label="Nepali Text to Summarize"),
29
  outputs=gr.Textbox(lines=5, label="Summary"),
30
  title="Nepali Text Summarizer",
31
+ description="Enter Nepali text and get a concise summary using multilingual NLP models.",
32
+ flagging_mode="never"
33
  )
34
 
35
  if __name__ == "__main__":