import gradio as gr from utils.pdf_parser import extract_text_from_pdf from summarizer import Summarizer from qa_engine import QABot from chatbot import ask_model from suggestions import suggest_questions # Initialize summarizer and global variables summarizer = Summarizer() qa_bot = None summary = "" text_chunks = [] # Gradio chat history chat_history = [] def process_pdf(file): global summary, qa_bot, text_chunks, chat_history text = extract_text_from_pdf(file.name) summary = summarizer.summarize(text) text_chunks = text.split("\n\n") qa_bot = QABot(text_chunks) chat_history.clear() return summary, "PDF processed. You can now ask questions." def chat_with_doc(question): if not qa_bot: return chat_history, "Please upload and summarize a document first." context = qa_bot.retrieve_context(question) response = ask_model(context, question) chat_history.append((question, response)) suggestions = suggest_questions(summary) suggestions_block = "💡 You can also ask:\n" + "\n".join([f"• {q}" for q in suggestions]) return chat_history, suggestions_block # UI layout with gr.Blocks(title="BioSummarize.ai") as iface: gr.Markdown("# 🧬 BioSummarize.ai") gr.Markdown("Upload a biotech research paper, generate its summary, and chat with it using an AI-powered assistant.") with gr.Row(): file_input = gr.File(label="Upload Biotech Research PDF") summarize_btn = gr.Button("Summarize + Start Chat") summary_box = gr.Textbox(label="📘 Summary", lines=6) summary_status = gr.Textbox(label="Status / Info", lines=2) chat_input = gr.Textbox(label="💬 Ask a Question", placeholder="What is the main finding?") chatbot = gr.Chatbot(label="🧠 BioResearch Chatbot") suggestions_box = gr.Textbox(label="💡 Follow-up Suggestions", interactive=False) # Bind actions summarize_btn.click(fn=process_pdf, inputs=file_input, outputs=[summary_box, summary_status]) chat_input.submit(fn=chat_with_doc, inputs=chat_input, outputs=[chatbot, suggestions_box]) # Launch the app if __name__ == "__main__": iface.launch()