Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ class ContentRequest:
|
|
17 |
prompt_key: str
|
18 |
|
19 |
class ContentGenerator:
|
20 |
-
def __init__(self,
|
21 |
self.current_prompts = self._load_default_prompts()
|
22 |
self.client = genai.Client(api_key=api_key)
|
23 |
|
@@ -117,8 +117,8 @@ def get_transcript(video_id: str) -> str:
|
|
117 |
return f"Error fetching transcript: {str(e)}"
|
118 |
|
119 |
class TranscriptProcessor:
|
120 |
-
def __init__(self
|
121 |
-
self.generator = ContentGenerator(api_key=
|
122 |
|
123 |
|
124 |
def _get_youtube_transcript(self, url: str) -> str:
|
@@ -130,11 +130,11 @@ class TranscriptProcessor:
|
|
130 |
except Exception as e:
|
131 |
raise Exception(f"Error fetching YouTube transcript: {str(e)}")
|
132 |
|
133 |
-
async def process_transcript(self, audio_file
|
134 |
"""Process input and generate all content."""
|
135 |
audio_path = audio_file.name
|
136 |
try:
|
137 |
-
aai.settings.api_key =
|
138 |
config = aai.TranscriptionConfig(speaker_labels=True, language_code="en")
|
139 |
transcript_iter = aai.Transcriber().transcribe(str(audio_path), config=config)
|
140 |
transcript = transcript_iter.text
|
@@ -184,50 +184,39 @@ class TranscriptProcessor:
|
|
184 |
|
185 |
def create_interface():
|
186 |
"""Create the Gradio interface."""
|
|
|
187 |
|
188 |
-
with gr.Blocks(title="
|
189 |
gr.Markdown(
|
190 |
"""
|
191 |
-
#
|
192 |
-
Generate preview clips, timestamps, descriptions and more from podcast transcripts
|
193 |
|
194 |
-
|
195 |
"""
|
196 |
)
|
197 |
|
198 |
with gr.Tab("Generate Content"):
|
199 |
-
google_api_key_input = gr.Textbox(
|
200 |
-
label="Google API Key",
|
201 |
-
placeholder="Enter your Google API Key here",
|
202 |
-
type="password",
|
203 |
-
lines=1,
|
204 |
-
info="Your GCP account needs to have billing enabled to use the 2.5 pro model.",
|
205 |
-
scale=1
|
206 |
-
)
|
207 |
-
assemblyai_api_key_input = gr.Textbox(
|
208 |
-
label="AssemblyAI API Key",
|
209 |
-
placeholder="Enter your AssemblyAI API Key here",
|
210 |
-
type="password",
|
211 |
-
lines=1,
|
212 |
-
info="Your key is used for initial audio transcription.",
|
213 |
-
scale=1
|
214 |
-
)
|
215 |
input_audio = gr.File(
|
216 |
label="Upload Audio File",
|
217 |
file_count="single",
|
218 |
file_types=["audio"]
|
219 |
)
|
220 |
-
|
221 |
-
|
|
|
|
|
|
|
|
|
222 |
|
223 |
output = gr.Markdown() # Single markdown output
|
224 |
|
225 |
-
async def process_wrapper(text
|
226 |
print("Process wrapper started")
|
227 |
print(f"Input text: {text[:100]}...")
|
228 |
|
229 |
try:
|
230 |
-
result = await processor.process_transcript(text
|
231 |
print("Process completed, got results")
|
232 |
return result
|
233 |
except Exception as e:
|
@@ -236,7 +225,7 @@ def create_interface():
|
|
236 |
|
237 |
submit_btn.click(
|
238 |
fn=process_wrapper,
|
239 |
-
inputs=
|
240 |
outputs=output,
|
241 |
queue=True
|
242 |
)
|
@@ -244,7 +233,7 @@ def create_interface():
|
|
244 |
with gr.Tab("Customize Prompts"):
|
245 |
gr.Markdown(
|
246 |
"""
|
247 |
-
## Customize Generation Prompts
|
248 |
Here you can experiment with different prompts during your session.
|
249 |
Changes will remain active until you reload the page.
|
250 |
|
@@ -277,7 +266,7 @@ def create_interface():
|
|
277 |
)
|
278 |
|
279 |
# Reset button
|
280 |
-
reset_btn = gr.Button("Reset to Default
|
281 |
reset_btn.click(
|
282 |
fn=lambda: (
|
283 |
processor.update_prompts(*processor.generator.current_prompts.values()),
|
@@ -289,4 +278,4 @@ def create_interface():
|
|
289 |
return app
|
290 |
|
291 |
if __name__ == "__main__":
|
292 |
-
create_interface().launch(
|
|
|
17 |
prompt_key: str
|
18 |
|
19 |
class ContentGenerator:
|
20 |
+
def __init__(self,api_key):
|
21 |
self.current_prompts = self._load_default_prompts()
|
22 |
self.client = genai.Client(api_key=api_key)
|
23 |
|
|
|
117 |
return f"Error fetching transcript: {str(e)}"
|
118 |
|
119 |
class TranscriptProcessor:
|
120 |
+
def __init__(self):
|
121 |
+
self.generator = ContentGenerator(api_key=os.getenv("GOOGLE_API_KEY"))
|
122 |
|
123 |
|
124 |
def _get_youtube_transcript(self, url: str) -> str:
|
|
|
130 |
except Exception as e:
|
131 |
raise Exception(f"Error fetching YouTube transcript: {str(e)}")
|
132 |
|
133 |
+
async def process_transcript(self, audio_file):
|
134 |
"""Process input and generate all content."""
|
135 |
audio_path = audio_file.name
|
136 |
try:
|
137 |
+
aai.settings.api_key = os.getenv("ASSEMBLYAI_API_KEY")
|
138 |
config = aai.TranscriptionConfig(speaker_labels=True, language_code="en")
|
139 |
transcript_iter = aai.Transcriber().transcribe(str(audio_path), config=config)
|
140 |
transcript = transcript_iter.text
|
|
|
184 |
|
185 |
def create_interface():
|
186 |
"""Create the Gradio interface."""
|
187 |
+
processor = TranscriptProcessor()
|
188 |
|
189 |
+
with gr.Blocks(title="Podcast Content Generator") as app:
|
190 |
gr.Markdown(
|
191 |
"""
|
192 |
+
# Podcast Content Generator
|
193 |
+
Generate preview clips, timestamps, descriptions and more from podcast transcripts or YouTube videos.
|
194 |
|
195 |
+
Simply paste a YouTube URL or raw transcript text to get started!
|
196 |
"""
|
197 |
)
|
198 |
|
199 |
with gr.Tab("Generate Content"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
input_audio = gr.File(
|
201 |
label="Upload Audio File",
|
202 |
file_count="single",
|
203 |
file_types=["audio"]
|
204 |
)
|
205 |
+
input_text = gr.Textbox(
|
206 |
+
label="Youtube URL",
|
207 |
+
placeholder="YouTube URL",
|
208 |
+
lines=1
|
209 |
+
)
|
210 |
+
submit_btn = gr.Button("Generate Content")
|
211 |
|
212 |
output = gr.Markdown() # Single markdown output
|
213 |
|
214 |
+
async def process_wrapper(text):
|
215 |
print("Process wrapper started")
|
216 |
print(f"Input text: {text[:100]}...")
|
217 |
|
218 |
try:
|
219 |
+
result = await processor.process_transcript(text)
|
220 |
print("Process completed, got results")
|
221 |
return result
|
222 |
except Exception as e:
|
|
|
225 |
|
226 |
submit_btn.click(
|
227 |
fn=process_wrapper,
|
228 |
+
inputs=input_audio,
|
229 |
outputs=output,
|
230 |
queue=True
|
231 |
)
|
|
|
233 |
with gr.Tab("Customize Prompts"):
|
234 |
gr.Markdown(
|
235 |
"""
|
236 |
+
## Customize Generation Prompts
|
237 |
Here you can experiment with different prompts during your session.
|
238 |
Changes will remain active until you reload the page.
|
239 |
|
|
|
266 |
)
|
267 |
|
268 |
# Reset button
|
269 |
+
reset_btn = gr.Button("Reset to Default Prompts")
|
270 |
reset_btn.click(
|
271 |
fn=lambda: (
|
272 |
processor.update_prompts(*processor.generator.current_prompts.values()),
|
|
|
278 |
return app
|
279 |
|
280 |
if __name__ == "__main__":
|
281 |
+
create_interface().launch(
|