Spaces:
Sleeping
Sleeping
Update app.py
Browse files11 unmodified lines121314151617186 unmodified lines252627282930314 unmodified lines36373839404142434445464748495051525315 unmodified lines6970717273741 unmodified line7677787980818211 unmodified lineslogs = []if not file_path:return "Please select a file for transcription.", None, Falselogs.append("Processing file...")6 unmodified lineslogs.append(f"File converted to: {file_path}")except Exception as e:logs.append(f"Conversion error: {str(e)}")return "\n".join(logs), None, Falseprocessed_files = validate_and_process_file(file_path)transcriptions = []4 unmodified linestranscriptions.append(transcription)logs.append(f"Part {i + 1} transcription completed.")# Save transcription to temporary filewith tempfile.NamedTemporaryFile(delete=False, mode="w", suffix=".txt", encoding="utf-8") as f:f.write("\n\n".join(transcriptions))temp_file_path = f.namelogs.append("Transcription completed. Ready for download.")return "\n".join(logs), temp_file_path, Trueexcept Exception as e:error_msg = str(e)logs.append(f"An error occurred: {error_msg}")return "\n".join(logs), None, False# User interfacewith gr.Blocks() as demo:15 unmodified lineswith gr.Row():download_link = gr.File(label="Download Transcription", visible=False)# Add visibility management componentdownload_visibility = gr.Checkbox(value=False, visible=False)1 unmodified linesubmit_button.click(process_input,inputs=[api_key, file_input],outputs=[logs, download_link, download_visibility])# Set download_link visibility based on download_visibility value11 unmodified lines121314151617186 unmodified lines252627282930314 unmodified lines36373839404142434445464748495051525354555615 unmodified lines72737475767778798081828384851 unmodified line8788899091929311 unmodified lineslogs = []if not file_path:return "Please select a file for transcription.", None, False, ""logs.append("Processing file...")6 unmodified lineslogs.append(f"File converted to: {file_path}")except Exception as e:logs.append(f"Conversion error: {str(e)}")return "\n".join(logs), None, False, ""processed_files = validate_and_process_file(file_path)transcriptions = []4 unmodified linestranscriptions.append(transcription)logs.append(f"Part {i + 1} transcription completed.")# Połącz wszystkie transkrypcjefull_transcription = "\n\n".join(transcriptions)# Save transcription to temporary filewith tempfile.NamedTemporaryFile(delete=False, mode="w", suffix=".txt", encoding="utf-8") as f:f.write(full_transcription)temp_file_path = f.namelogs.append("Transcription completed. Ready for download.")return "\n".join(logs), temp_file_path, True, full_transcriptionexcept Exception as e:error_msg = str(e)logs.append(f"An error occurred: {error_msg}")return "\n".join(logs), None, False, ""# User interfacewith gr.Blocks() as demo:15 unmodified lineswith gr.Row():download_link = gr.File(label="Download Transcription", visible=False)with gr.Row():transcription_preview = gr.Textbox(label="Transcription Preview",interactive=False,lines=15,placeholder="Transcription will appear here...")# Add visibility management componentdownload_visibility = gr.Checkbox(value=False, visible=False)1 unmodified linesubmit_button.click(process_input,inputs=[api_key, file_input],outputs=[logs, download_link, download_visibility, transcription_preview])# Set download_link visibility based on download_visibility value
app.py+17-6