File size: 1,358 Bytes
2ddcf2d
bf6f7a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()