Spaces:
Running
Running
Update app.py
Browse filesUpdated edit, a few new templates, etc.
32 unmodified lines3334353637383929 unmodified lines697071727374751 unmodified line777879808182389 unmodified lines47247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350447 unmodified lines55255355455555655719 unmodified lines5775785795805815825835845855865878 unmodified lines59659759859960060160211 unmodified lines61461561661761861962062162262362462510 unmodified lines6366376386396406411 unmodified line64364464564664764864965065165265365465565613 unmodified lines67067167267367467567672 unmodified lines7497507517527537544 unmodified lines7597607617627637647657667677687697707717727737747757769 unmodified lines78678778878979079123 unmodified lines81581681781881982068 unmodified lines88989089189289389434 unmodified lines9299309319329339349354 unmodified lines94094194294394494514 unmodified lines9609619629639649659669679689699709719729739745 unmodified lines9809819829839849859863 unmodified lines99099199299399499599699799899910001001100210035 unmodified lines10091010101110121013101432 unmodified linesINSTRUCTION_TEMPLATES = {################# DEEP DATA ANALYSIS ##################"Deep research analysis": {# 1) High‑level task description"intro": """You are a senior analyst who conducts deep research.29 unmodified lines"prelude": """Below is the structured report based on the supplied raw data:""",# 5) Main output instructions"dialog": """Design your output to be read aloud -- it will be directly converted into audio. The presentation of materials should include 30,000 words.There is only one speaker, you. Stay on topic and maintaining an engaging flow.1 unmodified line},################# PODCAST ##################"podcast": {"intro": """Your task is to take the input text provided and turn it into an lively, engaging, informative podcast dialogue, in the style of NPR. Do not use or make up names. The input text may be messy or unstructured, as it could come from a variety of sources like PDFs or web pages.389 unmodified lines},}# Function to update instruction fields based on template selectiondef update_instructions(template):return (INSTRUCTION_TEMPLATES[template]["intro"],INSTRUCTION_TEMPLATES[template]["text_instructions"],INSTRUCTION_TEMPLATES[template]["scratch_pad"],INSTRUCTION_TEMPLATES[template]["prelude"],INSTRUCTION_TEMPLATES[template]["dialog"])import concurrent.futures as cfimport globimport ioimport osimport timefrom pathlib import Pathfrom tempfile import NamedTemporaryFilefrom typing import List, Literalimport gradio as grfrom loguru import loggerfrom openai import OpenAIfrom promptic import llmfrom pydantic import BaseModel, ValidationErrorfrom pypdf import PdfReaderfrom tenacity import retry, retry_if_exception_type# Define standard valuesSTANDARD_TEXT_MODELS = [47 unmodified lines]class DialogueItem(BaseModel):text: strspeaker: Literal["speaker-1", "speaker-2"]19 unmodified lines'''def get_mp3(text: str, voice: str, audio_model: str, api_key: str = None,speaker_instructions: str ='Speak in an emotive and friendly tone.') -> bytes:client = OpenAI(api_key=api_key or os.getenv("OPENAI_API_KEY"),)with client.audio.speech.with_streaming_response.create(model=audio_model,voice=voice,8 unmodified linesfrom functools import wrapsdef conditional_llm(model, api_base=None, api_key=None, reasoning_effort="N/A"):"""Conditionally apply the @llm decorator based on the api_base parameter.11 unmodified linesreturn llm(model=model, api_key=api_key, reasoning_effort=reasoning_effort)(func)return decoratordef generate_audio(files: list,openai_api_key: str = None,text_model: str = "o4-mini", #o1-2024-12-17", #"o1-preview-2024-09-12",reasoning_effort: str = "N/A",audio_model: str = "tts-1",speaker_1_voice: str = "alloy",speaker_2_voice: str = "echo",10 unmodified linesoriginal_text: str = None,debug = False,) -> tuple:# Validate API Keyif not os.getenv("OPENAI_API_KEY") and not openai_api_key:raise gr.Error("OpenAI API key is required")1 unmodified linecombined_text = original_text or ""# If there's no original text, extract it from the uploaded files'''if not combined_text:for file in files:with Path(file).open("rb") as f:reader = PdfReader(f)text = "\n\n".join([page.extract_text() for page in reader.pages if page.extract_text()])combined_text += text + "\n\n"'''if not combined_text:for file in files:13 unmodified linescombined_text += text + "\n\n"# Configure the LLM based on selected model and api_base@retry(retry=retry_if_exception_type(ValidationError))@conditional_llm(model=text_model, api_base=api_base, api_key=openai_api_key)def generate_dialogue(text: str, intro_instructions: str, text_instructions: str, scratch_pad_instructions: str,prelude_dialog: str, podcast_dialog_instructions: str,edited_transcript: str = None, user_feedback: str = None, ) -> Dialogue:72 unmodified linestemporary_file = NamedTemporaryFile(dir=temporary_directory,delete=False,suffix=".mp3",)temporary_file.write(audio)4 unmodified linesif os.path.isfile(file) and time.time() - os.path.getmtime(file) > 24 * 60 * 60:os.remove(file)return temporary_file.name, transcript, combined_textdef validate_and_generate_audio(*args):files = args[0]if not files:return None, None, None, "Please upload at least one PDF (or MD/MMD/TXT) file before generating audio."try:audio_file, transcript, original_text = generate_audio(*args)return audio_file, transcript, original_text, None # Return None as the error when successfulexcept Exception as e:# If an error occurs during generation, return None for the outputs and the error messagereturn None, None, None, str(e)def edit_and_regenerate(edited_transcript, user_feedback, *args):# Replace the original transcript and feedback in the args with the new ones9 unmodified linesnew_args.append(feedback) # Add user feedback as a new argumentreturn validate_and_generate_audio(*new_args)with gr.Blocks(title="PDF to Audio", css="""#header {display: flex;23 unmodified linesmargin-top: 20px;}""") as demo:with gr.Row(elem_id="header"):with gr.Column(scale=4):68 unmodified linesinfo="If you are using a custom or local model, provide the API base URL here, e.g.: http://localhost:8080/v1 for llama.cpp REST server.",)with gr.Column(scale=3):template_dropdown = gr.Dropdown(label="Instruction Template",34 unmodified lines)audio_output = gr.Audio(label="Audio", format="mp3", interactive=False, autoplay=False)transcript_output = gr.Textbox(label="Transcript", lines=20, show_copy_button=True)original_text_output = gr.Textbox(label="Original Text", lines=10, visible=False)error_output = gr.Textbox(visible=False) # Hidden textbox to store error message4 unmodified linesuser_feedback = gr.Textbox(label="Provide Feedback or Notes", lines=10, #placeholder="Enter your feedback or notes here...")regenerate_btn = gr.Button("Regenerate Audio with Edits and Feedback")# Function to update the interactive state of edited_transcriptdef update_edit_box(checkbox_value):return gr.update(interactive=checkbox_value, lines=20 if checkbox_value else 20, visible=True if checkbox_value else False)14 unmodified linessubmit_btn.click(fn=validate_and_generate_audio,inputs=[files, openai_api_key, text_model, reasoning_effort, audio_model,speaker_1_voice, speaker_2_voice, speaker_1_instructions, speaker_2_instructions,api_base,intro_instructions, text_instructions, scratch_pad_instructions,prelude_dialog, podcast_dialog_instructions,edited_transcript, # placeholder for edited_transcriptuser_feedback, # placeholder for user_feedback],outputs=[audio_output, transcript_output, original_text_output, error_output]).then(fn=lambda audio, transcript, original_text, error: (transcript if transcript else "",5 unmodified linesfn=lambda error: gr.Warning(error) if error else None,inputs=[error_output],outputs=[])regenerate_btn.click(fn=lambda use_edit, edit, *args: validate_and_generate_audio(3 unmodified lines),inputs=[use_edited_transcript, edited_transcript,files, openai_api_key, text_model, reasoning_effort, audio_model,speaker_1_voice, speaker_2_voice, speaker_1_instructions, speaker_2_instructions,api_base,intro_instructions, text_instructions, scratch_pad_instructions,prelude_dialog, podcast_dialog_instructions,user_feedback, original_text_output],outputs=[audio_output, transcript_output, original_text_output, error_output]).then(fn=lambda audio, transcript, original_text, error: (transcript if transcript else "",5 unmodified linesfn=lambda error: gr.Warning(error) if error else None,inputs=[error_output],outputs=[])# Add README content at the bottom32 unmodified lines3334353637383929 unmodified lines6970717273747576771 unmodified line798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126389 unmodified lines51651751851952052147 unmodified lines56957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260319 unmodified lines6236246256266276286296306316326338 unmodified lines64264364464564664764811 unmodified lines66066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270310 unmodified lines7147157167177187197207211 unmodified line72372472572672772872913 unmodified lines74374474574674774874975075175275375475575672 unmodified lines8298308318328338348354 unmodified lines8408418428438448458468478488498508518528538548558568578588598609 unmodified lines87087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699723 unmodified lines1021102210231024102510261027102868 unmodified lines10971098109911001101110211031104110511061107110834 unmodified lines11431144114511461147114811494 unmodified lines11541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119814 unmodified lines12131214121512161217121812191220122112221223122412251226122712285 unmodified lines123412351236123712381239124012411242124312443 unmodified lines124812491250125112521253125412551256125712581259126012615 unmodified lines1267126812691270127112721273127412751276127712781279128012811282128312841285128632 unmodified linesINSTRUCTION_TEMPLATES = {################# DEEP DATA ANALYSIS ##################"deep research analysis": {# 1) High‑level task description"intro": """You are a senior analyst who conducts deep research.29 unmodified lines"prelude": """Below is the structured report based on the supplied raw data:""",# 5) Main output instructions"dialog": """Design your output to be read aloud -- it will be directly converted into audio. The presentation of materials should include 30,000 words.If you have equations, variables or other complex concepts, make sure to design your output so that it can be clearly rendered by a text-to-voice model.There is only one speaker, you. Stay on topic and maintaining an engaging flow.1 unmodified line},################# CLEAN READ‑THROUGH ##################"clean rendering": {# 1) What the model should do"intro": """You are a careful narrator tasked with producing an **accurate, faithful rendering** of the supplied document so it can be read aloud.Your priorities are:• Preserve the original wording and ordering of the content.• Remove anything that is clearly an artefact of page layout (page numbers, running headers/footers, line numbers, PDF crop marks, hyphen‑splits at line wraps).• Keep mathematical symbols, equations and variable names intact, but read them in a way a TTS system can pronounce (e.g. “square root of”, “alpha sub i”).• Do **not** add commentary, summaries, or extra explanations—just the cleaned text.• Present everything in the **same sequence** as in the source.Output must be suitable for text‑to‑speech; begin every paragraph with `speaker-1:` and write as a single narrator.""",# 2) How to cleanse the raw text"text_instructions": """Scan the input for artefacts such as:- Stand‑alone page numbers or headers like “Page 12 of 30”- Repeated footers, URLs or timestamps- Manual hyphenation at line breaks (join split words)- Broken tables or columns (flatten them into continuous sentences where possible)Strip these while keeping all legitimate content. Do **not** reorder paragraphs or sentences.""",# 3) Hidden scratch‑pad for the model"scratch_pad": """Brainstorm here (hidden):- Identify obvious header/footer patterns to delete.- Decide how to handle any malformed tables (e.g. read row‑by‑row).- Note any equations that need a spoken equivalent.After cleaning decisions are made, move on to generate the final narration.""",# 4) Prelude before the narration starts"prelude": """Below is the faithful narration of the provided document (cleaned of layout artefacts, otherwise unchanged):""",# 5) Main output instructions"dialog": """Design your output to be read aloud—no markup, no bracketed directions.Only one speaker (`speaker-1:`).Maintain original headings and paragraph breaks where they naturally occur in the source.If an equation appears, read it in a TTS‑friendly style (e.g. `speaker-1: E equals m times c squared`)."""},################# PODCAST ##################"podcast": {"intro": """Your task is to take the input text provided and turn it into an lively, engaging, informative podcast dialogue, in the style of NPR. Do not use or make up names. The input text may be messy or unstructured, as it could come from a variety of sources like PDFs or web pages.389 unmodified lines},}# Define standard valuesSTANDARD_TEXT_MODELS = [47 unmodified lines]# Function to update instruction fields based on template selectiondef update_instructions(template):return (INSTRUCTION_TEMPLATES[template]["intro"],INSTRUCTION_TEMPLATES[template]["text_instructions"],INSTRUCTION_TEMPLATES[template]["scratch_pad"],INSTRUCTION_TEMPLATES[template]["prelude"],INSTRUCTION_TEMPLATES[template]["dialog"])import concurrent.futures as cfimport globimport ioimport osimport timefrom pathlib import Pathfrom tempfile import NamedTemporaryFilefrom typing import List, Literalimport gradio as grfrom loguru import loggerfrom openai import OpenAIfrom promptic import llmfrom pydantic import BaseModel, ValidationErrorfrom pypdf import PdfReaderfrom tenacity import retry, retry_if_exception_typeclass DialogueItem(BaseModel):text: strspeaker: Literal["speaker-1", "speaker-2"]19 unmodified lines'''def get_mp3(text: str, voice: str, audio_model: str, api_key: str = None,speaker_instructions: str ='Speak in an emotive and friendly tone.') -> bytes:client = OpenAI(api_key=api_key or os.getenv("OPENAI_API_KEY"),)with client.audio.speech.with_streaming_response.create(model=audio_model,voice=voice,8 unmodified linesfrom functools import wraps'''def conditional_llm(model, api_base=None, api_key=None, reasoning_effort="N/A"):"""Conditionally apply the @llm decorator based on the api_base parameter.11 unmodified linesreturn llm(model=model, api_key=api_key, reasoning_effort=reasoning_effort)(func)return decorator'''def conditional_llm(model,api_base=None,api_key=None,reasoning_effort="N/A",do_web_search=False,):"""Wrap a function with the @llm decorator, choosing kwargs dynamically.Adds `web_search_options={}` when do_web_search==True."""# build decorator kwargs once so we don’t repeat logicdecorator_kwargs = {"model": model}if api_base:decorator_kwargs["api_base"] = api_baseelse:decorator_kwargs["api_key"] = api_keyif reasoning_effort != "N/A":decorator_kwargs["reasoning_effort"] = reasoning_effortif do_web_search:decorator_kwargs["web_search_options"] = {} # empty dict → default behaviourdef decorator(func):return llm(**decorator_kwargs)(func)return decoratordef generate_audio(files: list,openai_api_key: str = None,text_model: str = "o4-mini", #o1-2024-12-17", #"o1-preview-2024-09-12",reasoning_effort: str = "N/A",do_web_search: bool = False,audio_model: str = "tts-1",speaker_1_voice: str = "alloy",speaker_2_voice: str = "echo",10 unmodified linesoriginal_text: str = None,debug = False,) -> tuple:# Validate API Keyif not os.getenv("OPENAI_API_KEY") and not openai_api_key:raise gr.Error("OpenAI API key is required")1 unmodified linecombined_text = original_text or ""# If there's no original text, extract it from the uploaded filesif not combined_text:for file in files:13 unmodified linescombined_text += text + "\n\n"# Configure the LLM based on selected model and api_base@retry(retry=retry_if_exception_type(ValidationError))#@conditional_llm(model=text_model, api_base=api_base, api_key=openai_api_key)@conditional_llm(model=text_model,api_base=api_base,api_key=openai_api_key,reasoning_effort=reasoning_effort,do_web_search=do_web_search,)def generate_dialogue(text: str, intro_instructions: str, text_instructions: str, scratch_pad_instructions: str,prelude_dialog: str, podcast_dialog_instructions: str,edited_transcript: str = None, user_feedback: str = None, ) -> Dialogue:72 unmodified linestemporary_file = NamedTemporaryFile(dir=temporary_directory,delete=False,prefix="PDF2Audio_",suffix=".mp3",)temporary_file.write(audio)4 unmodified linesif os.path.isfile(file) and time.time() - os.path.getmtime(file) > 24 * 60 * 60:os.remove(file)return temporary_file.name, transcript, combined_text, llm_outputdef validate_and_generate_audio(*args):files = args[0]if not files:return None, None, None, "Please upload at least one PDF (or MD/MMD/TXT) file before generating audio."try:#audio_file, transcript, original_text = generate_audio(*args)audio_file, transcript, original_text, dialogue = generate_audio(*args)return audio_file, transcript, original_text, None, dialogue #except Exception as e:return None, None, None, str(e), None #def edit_and_regenerate(edited_transcript, user_feedback, *args):# Replace the original transcript and feedback in the args with the new ones9 unmodified linesnew_args.append(feedback) # Add user feedback as a new argumentreturn validate_and_generate_audio(*new_args)#####################################################Download dialog/result as markdown####################################################def dialogue_to_markdown(dlg: Dialogue) -> str:lines = []lines.append("# PDF2Audio Transcript\n")lines.append("## Transcript\n")for item in dlg.dialogue:lines.append(f"**{item.speaker}:** {item.text.strip()}\n")return "\n".join(lines)def save_dialogue_as_markdown(cached_dialogue) -> str:if cached_dialogue is None:raise gr.Error("No dialogue to save. Please generate or edit a dialogue first.")markdown_text = dialogue_to_markdown(cached_dialogue)# Write to a temporary .md filetemp_dir = "./gradio_cached_examples/tmp/"os.makedirs(temp_dir, exist_ok=True)file_path = os.path.join(temp_dir, f"PDF2Audio_dialogue_{int(time.time())}.md")with open(file_path, "w", encoding="utf-8") as f:f.write(markdown_text)return file_path#####################################################Edit and re-render audio from existing LLM output####################################################import pandas as pdfrom typing import Listdef dialogue_to_df(dlg: Dialogue) -> pd.DataFrame:data = [{"Speaker": item.speaker, "Line": item.text} for item in dlg.dialogue]return pd.DataFrame(data)def df_to_dialogue(df: pd.DataFrame, scratchpad: str = "") -> Dialogue:items: List[DialogueItem] = [DialogueItem(speaker=row["Speaker"], text=row["Line"])for _, row in df.iterrows()]return Dialogue(scratchpad=scratchpad, dialogue=items)def save_dialogue_edits(df, cached_dialogue):"""Save the edited dialogue and update the per-session cached state."""if cached_dialogue is None:raise gr.Error("Nothing to edit yet – run Generate Audio first.")import pandas as pdnew_dlg = df_to_dialogue(pd.DataFrame(df, columns=["Speaker", "Line"]))# regenerate plain transcript so the user sees the change immediatelytranscript_str = "\n".join(f"{d.speaker}: {d.text}" for d in new_dlg.dialogue)# Return updated state and transcriptreturn new_dlg, gr.update(value=transcript_str), "Edits saved. Press *Re‑render* to hear them."def render_audio_from_dialogue(cached_dialogue, # 👈 NEW: pass in as argumentopenai_api_key: str,audio_model: str,speaker_1_voice: str,speaker_2_voice: str,speaker_1_instructions: str,speaker_2_instructions: str,) -> tuple[str, str]: # mp3 file path, transcriptif cached_dialogue is None:raise gr.Error("Nothing to re‑render yet – run Generate Audio first.")dlg = cached_dialogueaudio_bytes, transcript, characters = b"", "", 0with cf.ThreadPoolExecutor() as ex:futures = []for item in dlg.dialogue:voice = speaker_1_voice if item.speaker == "speaker-1" else speaker_2_voiceinstr = speaker_1_instructions if item.speaker == "speaker-1" else speaker_2_instructionsfutures.append((ex.submit(get_mp3, item.text, voice, audio_model, openai_api_key, instr),f"{item.speaker}: {item.text}",))characters += len(item.text)for fut, line in futures:audio_bytes += fut.result()transcript += line + "\n\n"logger.info(f"[Re‑render] {characters} characters voiced")# Write to temporary .mp3 filetemporary_directory = "./gradio_cached_examples/tmp/"os.makedirs(temporary_directory, exist_ok=True)temporary_file = NamedTemporaryFile(dir=temporary_directory,delete=False,prefix="PDF2Audio_",suffix=".mp3",)temporary_file.write(audio_bytes)temporary_file.close()# Clean up old filesfor file in glob.glob(f"{temporary_directory}*.mp3"):if os.path.isfile(file) and time.time() - os.path.getmtime(file) > 24 * 60 * 60:os.remove(file)return temporary_file.name, transcriptwith gr.Blocks(title="PDF to Audio", css="""#header {display: flex;23 unmodified linesmargin-top: 20px;}""") as demo:cached_dialogue = gr.State()with gr.Row(elem_id="header"):with gr.Column(scale=4):68 unmodified linesinfo="If you are using a custom or local model, provide the API base URL here, e.g.: http://localhost:8080/v1 for llama.cpp REST server.",)do_web_search = gr.Checkbox(label="Let the LLM search the web to complement the documents.",value=False,info="When enabled, the LLM will call the web search tool during its reasoning.")with gr.Column(scale=3):template_dropdown = gr.Dropdown(label="Instruction Template",34 unmodified lines)audio_output = gr.Audio(label="Audio", format="mp3", interactive=False, autoplay=False)transcript_output = gr.Textbox(label="Transcript", lines=25, show_copy_button=True)original_text_output = gr.Textbox(label="Original Text", lines=10, visible=False)error_output = gr.Textbox(visible=False) # Hidden textbox to store error message4 unmodified linesuser_feedback = gr.Textbox(label="Provide Feedback or Notes", lines=10, #placeholder="Enter your feedback or notes here...")regenerate_btn = gr.Button("Regenerate Audio with Edits and Feedback")with gr.Accordion("Edit dialogue line‑by‑line", open=False) as editor_box:df_editor = gr.Dataframe(headers=["Speaker", "Line"],datatype=["str", "str"],wrap=True,interactive=True,row_count=(1, "dynamic"),col_count=(2, "fixed"),)save_btn = gr.Button("Save edits")save_msg = gr.Markdown()save_btn.click(fn=save_dialogue_edits,inputs=[df_editor, cached_dialogue],outputs=[cached_dialogue, transcript_output, save_msg],)rerender_btn = gr.Button("Re‑render with current voice settings (must have generated original LLM output)")rerender_btn.click(fn=render_audio_from_dialogue,inputs=[cached_dialogue,openai_api_key,audio_model,speaker_1_voice,speaker_2_voice,speaker_1_instructions,speaker_2_instructions,],outputs=[audio_output, transcript_output],)# Function to update the interactive state of edited_transcriptdef update_edit_box(checkbox_value):return gr.update(interactive=checkbox_value, lines=20 if checkbox_value else 20, visible=True if checkbox_value else False)14 unmodified linessubmit_btn.click(fn=validate_and_generate_audio,inputs=[files, openai_api_key, text_model, reasoning_effort, do_web_search, audio_model,speaker_1_voice, speaker_2_voice, speaker_1_instructions, speaker_2_instructions,api_base,intro_instructions, text_instructions, scratch_pad_instructions,prelude_dialog, podcast_dialog_instructions,edited_transcript,user_feedback,],outputs=[audio_output, transcript_output, original_text_output, error_output, cached_dialogue, ]).then(fn=lambda audio, transcript, original_text, error: (transcript if transcript else "",5 unmodified linesfn=lambda error: gr.Warning(error) if error else None,inputs=[error_output],outputs=[]).then( # fill spreadsheet editorfn=dialogue_to_df,inputs=[cached_dialogue],outputs=[df_editor],)regenerate_btn.click(fn=lambda use_edit, edit, *args: validate_and_generate_audio(3 unmodified lines),inputs=[use_edited_transcript, edited_transcript,files, openai_api_key, text_model, reasoning_effort, do_web_search, audio_model,speaker_1_voice, speaker_2_voice, speaker_1_instructions, speaker_2_instructions,api_base,intro_instructions, text_instructions, scratch_pad_instructions,prelude_dialog, podcast_dialog_instructions,user_feedback, original_text_output],outputs=[audio_output, transcript_output, original_text_output, error_output, cached_dialogue, ]).then(fn=lambda audio, transcript, original_text, error: (transcript if transcript else "",5 unmodified linesfn=lambda error: gr.Warning(error) if error else None,inputs=[error_output],outputs=[]).then( # fill spreadsheet editorfn=dialogue_to_df,inputs=[cached_dialogue],outputs=[df_editor],)with gr.Row():save_md_btn = gr.Button("Download Markdown of Dialogue")markdown_file_output = gr.File(label="Download .md file")save_md_btn.click(fn=save_dialogue_as_markdown,inputs=[cached_dialogue],outputs=[markdown_file_output],)# Add README content at the bottom
app.py+326-54