Spaces:
Paused
Paused
avinash
commited on
Commit
Β·
bf6f7a9
1
Parent(s):
a50f676
updated ui
Browse files
app.py
CHANGED
|
@@ -1,34 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
from
|
| 4 |
-
from
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from loader import load_and_split_pdf
|
| 3 |
+
from rag_chain import setup_rag_chain
|
| 4 |
+
from tts_engine import generate_voice
|
| 5 |
+
import tempfile
|
| 6 |
+
|
| 7 |
+
qa_chain = None
|
| 8 |
+
|
| 9 |
+
def handle_pdf(file):
|
| 10 |
+
global qa_chain
|
| 11 |
+
docs = load_and_split_pdf(file.name)
|
| 12 |
+
qa_chain = setup_rag_chain(docs)
|
| 13 |
+
|
| 14 |
+
summary = qa_chain.run("Give me a 1-minute summary as if itβs a podcast intro.")
|
| 15 |
+
voice_path = generate_voice(summary)
|
| 16 |
+
|
| 17 |
+
return summary, voice_path
|
| 18 |
+
|
| 19 |
+
def ask_question(question):
|
| 20 |
+
if qa_chain is None:
|
| 21 |
+
return "Upload a PDF first.", None
|
| 22 |
+
answer = qa_chain.run(question)
|
| 23 |
+
voice_path = generate_voice(answer)
|
| 24 |
+
return answer, voice_path
|
| 25 |
+
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
+
gr.Markdown("# ποΈ Notebook LLM Style AI Podcast")
|
| 28 |
+
with gr.Row():
|
| 29 |
+
pdf_input = gr.File(label="Upload a PDF", file_types=[".pdf"])
|
| 30 |
+
summary_out = gr.Textbox(label="π Podcast Summary")
|
| 31 |
+
voice_out = gr.Audio(label="π§ Audio Summary", type="filepath")
|
| 32 |
+
|
| 33 |
+
pdf_input.change(handle_pdf, inputs=pdf_input, outputs=[summary_out, voice_out])
|
| 34 |
+
|
| 35 |
+
with gr.Row():
|
| 36 |
+
user_q = gr.Textbox(label="β Ask Something from PDF")
|
| 37 |
+
bot_reply = gr.Textbox(label="π€ Answer")
|
| 38 |
+
audio_reply = gr.Audio(label="π Voice Reply", type="filepath")
|
| 39 |
+
|
| 40 |
+
user_q.submit(ask_question, inputs=user_q, outputs=[bot_reply, audio_reply])
|
| 41 |
+
|
| 42 |
+
demo.launch()
|