Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
import speech_recognition as sr
|
3 |
from gtts import gTTS
|
4 |
-
import
|
5 |
import fitz # PyMuPDF for PDF extraction
|
6 |
from langchain.chains import ConversationalRetrievalChain
|
7 |
from langchain.vectorstores import FAISS
|
8 |
from langchain.embeddings import HuggingFaceEmbeddings
|
9 |
-
from langchain.text_splitter import CharacterTextSplitter
|
10 |
from langchain.docstore.document import Document
|
11 |
from langchain.llms import Anthropic
|
12 |
|
@@ -34,12 +33,9 @@ def record_audio():
|
|
34 |
# Function for text-to-speech (Text to Audio)
|
35 |
def text_to_speech_urdu(text):
|
36 |
tts = gTTS(text=text, lang='ur')
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
st.audio(audio_bytes, format="audio/mp3")
|
41 |
-
if os.path.exists("response.mp3"):
|
42 |
-
os.remove("response.mp3")
|
43 |
|
44 |
# Function to extract text from PDFs
|
45 |
def extract_text_from_pdf(pdf_file):
|
|
|
1 |
import streamlit as st
|
2 |
import speech_recognition as sr
|
3 |
from gtts import gTTS
|
4 |
+
import tempfile
|
5 |
import fitz # PyMuPDF for PDF extraction
|
6 |
from langchain.chains import ConversationalRetrievalChain
|
7 |
from langchain.vectorstores import FAISS
|
8 |
from langchain.embeddings import HuggingFaceEmbeddings
|
|
|
9 |
from langchain.docstore.document import Document
|
10 |
from langchain.llms import Anthropic
|
11 |
|
|
|
33 |
# Function for text-to-speech (Text to Audio)
|
34 |
def text_to_speech_urdu(text):
|
35 |
tts = gTTS(text=text, lang='ur')
|
36 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as temp_audio_file:
|
37 |
+
tts.save(temp_audio_file.name)
|
38 |
+
st.audio(temp_audio_file.name, format="audio/mp3")
|
|
|
|
|
|
|
39 |
|
40 |
# Function to extract text from PDFs
|
41 |
def extract_text_from_pdf(pdf_file):
|