Spaces:
Paused
Paused
| 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() | |