import gradio as gr from transformers import pipeline def summarizer(sentence, min_length, max_length): model_name = "AirrStorm/T5-Small-XSUM-Summarizer" # Create a summarization pipeline with the local model summarizer = pipeline("summarization", model=model_name, tokenizer=model_name) summary = summarizer( sentence, max_length=int(max_length), # Convert to int for Gradio input compatibility min_length=int(min_length), # Convert to int for Gradio input compatibility length_penalty=1.2, # Length penalty for beam search num_beams=4, # Number of beams for beam search early_stopping=True # Stop early when an optimal summary is found ) return summary[0]["summary_text"] # Define inputs for the Gradio interface with better layout and styling examples = [ ["The stock market experienced a significant downturn today, with major indices, including the S&P 500, falling by more than 2%. The drop in stock prices came after reports indicated rising inflation and the Federal Reserve's decision to increase interest rates in an effort to curb the growing cost of living. Investors are increasingly concerned that these economic pressures will lead to a slowdown in economic growth, which could negatively impact corporate profits in the coming quarters. As a result, many sectors, particularly technology and consumer goods, saw significant losses."], ["This paper provides a comprehensive review of the application of deep learning algorithms in the healthcare sector, specifically focusing on diagnostic tools. The research evaluates a variety of AI models, including convolutional neural networks (CNNs) and recurrent neural networks (RNNs), for their ability to detect early signs of life-threatening conditions such as cancer and heart disease. The study emphasizes the potential of deep learning to improve diagnostic accuracy, reduce human error, and provide earlier detection, which can ultimately lead to better patient outcomes and lower healthcare costs."], ["The United Nations has issued a new report on the impact of climate change on global food security, warning that rising temperatures and extreme weather events are threatening the world's food supply. The report highlights the vulnerability of agricultural systems to climate-related disruptions, such as droughts, floods, and heatwaves, which can reduce crop yields and increase food prices. The UN calls for urgent action to address the root causes of climate change and build more resilient food systems that can withstand future environmental challenges."], ["In recent years, the Python programming language has gained significant traction in the field of scientific computing due to its ease of use and robust ecosystem of libraries. JAX, an open-source machine learning library developed by Google, allows users to perform high-performance numerical computing with automatic differentiation, making it particularly useful for optimization and machine learning tasks. With JAX, users can efficiently implement and execute complex mathematical functions on both CPUs and GPUs, enabling faster computation and model training. Its integration with NumPy and seamless handling of automatic differentiation allows researchers and developers to prototype machine learning models quickly while leveraging the power of modern hardware."], ["In an insightful interview, the CEO shared her vision for the company’s future, discussing plans to expand into international markets and enhance the company’s focus on sustainable and environmentally friendly practices in production. She outlined the company’s strategy to adopt cutting-edge technologies, such as artificial intelligence and automation, to improve efficiency and customer satisfaction. Additionally, she emphasized the importance of fostering a collaborative work environment and increasing employee satisfaction through comprehensive training programs and initiatives designed to promote diversity and inclusion within the workplace."] ] inputs = [ gr.Textbox( label="Input Text", lines=10, placeholder="Enter the text to summarize here...", interactive=True, elem_id="input_text_box" ), gr.Number( label="Minimum Length", value=50, precision=0, interactive=True, elem_id="min_length" ), gr.Number( label="Maximum Length", value=200, precision=0, interactive=True, elem_id="max_length" ), ] # Define the Gradio interface demo = gr.Interface( fn=summarizer, inputs=inputs, outputs=gr.Textbox( label="Summary", lines=6, placeholder="Your summary will appear here.", interactive=False, elem_id="output_summary" ), title="Text Summarization Tool", description="Provide a text input, specify the minimum and maximum lengths for the summary, and get a concise version of your text.", theme="huggingface", # Optional, you can change to other themes like 'compact' allow_flagging="never", # Disable flagging examples=examples ) # Launch the interface with shareable link demo.launch()