barghavani commited on
Commit
e85d364
·
verified ·
1 Parent(s): 2da9939

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -12,7 +12,10 @@ from dotenv import load_dotenv
12
 
13
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
14
 
15
-
 
 
 
16
  def get_pdf_text(pdf_docs):
17
  text=""
18
  for pdf in pdf_docs:
@@ -78,20 +81,22 @@ def main():
78
  st.set_page_config("Chat PDF")
79
  st.header("QnA with Multiple PDF files💁")
80
 
81
- user_question = st.text_input("Ask a Question from the PDF Files")
82
-
83
- if user_question:
84
- user_input(user_question)
85
-
86
  with st.sidebar:
87
  st.title("Menu:")
88
- pdf_docs = st.file_uploader("Upload your PDF Files and Click on the Submit & Process Button", accept_multiple_files=True)
 
89
  if st.button("Submit & Process"):
90
- with st.spinner("Processing..."):
91
- raw_text = get_pdf_text(pdf_docs)
92
- text_chunks = get_text_chunks(raw_text)
93
- get_vector_store(text_chunks)
94
- st.success("Done")
 
 
 
 
 
 
95
 
96
 
97
 
 
12
 
13
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
14
 
15
+ def transcribe_audio(audio_file):
16
+ model = whisper.load_model("large")
17
+ result = model.transcribe(audio_file, language="en", fp16=False)
18
+ return result["text"]
19
  def get_pdf_text(pdf_docs):
20
  text=""
21
  for pdf in pdf_docs:
 
81
  st.set_page_config("Chat PDF")
82
  st.header("QnA with Multiple PDF files💁")
83
 
 
 
 
 
 
84
  with st.sidebar:
85
  st.title("Menu:")
86
+ audio_query = st.file_uploader("Upload your Audio Query", type=['mp3', 'wav'])
87
+ pdf_docs = st.file_uploader("Upload your PDF Files", accept_multiple_files=True)
88
  if st.button("Submit & Process"):
89
+ with st.spinner("Processing Audio and PDFs..."):
90
+ if audio_query is not None:
91
+ user_question = transcribe_audio(audio_query)
92
+ raw_text = get_pdf_text(pdf_docs)
93
+ text_chunks = get_text_chunks(raw_text)
94
+ get_vector_store(text_chunks)
95
+ response = user_input(user_question)
96
+ st.success("Done")
97
+ st.write("Reply: ", response)
98
+ else:
99
+ st.error("Please upload an audio file for the query.")
100
 
101
 
102