Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ import io
|
|
| 5 |
from pydub import AudioSegment
|
| 6 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 7 |
import PyPDF2
|
| 8 |
-
from fpdf import FPDF
|
| 9 |
|
| 10 |
# Set OpenAI API key
|
| 11 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
|
@@ -34,7 +33,7 @@ def transcribe_audio(audio_file):
|
|
| 34 |
|
| 35 |
# Function to extract text from PDF and split it into chunks
|
| 36 |
def extract_text_from_pdf(pdf_file):
|
| 37 |
-
reader = PyPDF2.PdfReader(pdf_file)
|
| 38 |
text = ""
|
| 39 |
for page in reader.pages:
|
| 40 |
text += page.extract_text() + "\n"
|
|
@@ -89,7 +88,6 @@ def main():
|
|
| 89 |
st.sidebar.markdown("### Steps to Use the Tool:")
|
| 90 |
st.sidebar.markdown("1. Upload an audio file (25MB max), PDF, or YouTube URL for notes.")
|
| 91 |
st.sidebar.markdown("2. Click on 'Generate Notes' to get AI-generated notes.")
|
| 92 |
-
st.sidebar.markdown("3. Use 'Download Notes as PDF' to save them locally.")
|
| 93 |
|
| 94 |
# File uploader or URL input based on selected type
|
| 95 |
audio_input = pdf_input = youtube_input = None
|
|
@@ -127,24 +125,8 @@ def main():
|
|
| 127 |
if 'summary' in st.session_state:
|
| 128 |
st.markdown("---")
|
| 129 |
st.subheader("Generated Notes")
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
# Button to save notes as PDF
|
| 133 |
-
pdf = FPDF()
|
| 134 |
-
pdf.add_page()
|
| 135 |
-
pdf.set_auto_page_break(auto=True, margin=15)
|
| 136 |
-
pdf.set_font("Arial", size=12)
|
| 137 |
-
for line in st.session_state['summary'].split('\n'):
|
| 138 |
-
pdf.multi_cell(0, 10, line)
|
| 139 |
-
pdf_output = io.BytesIO()
|
| 140 |
-
pdf.output(pdf_output)
|
| 141 |
-
pdf_output.seek(0)
|
| 142 |
-
st.download_button(
|
| 143 |
-
label="Download Notes as PDF",
|
| 144 |
-
data=pdf_output,
|
| 145 |
-
file_name="notes.pdf",
|
| 146 |
-
mime="application/pdf"
|
| 147 |
-
)
|
| 148 |
|
| 149 |
if __name__ == "__main__":
|
| 150 |
main()
|
|
|
|
| 5 |
from pydub import AudioSegment
|
| 6 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 7 |
import PyPDF2
|
|
|
|
| 8 |
|
| 9 |
# Set OpenAI API key
|
| 10 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
|
|
|
| 33 |
|
| 34 |
# Function to extract text from PDF and split it into chunks
|
| 35 |
def extract_text_from_pdf(pdf_file):
|
| 36 |
+
reader = PyPDF2.PdfReader(io.BytesIO(pdf_file.read()))
|
| 37 |
text = ""
|
| 38 |
for page in reader.pages:
|
| 39 |
text += page.extract_text() + "\n"
|
|
|
|
| 88 |
st.sidebar.markdown("### Steps to Use the Tool:")
|
| 89 |
st.sidebar.markdown("1. Upload an audio file (25MB max), PDF, or YouTube URL for notes.")
|
| 90 |
st.sidebar.markdown("2. Click on 'Generate Notes' to get AI-generated notes.")
|
|
|
|
| 91 |
|
| 92 |
# File uploader or URL input based on selected type
|
| 93 |
audio_input = pdf_input = youtube_input = None
|
|
|
|
| 125 |
if 'summary' in st.session_state:
|
| 126 |
st.markdown("---")
|
| 127 |
st.subheader("Generated Notes")
|
| 128 |
+
formatted_notes = '\n\n'.join([f'• {line.strip()}' for line in st.session_state['summary'].split('\n')])
|
| 129 |
+
st.text_area("", formatted_notes, height=400)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
if __name__ == "__main__":
|
| 132 |
main()
|