Update app.py
Browse files1 unmodified line23456786 unmodified lines15161718192021222324252627282930313233343536371 unmodified linefrom transformers import pipelineimport gradio as gr# Initialize the Hugging Face summarization pipelinesummarizer = pipeline("summarization", model="facebook/bart-large-cnn")# Function to extract text from PDF6 unmodified lines# Function to summarize the content of the PDFdef summarize_pdf(pdf_file):text = extract_text_from_pdf(pdf_file.name)# Summarizing the extracted textsummary = summarizer(text, max_length=500, min_length=100, do_sample=False)return summary[0]['summary_text']# Chatbot function to handle user queriesdef chatbot(input_text, summarized_text):if input_text.lower() in ['exit', 'quit', 'bye']:return "Goodbye! Feel free to upload a new PDF if you'd like to chat again."elif "summary" in input_text.lower():return summarized_textelse:return "Ask me about the PDF summary, or type 'summary' to get the summary again!"# Gradio interface functiondef gradio_interface(pdf_file, user_input):summarized_text = summarize_pdf(pdf_file) # Generate summary for the uploaded PDFreturn chatbot(user_input, summarized_text) # Respond based on user input and the summary# Gradio UI setup1 unmodified line23456786 unmodified lines151617181920212223242526272829303132333435361 unmodified linefrom transformers import pipelineimport gradio as gr# Initialize the Hugging Face summarization pipeline (using Facebook BART for summarization)summarizer = pipeline("summarization", model="facebook/bart-large-cnn")# Function to extract text from PDF6 unmodified lines# Function to summarize the content of the PDFdef summarize_pdf(pdf_file):text = extract_text_from_pdf(pdf_file.name) # Get the text from the PDFsummary = summarizer(text, max_length=500, min_length=100, do_sample=False) # Generate the summaryreturn summary[0]['summary_text'] # Return the summarized text# Chatbot function for user interactiondef chatbot(input_text, summarized_text):if input_text.lower() in ['exit', 'quit', 'bye']:return "Goodbye! Feel free to upload a new PDF and chat again."elif "summary" in input_text.lower():return summarized_text # Return the summary of the PDFelse:return "Ask me about the PDF summary, or type 'summary' to get the summary again!"# Gradio interface functiondef gradio_interface(pdf_file, user_input):summarized_text = summarize_pdf(pdf_file) # Generate the PDF summaryreturn chatbot(user_input, summarized_text) # Respond based on user input and the summary# Gradio UI setup
app.py+8-9