Spaces:
Build error
Build error
Update app.py
Browse files1234567891011121314151617181920# Function to generate discussion points with a promptdef generate_discussion_points(text, user_prompt=""):summarizer = pipeline("summarization", model="facebook/bart-large-cnn")# Prepend the user prompt to the text for guided summarizationinput_text = f"{user_prompt}\n\n{text}"summary = summarizer(input_text, max_length=130, min_length=30, do_sample=False)return summary[0]['summary_text']# Streamlit appst.title("๐ PDF Discussion Points Generator with User Prompts")st.write("Upload a PDF file, provide a prompt for the summary, and listen to the generated discussion points.")# File uploaderuploaded_file = st.file_uploader("Upload a PDF", type=["pdf"])# Prompt inputuser_prompt = st.text_input("Enter a specific prompt for the summary (optional):", "")if uploaded_file:# Extract text from uploaded PDF12345678910111213141516171819202122232425262728293031323334353637383940414243import streamlit as stimport pdfplumberfrom transformers import pipelinefrom gtts import gTTSimport os# Function to extract text from PDFdef extract_text_from_pdf(pdf_file):text = ""try:with pdfplumber.open(pdf_file) as pdf:for page in pdf.pages:text += page.extract_text() or ""except Exception as e:st.error(f"Error reading the PDF: {e}")return text# Function to generate discussion pointsdef generate_discussion_points(text, user_prompt=None):summarizer = pipeline("summarization", model="facebook/bart-large-cnn")if user_prompt:text = user_prompt + " " + text # Include the user's prompt in the summary inputsummary = summarizer(text, max_length=130, min_length=30, do_sample=False)return summary[0]['summary_text']# Function to convert text to speechdef text_to_speech(text, output_file="output.mp3"):tts = gTTS(text)tts.save(output_file)return output_file# Streamlit app starts herest.title("๐ PDF Discussion Points Generator with User Prompts")st.write("Upload a small PDF file to generate discussion points and listen to them.")# File uploaderuploaded_file = st.file_uploader("Upload a PDF", type=["pdf"])# User prompt inputuser_prompt = st.text_input("Enter a prompt for the summary (optional)")if uploaded_file:# Extract text from uploaded PDF
app.py+32-9