Spaces:
Runtime error
Runtime error
knowsuchagency
commited on
Commit
•
74e9bb4
1
Parent(s):
5cb24e8
add examples
Browse files- .dockerignore +2 -0
- .gitignore +3 -0
- main.py +8 -3
.dockerignore
CHANGED
@@ -160,3 +160,5 @@ cython_debug/
|
|
160 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
161 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
162 |
#.idea/
|
|
|
|
|
|
160 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
161 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
162 |
#.idea/
|
163 |
+
|
164 |
+
gradio_cached_examples/
|
.gitignore
CHANGED
@@ -160,3 +160,6 @@ cython_debug/
|
|
160 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
161 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
162 |
#.idea/
|
|
|
|
|
|
|
|
160 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
161 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
162 |
#.idea/
|
163 |
+
|
164 |
+
gradio_cached_examples/
|
165 |
+
.DS_Store
|
main.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import io
|
2 |
import os
|
3 |
from typing import List, Literal
|
|
|
4 |
|
5 |
import gradio as gr
|
6 |
from loguru import logger
|
@@ -78,12 +79,12 @@ def get_mp3(text: str, voice: str, api_key: str = None) -> bytes:
|
|
78 |
return file.getvalue()
|
79 |
|
80 |
|
81 |
-
def generate_audio(file:
|
82 |
|
83 |
if not os.getenv("OPENAI_API_KEY", openai_api_key):
|
84 |
raise gr.Error("OpenAI API key is required")
|
85 |
|
86 |
-
reader = PdfReader(
|
87 |
text = "\n\n".join([page.extract_text() for page in reader.pages])
|
88 |
|
89 |
llm_output = generate_dialogue(text)
|
@@ -108,6 +109,7 @@ def generate_audio(file: bytes, openai_api_key: str = None) -> bytes:
|
|
108 |
|
109 |
return audio, transcript
|
110 |
|
|
|
111 |
description = """
|
112 |
<p style="text-align:center">
|
113 |
<strong>Convert any PDF into a podcast episode! Experience research papers, websites, and more in a whole new way.</strong>
|
@@ -118,10 +120,11 @@ demo = gr.Interface(
|
|
118 |
title="PDF to Podcast",
|
119 |
description=description,
|
120 |
fn=generate_audio,
|
|
|
121 |
inputs=[
|
122 |
gr.File(
|
123 |
label="PDF",
|
124 |
-
type="binary",
|
125 |
),
|
126 |
gr.Textbox(
|
127 |
label="OpenAI API Key",
|
@@ -135,6 +138,8 @@ demo = gr.Interface(
|
|
135 |
allow_flagging=False,
|
136 |
clear_btn=None,
|
137 |
head=os.getenv("HEAD"),
|
|
|
|
|
138 |
)
|
139 |
|
140 |
demo.launch(
|
|
|
1 |
import io
|
2 |
import os
|
3 |
from typing import List, Literal
|
4 |
+
from pathlib import Path
|
5 |
|
6 |
import gradio as gr
|
7 |
from loguru import logger
|
|
|
79 |
return file.getvalue()
|
80 |
|
81 |
|
82 |
+
def generate_audio(file: str, openai_api_key: str = None) -> bytes:
|
83 |
|
84 |
if not os.getenv("OPENAI_API_KEY", openai_api_key):
|
85 |
raise gr.Error("OpenAI API key is required")
|
86 |
|
87 |
+
reader = PdfReader(Path(file).open("rb"))
|
88 |
text = "\n\n".join([page.extract_text() for page in reader.pages])
|
89 |
|
90 |
llm_output = generate_dialogue(text)
|
|
|
109 |
|
110 |
return audio, transcript
|
111 |
|
112 |
+
|
113 |
description = """
|
114 |
<p style="text-align:center">
|
115 |
<strong>Convert any PDF into a podcast episode! Experience research papers, websites, and more in a whole new way.</strong>
|
|
|
120 |
title="PDF to Podcast",
|
121 |
description=description,
|
122 |
fn=generate_audio,
|
123 |
+
examples=[[p.__fspath__()] for p in Path("examples").glob("*.pdf")],
|
124 |
inputs=[
|
125 |
gr.File(
|
126 |
label="PDF",
|
127 |
+
# type="binary",
|
128 |
),
|
129 |
gr.Textbox(
|
130 |
label="OpenAI API Key",
|
|
|
138 |
allow_flagging=False,
|
139 |
clear_btn=None,
|
140 |
head=os.getenv("HEAD"),
|
141 |
+
concurrency_limit=20,
|
142 |
+
cache_examples="lazy",
|
143 |
)
|
144 |
|
145 |
demo.launch(
|