Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
knowsuchagency committed Jun 9, 2024
1 parent 5cb24e8 commit 9974fbf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

gradio_cached_examples/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

gradio_cached_examples/
.DS_Store
Binary file added examples/Accessible Quantum Field Theory.pdf
Binary file not shown.
Binary file added examples/Attention is all you need.pdf
Binary file not shown.
Binary file added examples/Gene therapy for deafness.pdf
Binary file not shown.
11 changes: 8 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import io
import os
from typing import List, Literal
from pathlib import Path

import gradio as gr
from loguru import logger
Expand Down Expand Up @@ -78,12 +79,12 @@ def get_mp3(text: str, voice: str, api_key: str = None) -> bytes:
return file.getvalue()


def generate_audio(file: bytes, openai_api_key: str = None) -> bytes:
def generate_audio(file: str, openai_api_key: str = None) -> bytes:

if not os.getenv("OPENAI_API_KEY", openai_api_key):
raise gr.Error("OpenAI API key is required")

reader = PdfReader(io.BytesIO(file))
reader = PdfReader(Path(file).open("rb"))
text = "\n\n".join([page.extract_text() for page in reader.pages])

llm_output = generate_dialogue(text)
Expand All @@ -108,6 +109,7 @@ def generate_audio(file: bytes, openai_api_key: str = None) -> bytes:

return audio, 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>
Expand All @@ -118,10 +120,11 @@ def generate_audio(file: bytes, openai_api_key: str = None) -> bytes:
title="PDF to Podcast",
description=description,
fn=generate_audio,
examples=[[p.__fspath__()] for p in Path("examples").glob("*.pdf")],
inputs=[
gr.File(
label="PDF",
type="binary",
# type="binary",
),
gr.Textbox(
label="OpenAI API Key",
Expand All @@ -135,6 +138,8 @@ def generate_audio(file: bytes, openai_api_key: str = None) -> bytes:
allow_flagging=False,
clear_btn=None,
head=os.getenv("HEAD"),
concurrency_limit=20,
cache_examples="lazy",
)

demo.launch(
Expand Down

0 comments on commit 9974fbf

Please sign in to comment.