tmleyncodes/LumeCast
1
1import gradio as gr2from gradio_client import Client, handle_file3import tempfile4import os5 6def convert_pdf_to_podcast(pdf_file, url, question, tone, length, language, use_advanced_audio):7 """Convert PDF to podcast using Hugging Face API"""8 try:9 # Save uploaded file to temporary location10 with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as tmp_file:11 tmp_file.write(pdf_file)12 temp_path = tmp_file.name13 14 # Initialize client and make prediction15 client = Client("gabrielchua/open-notebooklm")16 result = client.predict(17 files=[handle_file(temp_path)],18 url=url,19 question=question,20 tone=tone,21 length=length,22 language=language,23 use_advanced_audio=use_advanced_audio,24 api_name="/generate_podcast"25 )26 27 # Clean up temp file28 os.unlink(temp_path)29 30 return result[0], result[1] # Returns (audio_path, transcript)31 32 except Exception as e:33 return None, f"Error: {str(e)}"34 35# Create Gradio interface36with gr.Blocks(title="LumeCast: Convert PDFs to Podcasts") as demo:37 gr.Markdown("# LumeCast: Convert PDFs to Podcasts")38 39 with gr.Row():40 with gr.Column():41 # Input components42 pdf_input = gr.File(43 label="Upload your PDF",44 file_types=[".pdf"],45 type="binary"46 )47 48 url_input = gr.Textbox(49 label="URL (optional)",50 placeholder="Enter URL here...",51 value=""52 )53 54 question_input = gr.Textbox(55 label="Question or Topic",56 placeholder="What would you like to focus on?",57 value=""58 )59 60 tone_input = gr.Radio(61 label="Select Tone",62 choices=["Fun", "Formal"],63 value="Fun"64 )65 66 length_input = gr.Radio(67 label="Select Length",68 choices=["Short (1-2 min)", "Medium (3-5 min)"],69 value="Medium (3-5 min)"70 )71 72 language_input = gr.Dropdown(73 label="Select Language",74 choices=[75 "English", "Spanish", "French", "German",76 "Chinese", "Japanese", "Korean", "Hindi",77 "Portuguese", "Russian", "Italian", "Turkish", "Polish"78 ],79 value="English"80 )81 82 advanced_audio = gr.Checkbox(83 label="Use Advanced Audio Generation",84 value=True85 )86 87 convert_btn = gr.Button("Convert to Podcast")88 89 with gr.Column():90 # Output components91 audio_output = gr.Audio(label="Generated Podcast")92 transcript_output = gr.Markdown(label="Transcript")93 status_output = gr.Textbox(label="Status", interactive=False)94 95 # Handle conversion96 convert_btn.click(97 fn=convert_pdf_to_podcast,98 inputs=[99 pdf_input,100 url_input,101 question_input,102 tone_input,103 length_input,104 language_input,105 advanced_audio106 ],107 outputs=[audio_output, transcript_output]108 )109 110# Launch the app111if __name__ == "__main__":112 demo.launch(share=True)113 114app = demo.app