Arslan17121 commited on
Commit
fe47eb6
·
verified ·
1 Parent(s): 8cf3d5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -9
app.py CHANGED
@@ -1,20 +1,43 @@
1
- # Function to generate discussion points with a prompt
2
- def generate_discussion_points(text, user_prompt=""):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
4
- # Prepend the user prompt to the text for guided summarization
5
- input_text = f"{user_prompt}\n\n{text}"
6
- summary = summarizer(input_text, max_length=130, min_length=30, do_sample=False)
7
  return summary[0]['summary_text']
8
 
9
- # Streamlit app
 
 
 
 
 
 
10
  st.title("📄 PDF Discussion Points Generator with User Prompts")
11
- st.write("Upload a PDF file, provide a prompt for the summary, and listen to the generated discussion points.")
12
 
13
  # File uploader
14
  uploaded_file = st.file_uploader("Upload a PDF", type=["pdf"])
15
 
16
- # Prompt input
17
- user_prompt = st.text_input("Enter a specific prompt for the summary (optional):", "")
18
 
19
  if uploaded_file:
20
  # Extract text from uploaded PDF
 
1
+ import streamlit as st
2
+ import pdfplumber
3
+ from transformers import pipeline
4
+ from gtts import gTTS
5
+ import os
6
+
7
+ # Function to extract text from PDF
8
+ def extract_text_from_pdf(pdf_file):
9
+ text = ""
10
+ try:
11
+ with pdfplumber.open(pdf_file) as pdf:
12
+ for page in pdf.pages:
13
+ text += page.extract_text() or ""
14
+ except Exception as e:
15
+ st.error(f"Error reading the PDF: {e}")
16
+ return text
17
+
18
+ # Function to generate discussion points
19
+ def generate_discussion_points(text, user_prompt=None):
20
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
21
+ if user_prompt:
22
+ text = user_prompt + " " + text # Include the user's prompt in the summary input
23
+ summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
24
  return summary[0]['summary_text']
25
 
26
+ # Function to convert text to speech
27
+ def text_to_speech(text, output_file="output.mp3"):
28
+ tts = gTTS(text)
29
+ tts.save(output_file)
30
+ return output_file
31
+
32
+ # Streamlit app starts here
33
  st.title("📄 PDF Discussion Points Generator with User Prompts")
34
+ st.write("Upload a small PDF file to generate discussion points and listen to them.")
35
 
36
  # File uploader
37
  uploaded_file = st.file_uploader("Upload a PDF", type=["pdf"])
38
 
39
+ # User prompt input
40
+ user_prompt = st.text_input("Enter a prompt for the summary (optional)")
41
 
42
  if uploaded_file:
43
  # Extract text from uploaded PDF