Spaces:
Paused
Paused
Update app.py
Browse files20 unmodified lines21222324252425262728293031323334353613 unmodified lines505152455354555626 unmodified lines8384857879868720 unmodified lines
# Function to segment the text file into chunks of 3000 wordsdef segment_text(file_path): try: # Try reading with UTF-8 encoding first with open(file_path, "r") as f: text = f.read() with open(file_path, "r", encoding="utf-8") as f: text = f.read() except UnicodeDecodeError: # Fallback to latin-1 encoding if UTF-8 fails with open(file_path, "r", encoding="latin-1") as f: text = f.read() # Split the text into chunks of 3000 words words = text.split() chunks = [" ".join(words[i:i + 3000]) for i in range(0, len(words), 3000)] return chunks13 unmodified lines # Save results as individual text files os.makedirs("outputs", exist_ok=True) for idx, result in enumerate(results): with open(f"outputs/output_{idx}.txt", "w") as f: with open(f"outputs/output_{idx}.txt", "w", encoding="utf-8") as f: f.write(result) # Upload to Hugging Face dataset26 unmodified lines outputs=[output_zip, output_message] )
# Launch the Gradio appdemo.launch()# Launch the Gradio app with a public linkdemo.launch(share=True)app.py+13-5