Skip to content

Commit

Permalink
serve via granian and add standard head tags and static files
Browse files Browse the repository at this point in the history
  • Loading branch information
knowsuchagency committed Jun 12, 2024
1 parent a45ce2f commit 4ae356e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ COPY . .
ENV GRADIO_SERVER_NAME="0.0.0.0"
ENV GRADIO_SERVER_PORT="8080"

CMD .venv/bin/python main.py
CMD .venv/bin/granian --interface asgi --port 8080 --host 0.0.0.0 main:app
35 changes: 35 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
description = """
<p style="text-align:center">
<strong>Convert any PDF into a podcast episode! Experience research papers, websites, and more in a whole new way.</strong>
<br>
<a href="https://github.com/knowsuchagency/pdf-to-podcast">knowsuchagency/pdf-to-podcast</a>
</p>
"""

head = """
<!-- Primary Meta Tags -->
<title>PDF to Podcast - Convert Your Documents to Audio</title>
<meta name="title" content="PDF to Podcast - Convert Your Documents to Audio">
<meta name="description" content="Easily convert your PDF documents into audio podcasts. Perfect for listening on the go and making content more accessible.">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://pdf-to-podcast.com/">
<meta property="og:title" content="PDF to Podcast - Convert Your Documents to Audio">
<meta property="og:description" content="Easily convert your PDF documents into audio podcasts. Perfect for listening on the go and making content more accessible.">
<meta property="og:image" content="https://pdf-to-podcast.com/static/logo.png">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://pdf-to-podcast.com/">
<meta property="twitter:title" content="PDF to Podcast - Convert Your Documents to Audio">
<meta property="twitter:description" content="Easily convert your PDF documents into audio podcasts. Perfect for listening on the go and making content more accessible.">
<meta property="twitter:image" content="https://pdf-to-podcast.com/static/logo.png">
<!-- Additional Meta Tags -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<meta name="author" content="Stephan Fitzpatrick">
<meta name="keywords" content="PDF to Podcast, PDF to audio, document to podcast, audio conversion, podcast creation, accessible content">
<link rel="icon" href="/static/icon.png" type="image/png">
"""
34 changes: 19 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@

import gradio as gr
import sentry_sdk
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from loguru import logger
from openai import OpenAI
from promptic import llm
from pydantic import BaseModel, ValidationError
from pypdf import PdfReader
from tenacity import retry, retry_if_exception_type

from constants import description, head

sentry_sdk.init(os.getenv("SENTRY_DSN"))

app = FastAPI()

app.mount("/static", StaticFiles(directory="static"), name="static")


class DialogueItem(BaseModel):
text: str
Expand Down Expand Up @@ -46,13 +54,13 @@ def generate_dialogue(text: str) -> Dialogue:
Here is the input text you will be working with:
<input_text>
{text}
{text}
</input_text>
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.
<scratchpad>
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.
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.
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.
Expand All @@ -61,7 +69,7 @@ def generate_dialogue(text: str) -> Dialogue:
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.
</scratchpad>
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.
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.
<podcast_dialogue>
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.
Expand Down Expand Up @@ -139,14 +147,6 @@ def generate_audio(file: str, openai_api_key: str = None) -> bytes:
return temporary_file.name, transcript


description = """
<p style="text-align:center">
<strong>Convert any PDF into a podcast episode! Experience research papers, websites, and more in a whole new way.</strong>
<br>
<a href="https://github.com/knowsuchagency/pdf-to-podcast">knowsuchagency/pdf-to-podcast</a>
</p>
"""

demo = gr.Interface(
title="PDF to Podcast",
description=description,
Expand All @@ -167,14 +167,18 @@ def generate_audio(file: str, openai_api_key: str = None) -> bytes:
],
allow_flagging=False,
clear_btn=None,
head=os.getenv("HEAD"),
head=os.getenv("HEAD", "") + head,
cache_examples="lazy",
api_name=False,
)


demo.queue(
demo = demo.queue(
max_size=20,
default_concurrency_limit=20,
).launch(
show_api=False,
)

app = gr.mount_gradio_app(app, demo, path="/")

if __name__ == "__main__":
demo.launch(show_api=False)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ loguru~=0.7
pypdf~=4.1
tenacity~=8.3
sentry-sdk~=2.5
granian~=1.4
Binary file added static/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4ae356e

Please sign in to comment.