import gradio as gr from transformers import pipeline summarizer = pipeline(task="summarization", model="facebook/bart-large-cnn") def fetch_record(record_url): return "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80" def summary_text(input_text: str, min_length: int = 30, max_length: int = 120): summary = summarizer(input_text, max_length=max_length, min_length=min_length, do_sample=False) return summary[0]['summary_text'] with gr.Blocks() as app: gr.Markdown("# SLNSW - Text sumarisation from the input above") gr.Markdown("Summarise long text description either by record URL or manual copy-and-paste.") with gr.Row(): with gr.Column(): record_url = gr.Text(label="SL record URL", lines=5, info="The main URL of collections eg. https://collection.sl.nsw.gov.au/record/YdmdvKj9") fetch_record_btn = gr.Button("Fetch URL") with gr.Column(): input_text = gr.Text(label="Input text", lines=5, info="The manual input of long text", interactive=True) summary_text_btn = gr.Button("Summary") with gr.Row(): with gr.Column(): summary_text_txt = gr.Text(label="Summary", info="The summarised text") fetch_record_btn.click(fn=fetch_record, inputs=[record_url], outputs=[input_text]) summary_text_btn.click(fn=summary_text, inputs=[input_text], outputs=[summary_text_txt], api_name="summary_text") if __name__ == "__main__": app.launch(server_name='0.0.0.0', ssl_verify=False)