Shirish15 commited on
Commit
d339557
·
verified ·
1 Parent(s): c2ee90f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -21
app.py CHANGED
@@ -1,36 +1,30 @@
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)}"
24
 
25
- # Create the Gradio interface
26
- iface = gr.Interface(
27
- fn=summarize_text,
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__":
36
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
3
 
4
+ # Load model and tokenizer explicitly
5
+ model_name = "facebook/mbart-large-50"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name, src_lang="ne_NP")
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
8
+
9
+ # Create pipeline with explicit config
10
+ summarizer = pipeline(
11
+ "summarization",
12
+ model=model,
13
+ tokenizer=tokenizer
14
+ )
15
 
16
  def summarize_text(text):
 
17
  try:
 
 
 
18
  summary = summarizer(
19
  text,
20
  max_length=150,
21
  min_length=30,
 
22
  truncation=True,
23
+ # No src_lang here anymore
24
+ generate_kwargs={"forced_bos_token_id": tokenizer.lang_code_to_id["ne_NP"]}
25
  )[0]['summary_text']
26
  return summary
27
  except Exception as e:
28
  return f"Error during summarization: {str(e)}"
29
 
30
+ # Rest of Gradio interface remains the same