Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
89 |
if st.button("Submit & Process"):
|
90 |
-
with st.spinner("Processing..."):
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|