Spaces:
Running
on
T4
Running
on
T4
knowsuchagency
commited on
Commit
•
5e89640
1
Parent(s):
16b3c05
serve via granian and add standard head tags and static files
Browse files- Dockerfile +1 -1
- constants.py +35 -0
- main.py +19 -15
- requirements.txt +1 -0
- static/icon.png +0 -0
- static/logo.png +0 -0
Dockerfile
CHANGED
@@ -11,4 +11,4 @@ COPY . .
|
|
11 |
ENV GRADIO_SERVER_NAME="0.0.0.0"
|
12 |
ENV GRADIO_SERVER_PORT="8080"
|
13 |
|
14 |
-
CMD .venv/bin/
|
|
|
11 |
ENV GRADIO_SERVER_NAME="0.0.0.0"
|
12 |
ENV GRADIO_SERVER_PORT="8080"
|
13 |
|
14 |
+
CMD .venv/bin/granian --interface asgi --port 8080 --host 0.0.0.0 main:app
|
constants.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
description = """
|
2 |
+
<p style="text-align:center">
|
3 |
+
<strong>Convert any PDF into a podcast episode! Experience research papers, websites, and more in a whole new way.</strong>
|
4 |
+
<br>
|
5 |
+
<a href="https://github.com/knowsuchagency/pdf-to-podcast">knowsuchagency/pdf-to-podcast</a>
|
6 |
+
</p>
|
7 |
+
"""
|
8 |
+
|
9 |
+
head = """
|
10 |
+
<!-- Primary Meta Tags -->
|
11 |
+
<title>PDF to Podcast - Convert Your Documents to Audio</title>
|
12 |
+
<meta name="title" content="PDF to Podcast - Convert Your Documents to Audio">
|
13 |
+
<meta name="description" content="Easily convert your PDF documents into audio podcasts. Perfect for listening on the go and making content more accessible.">
|
14 |
+
|
15 |
+
<!-- Open Graph / Facebook -->
|
16 |
+
<meta property="og:type" content="website">
|
17 |
+
<meta property="og:url" content="https://pdf-to-podcast.com/">
|
18 |
+
<meta property="og:title" content="PDF to Podcast - Convert Your Documents to Audio">
|
19 |
+
<meta property="og:description" content="Easily convert your PDF documents into audio podcasts. Perfect for listening on the go and making content more accessible.">
|
20 |
+
<meta property="og:image" content="https://pdf-to-podcast.com/static/logo.png">
|
21 |
+
|
22 |
+
<!-- Twitter -->
|
23 |
+
<meta property="twitter:card" content="summary_large_image">
|
24 |
+
<meta property="twitter:url" content="https://pdf-to-podcast.com/">
|
25 |
+
<meta property="twitter:title" content="PDF to Podcast - Convert Your Documents to Audio">
|
26 |
+
<meta property="twitter:description" content="Easily convert your PDF documents into audio podcasts. Perfect for listening on the go and making content more accessible.">
|
27 |
+
<meta property="twitter:image" content="https://pdf-to-podcast.com/static/logo.png">
|
28 |
+
|
29 |
+
<!-- Additional Meta Tags -->
|
30 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
31 |
+
<meta charset="UTF-8">
|
32 |
+
<meta name="author" content="Stephan Fitzpatrick">
|
33 |
+
<meta name="keywords" content="PDF to Podcast, PDF to audio, document to podcast, audio conversion, podcast creation, accessible content">
|
34 |
+
<link rel="icon" href="/static/icon.png" type="image/png">
|
35 |
+
"""
|
main.py
CHANGED
@@ -9,6 +9,8 @@ from typing import List, Literal
|
|
9 |
|
10 |
import gradio as gr
|
11 |
import sentry_sdk
|
|
|
|
|
12 |
from loguru import logger
|
13 |
from openai import OpenAI
|
14 |
from promptic import llm
|
@@ -16,8 +18,14 @@ from pydantic import BaseModel, ValidationError
|
|
16 |
from pypdf import PdfReader
|
17 |
from tenacity import retry, retry_if_exception_type
|
18 |
|
|
|
|
|
19 |
sentry_sdk.init(os.getenv("SENTRY_DSN"))
|
20 |
|
|
|
|
|
|
|
|
|
21 |
|
22 |
class DialogueItem(BaseModel):
|
23 |
text: str
|
@@ -46,13 +54,13 @@ def generate_dialogue(text: str) -> Dialogue:
|
|
46 |
Here is the input text you will be working with:
|
47 |
|
48 |
<input_text>
|
49 |
-
{text}
|
50 |
</input_text>
|
51 |
|
52 |
First, carefully read through the input text and identify the main topics, key points, and any interesting facts or anecdotes. Think about how you could present this information in a fun, engaging way that would be suitable for an audio podcast.
|
53 |
|
54 |
<scratchpad>
|
55 |
-
Brainstorm creative ways to discuss the main topics and key points you identified in the input text. Consider using analogies, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.
|
56 |
|
57 |
Keep in mind that your podcast should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms.
|
58 |
|
@@ -61,7 +69,7 @@ def generate_dialogue(text: str) -> Dialogue:
|
|
61 |
Write your brainstorming ideas and a rough outline for the podcast dialogue here. Be sure to note the key insights and takeaways you want to reiterate at the end.
|
62 |
</scratchpad>
|
63 |
|
64 |
-
Now that you have brainstormed ideas and created a rough outline, it's time to write the actual podcast dialogue. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.
|
65 |
|
66 |
<podcast_dialogue>
|
67 |
Write your engaging, informative podcast dialogue here, based on the key points and creative ideas you came up with during the brainstorming session. Use a conversational tone and include any necessary context or explanations to make the content accessible to a general audience. Use made-up names for the hosts and guests to create a more engaging and immersive experience for listeners. Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.
|
@@ -139,14 +147,6 @@ def generate_audio(file: str, openai_api_key: str = None) -> bytes:
|
|
139 |
return temporary_file.name, transcript
|
140 |
|
141 |
|
142 |
-
description = """
|
143 |
-
<p style="text-align:center">
|
144 |
-
<strong>Convert any PDF into a podcast episode! Experience research papers, websites, and more in a whole new way.</strong>
|
145 |
-
<br>
|
146 |
-
<a href="https://github.com/knowsuchagency/pdf-to-podcast">knowsuchagency/pdf-to-podcast</a>
|
147 |
-
</p>
|
148 |
-
"""
|
149 |
-
|
150 |
demo = gr.Interface(
|
151 |
title="PDF to Podcast",
|
152 |
description=description,
|
@@ -167,14 +167,18 @@ demo = gr.Interface(
|
|
167 |
],
|
168 |
allow_flagging=False,
|
169 |
clear_btn=None,
|
170 |
-
head=os.getenv("HEAD"),
|
171 |
cache_examples="lazy",
|
|
|
172 |
)
|
173 |
|
174 |
|
175 |
-
demo.queue(
|
176 |
max_size=20,
|
177 |
default_concurrency_limit=20,
|
178 |
-
).launch(
|
179 |
-
show_api=False,
|
180 |
)
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
import gradio as gr
|
11 |
import sentry_sdk
|
12 |
+
from fastapi import FastAPI
|
13 |
+
from fastapi.staticfiles import StaticFiles
|
14 |
from loguru import logger
|
15 |
from openai import OpenAI
|
16 |
from promptic import llm
|
|
|
18 |
from pypdf import PdfReader
|
19 |
from tenacity import retry, retry_if_exception_type
|
20 |
|
21 |
+
from constants import description, head
|
22 |
+
|
23 |
sentry_sdk.init(os.getenv("SENTRY_DSN"))
|
24 |
|
25 |
+
app = FastAPI()
|
26 |
+
|
27 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
28 |
+
|
29 |
|
30 |
class DialogueItem(BaseModel):
|
31 |
text: str
|
|
|
54 |
Here is the input text you will be working with:
|
55 |
|
56 |
<input_text>
|
57 |
+
{text}
|
58 |
</input_text>
|
59 |
|
60 |
First, carefully read through the input text and identify the main topics, key points, and any interesting facts or anecdotes. Think about how you could present this information in a fun, engaging way that would be suitable for an audio podcast.
|
61 |
|
62 |
<scratchpad>
|
63 |
+
Brainstorm creative ways to discuss the main topics and key points you identified in the input text. Consider using analogies, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.
|
64 |
|
65 |
Keep in mind that your podcast should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms.
|
66 |
|
|
|
69 |
Write your brainstorming ideas and a rough outline for the podcast dialogue here. Be sure to note the key insights and takeaways you want to reiterate at the end.
|
70 |
</scratchpad>
|
71 |
|
72 |
+
Now that you have brainstormed ideas and created a rough outline, it's time to write the actual podcast dialogue. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.
|
73 |
|
74 |
<podcast_dialogue>
|
75 |
Write your engaging, informative podcast dialogue here, based on the key points and creative ideas you came up with during the brainstorming session. Use a conversational tone and include any necessary context or explanations to make the content accessible to a general audience. Use made-up names for the hosts and guests to create a more engaging and immersive experience for listeners. Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.
|
|
|
147 |
return temporary_file.name, transcript
|
148 |
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
demo = gr.Interface(
|
151 |
title="PDF to Podcast",
|
152 |
description=description,
|
|
|
167 |
],
|
168 |
allow_flagging=False,
|
169 |
clear_btn=None,
|
170 |
+
head=os.getenv("HEAD", "") + head,
|
171 |
cache_examples="lazy",
|
172 |
+
api_name=False,
|
173 |
)
|
174 |
|
175 |
|
176 |
+
demo = demo.queue(
|
177 |
max_size=20,
|
178 |
default_concurrency_limit=20,
|
|
|
|
|
179 |
)
|
180 |
+
|
181 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
182 |
+
|
183 |
+
if __name__ == "__main__":
|
184 |
+
demo.launch(show_api=False)
|
requirements.txt
CHANGED
@@ -6,3 +6,4 @@ loguru~=0.7
|
|
6 |
pypdf~=4.1
|
7 |
tenacity~=8.3
|
8 |
sentry-sdk~=2.5
|
|
|
|
6 |
pypdf~=4.1
|
7 |
tenacity~=8.3
|
8 |
sentry-sdk~=2.5
|
9 |
+
granian~=1.4
|
static/icon.png
ADDED
static/logo.png
ADDED