Spaces:
Runtime error
Runtime error
george duan
commited on
Commit
·
a7f1536
1
Parent(s):
89019a3
modify dependency for docx
Browse files- app.py +2 -80
- description.md +1 -1
- head.html +0 -49
- requirements.txt +8 -8
app.py
CHANGED
|
@@ -112,84 +112,6 @@ def get_mp3(text: str, voice: str, api_key: str = None) -> bytes:
|
|
| 112 |
for chunk in response.iter_bytes():
|
| 113 |
file.write(chunk)
|
| 114 |
return file.getvalue()
|
| 115 |
-
# def get_ppt_text(filename):
|
| 116 |
-
# prs = Presentation(filename)
|
| 117 |
-
# full_text = []
|
| 118 |
-
# for slide in prs.slides:
|
| 119 |
-
# for shape in slide.shapes:
|
| 120 |
-
# if hasattr(shape, "text"):
|
| 121 |
-
# full_text.append(shape.text)
|
| 122 |
-
# return '\n'.join(full_text)
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
# def get_doc_text(filename):
|
| 126 |
-
# doc = Document(filename)
|
| 127 |
-
# full_text = [para.text for para in doc.paragraphs]
|
| 128 |
-
# return '\n'.join(full_text)
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
# def get_page_text(filename, page_num):
|
| 132 |
-
# with pdfplumber.open(filename) as pdf:
|
| 133 |
-
# page = pdf.pages[page_num]
|
| 134 |
-
# return page.extract_text()
|
| 135 |
-
|
| 136 |
-
# def summarize_page(i, text):
|
| 137 |
-
# prompt = """Summarize the text in a detailed and concise manner."""
|
| 138 |
-
# # text = get_page_text(filename, page_num)
|
| 139 |
-
# client = OpenAI()
|
| 140 |
-
# # Check if text extraction was successful
|
| 141 |
-
# if text:
|
| 142 |
-
# response = client.chat.completions.create(
|
| 143 |
-
# model="gpt-4o",
|
| 144 |
-
# temperature=0.1,
|
| 145 |
-
# messages=[
|
| 146 |
-
# {"role": "system", "content": prompt},
|
| 147 |
-
# {"role": "user", "content": text}
|
| 148 |
-
# ]
|
| 149 |
-
# )
|
| 150 |
-
# return i, response.choices[0].message.content
|
| 151 |
-
# else:
|
| 152 |
-
# return i, "No text found on this page."
|
| 153 |
-
|
| 154 |
-
# def summarize_large_text(texts):
|
| 155 |
-
# summary_parts = []
|
| 156 |
-
# num_pages = len(texts)
|
| 157 |
-
# with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 158 |
-
# future_to_page = {executor.submit(summarize_page, i, texts[i]): i for i in range(num_pages)}
|
| 159 |
-
# for future in concurrent.futures.as_completed(future_to_page):
|
| 160 |
-
# i, page_summary = future.result()
|
| 161 |
-
# summary_parts.append((i, f"p{i+1}: {page_summary}"))
|
| 162 |
-
|
| 163 |
-
# # Sort the summary parts by page index and join them into a single string
|
| 164 |
-
# summary_parts.sort(key=lambda x: x[0])
|
| 165 |
-
# full_summary = "\n".join(part[1] for part in summary_parts)
|
| 166 |
-
|
| 167 |
-
# return full_summary
|
| 168 |
-
|
| 169 |
-
# def summarize_pdf_parallel(filename):
|
| 170 |
-
# with pdfplumber.open(filename) as pdf:
|
| 171 |
-
# num_pages = len(pdf.pages)
|
| 172 |
-
# texts = [get_page_text(filename, i) for i in range(num_pages)]
|
| 173 |
-
|
| 174 |
-
# all_text = "\n".join(texts)
|
| 175 |
-
|
| 176 |
-
# if len(all_text) > 70000:
|
| 177 |
-
# return summarize_large_text(texts)
|
| 178 |
-
# else:
|
| 179 |
-
# return all_text
|
| 180 |
-
|
| 181 |
-
# def summarize_file(filename):
|
| 182 |
-
# if filename.endswith(".pdf"):
|
| 183 |
-
# return summarize_pdf_parallel(filename)
|
| 184 |
-
# elif filename.endswith(".txt"):
|
| 185 |
-
# with open(filename, "r") as f:
|
| 186 |
-
# return f.read()
|
| 187 |
-
# elif filename.endswith(".docx"):
|
| 188 |
-
# return get_doc_text(filename)
|
| 189 |
-
# elif filename.endswith(".pptx"):
|
| 190 |
-
# return get_ppt_text(filename)
|
| 191 |
-
# else:
|
| 192 |
-
# raise ValueError("Unsupported file type")
|
| 193 |
|
| 194 |
def summarize_chunk(chunk_text: str) -> str:
|
| 195 |
llm = ChatOpenAI(temperature=0, model_name="gpt-4o")
|
|
@@ -331,7 +253,7 @@ def generate_audio(file=None, url=None, openai_api_key: str = None) -> bytes:
|
|
| 331 |
|
| 332 |
|
| 333 |
demo = gr.Interface(
|
| 334 |
-
title="
|
| 335 |
description=Path("description.md").read_text(),
|
| 336 |
fn=generate_audio,
|
| 337 |
examples=[],
|
|
@@ -354,7 +276,7 @@ demo = gr.Interface(
|
|
| 354 |
],
|
| 355 |
allow_flagging=False,
|
| 356 |
clear_btn=None,
|
| 357 |
-
head=
|
| 358 |
cache_examples="lazy",
|
| 359 |
api_name=False,
|
| 360 |
)
|
|
|
|
| 112 |
for chunk in response.iter_bytes():
|
| 113 |
file.write(chunk)
|
| 114 |
return file.getvalue()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
def summarize_chunk(chunk_text: str) -> str:
|
| 117 |
llm = ChatOpenAI(temperature=0, model_name="gpt-4o")
|
|
|
|
| 253 |
|
| 254 |
|
| 255 |
demo = gr.Interface(
|
| 256 |
+
title="Antyhing to Podcast",
|
| 257 |
description=Path("description.md").read_text(),
|
| 258 |
fn=generate_audio,
|
| 259 |
examples=[],
|
|
|
|
| 276 |
],
|
| 277 |
allow_flagging=False,
|
| 278 |
clear_btn=None,
|
| 279 |
+
head="Anythin Podcast",
|
| 280 |
cache_examples="lazy",
|
| 281 |
api_name=False,
|
| 282 |
)
|
description.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
<p style="text-align:center">
|
| 2 |
-
<strong>Convert
|
| 3 |
</p>
|
|
|
|
| 1 |
<p style="text-align:center">
|
| 2 |
+
<strong>Convert anything into a podcast episode! Experience research papers, websites, and more in a whole new way.</strong>
|
| 3 |
</p>
|
head.html
DELETED
|
@@ -1,49 +0,0 @@
|
|
| 1 |
-
<!-- Primary Meta Tags -->
|
| 2 |
-
<title>PDF to Podcast - Convert Your Documents to Audio</title>
|
| 3 |
-
<meta name="title" content="PDF to Podcast - Convert Your Documents to Audio" />
|
| 4 |
-
<meta
|
| 5 |
-
name="description"
|
| 6 |
-
content="Easily convert your PDF documents into audio podcasts. Perfect for listening on the go and making content more accessible."
|
| 7 |
-
/>
|
| 8 |
-
|
| 9 |
-
<!-- Open Graph / Facebook -->
|
| 10 |
-
<meta property="og:type" content="website" />
|
| 11 |
-
<meta property="og:url" content="https://pdf-to-podcast.com/" />
|
| 12 |
-
<meta
|
| 13 |
-
property="og:title"
|
| 14 |
-
content="PDF to Podcast - Convert Your Documents to Audio"
|
| 15 |
-
/>
|
| 16 |
-
<meta
|
| 17 |
-
property="og:description"
|
| 18 |
-
content="Easily convert your PDF documents into audio podcasts. Perfect for listening on the go and making content more accessible."
|
| 19 |
-
/>
|
| 20 |
-
<meta
|
| 21 |
-
property="og:image"
|
| 22 |
-
content="https://pdf-to-podcast.com/static/logo.png"
|
| 23 |
-
/>
|
| 24 |
-
|
| 25 |
-
<!-- Twitter -->
|
| 26 |
-
<meta property="twitter:card" content="summary_large_image" />
|
| 27 |
-
<meta property="twitter:url" content="https://pdf-to-podcast.com/" />
|
| 28 |
-
<meta
|
| 29 |
-
property="twitter:title"
|
| 30 |
-
content="PDF to Podcast - Convert Your Documents to Audio"
|
| 31 |
-
/>
|
| 32 |
-
<meta
|
| 33 |
-
property="twitter:description"
|
| 34 |
-
content="Easily convert your PDF documents into audio podcasts. Perfect for listening on the go and making content more accessible."
|
| 35 |
-
/>
|
| 36 |
-
<meta
|
| 37 |
-
property="twitter:image"
|
| 38 |
-
content="https://pdf-to-podcast.com/static/logo.png"
|
| 39 |
-
/>
|
| 40 |
-
|
| 41 |
-
<!-- Additional Meta Tags -->
|
| 42 |
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 43 |
-
<meta charset="UTF-8" />
|
| 44 |
-
<meta name="author" content="Stephan Fitzpatrick" />
|
| 45 |
-
<meta
|
| 46 |
-
name="keywords"
|
| 47 |
-
content="PDF to Podcast, PDF to audio, document to podcast, audio conversion, podcast creation, accessible content"
|
| 48 |
-
/>
|
| 49 |
-
<link rel="icon" href="/static/icon.png" type="image/png" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -4,16 +4,16 @@ pydantic
|
|
| 4 |
google-generativeai
|
| 5 |
loguru~=0.7
|
| 6 |
pypdf~=4.1
|
| 7 |
-
tenacity
|
| 8 |
sentry-sdk~=2.5
|
| 9 |
granian~=1.4
|
| 10 |
# PyPDF2
|
| 11 |
-
pdfplumber
|
| 12 |
openai
|
| 13 |
-
|
| 14 |
# python-pptx
|
| 15 |
-
llmsherpa
|
| 16 |
-
langchain_openai
|
| 17 |
-
langchain_community
|
| 18 |
-
langchain
|
| 19 |
-
|
|
|
|
| 4 |
google-generativeai
|
| 5 |
loguru~=0.7
|
| 6 |
pypdf~=4.1
|
| 7 |
+
tenacity==8.3.0
|
| 8 |
sentry-sdk~=2.5
|
| 9 |
granian~=1.4
|
| 10 |
# PyPDF2
|
| 11 |
+
pdfplumber==0.11.1
|
| 12 |
openai
|
| 13 |
+
python-docx
|
| 14 |
# python-pptx
|
| 15 |
+
llmsherpa~=0.1.4
|
| 16 |
+
langchain_openai==0.1.8
|
| 17 |
+
langchain_community==0.2.4
|
| 18 |
+
langchain==0.2.5
|
| 19 |
+
beautifulsoup4==4.12.3
|