open-notebook / app.py
avinash
updated ui
bf6f7a9
import gradio as gr
from loader import load_and_split_pdf
from rag_chain import setup_rag_chain
from tts_engine import generate_voice
import tempfile
qa_chain = None
def handle_pdf(file):
global qa_chain
docs = load_and_split_pdf(file.name)
qa_chain = setup_rag_chain(docs)
summary = qa_chain.run("Give me a 1-minute summary as if it’s a podcast intro.")
voice_path = generate_voice(summary)
return summary, voice_path
def ask_question(question):
if qa_chain is None:
return "Upload a PDF first.", None
answer = qa_chain.run(question)
voice_path = generate_voice(answer)
return answer, voice_path
with gr.Blocks() as demo:
gr.Markdown("# πŸŽ™οΈ Notebook LLM Style AI Podcast")
with gr.Row():
pdf_input = gr.File(label="Upload a PDF", file_types=[".pdf"])
summary_out = gr.Textbox(label="πŸ“„ Podcast Summary")
voice_out = gr.Audio(label="🎧 Audio Summary", type="filepath")
pdf_input.change(handle_pdf, inputs=pdf_input, outputs=[summary_out, voice_out])
with gr.Row():
user_q = gr.Textbox(label="❓ Ask Something from PDF")
bot_reply = gr.Textbox(label="πŸ€– Answer")
audio_reply = gr.Audio(label="πŸ”Š Voice Reply", type="filepath")
user_q.submit(ask_question, inputs=user_q, outputs=[bot_reply, audio_reply])
demo.launch()