avinash commited on
Commit
bf6f7a9
Β·
1 Parent(s): a50f676

updated ui

Browse files
Files changed (1) hide show
  1. app.py +41 -33
app.py CHANGED
@@ -1,34 +1,42 @@
1
  import gradio as gr
2
- from asr import transcribe_audio
3
- from llm_agent import get_llm_reply
4
- from tts import generate_speech
5
-
6
- def voice_agent(audio):
7
- if audio is None:
8
- return "No audio received!", "...", None
9
-
10
- # ASR
11
- user_text = transcribe_audio(audio)
12
-
13
- # LLM
14
- bot_reply = get_llm_reply(user_text)
15
-
16
- # TTS
17
- audio_reply = generate_speech(bot_reply)
18
-
19
- return user_text, bot_reply, audio_reply
20
-
21
- ui = gr.Interface(
22
- fn=voice_agent,
23
- inputs=gr.Audio(type="filepath", label="πŸŽ™οΈ Upload Voice (.wav or .mp3)"),
24
- outputs=[
25
- gr.Textbox(label="πŸ“ Transcribed Text"),
26
- gr.Textbox(label="πŸ€– LLM Reply"),
27
- gr.Audio(type="filepath", label="πŸ”Š AI Voice Response")
28
- ],
29
- title="VoiceFreight AI v1.0",
30
- description="Upload a voice file. Get a spoken reply from an AI freight agent!"
31
- )
32
-
33
- if __name__ == "__main__":
34
- ui.launch()
 
 
 
 
 
 
 
 
 
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()