Spaces:
Build error
Build error
File size: 2,158 Bytes
7c114b1 f4dcafb 7c114b1 f4dcafb 7c114b1 f4dcafb 7c114b1 f4dcafb 7c114b1 f4dcafb 7c114b1 f4dcafb 7c114b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
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()
|