from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM import gradio as gr # Load the model and tokenizer model_path = '.' # Path to the current directory where files are located tokenizer = AutoTokenizer.from_pretrained(model_path) model = AutoModelForSeq2SeqLM.from_pretrained(model_path) summarizer = pipeline('summarization', model=model, tokenizer=tokenizer) def summarize_text(text): result = summarizer(text, max_length=150, min_length=30, do_sample=False) return result[0]['summary_text'] gr_interface = gr.Interface( fn=summarize_text, inputs=gr.Textbox(lines=5, placeholder="Enter text to summarize here..."), outputs=gr.Textbox(), title="Text Summarization with Fine-Tuned Model", description="Enter text to generate a summary using the fine-tuned summarization model." ) if __name__ == "__main__": gr_interface.launch(share=True)