File size: 939 Bytes
99ceffb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import gradio as gr
from transformers import pipeline

# Initialize the summarization pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")  # You can choose other models

def summarize_text(text):
    """Summarizes the given text using the pre-trained model."""
    try:
        summary = summarizer(text, max_length=150, min_length=30, do_sample=False)[0]['summary_text'] # Adjust max and min length as needed
        return summary
    except Exception as e:
        return f"Error during summarization: {str(e)}"

# Create the Gradio interface
iface = gr.Interface(
    fn=summarize_text,
    inputs=gr.Textbox(lines=5, label="Nepali Text to Summarize"),
    outputs=gr.Textbox(lines=5, label="Summary"),
    title="Nepali Text Summarizer",
    description="Enter Nepali text and get a concise summary using a pre-trained NLP model.",
    allow_flagging=False
)

if __name__ == "__main__":
    iface.launch()