Spaces:
Paused
Paused
Update app.py
Browse files48 unmodified lines4950515253545514 unmodified lines7071727374757624 unmodified lines10110210310410510610710810911048 unmodified lines# Split the text into chunks of 1500 wordswords = text.split()chunks = [" ".join(words[i:i + 1500]) for i in range(0, len(words), 1500)]logger.info(f"Segmented text into {len(chunks)} chunks.")return chunks14 unmodified lines# Repository name on Hugging Face Hubrepo_name = "TeacherPuffy/book2"# Process each chunk with a 20-second delay between API callsresults = []for idx, chunk in enumerate(chunks):logger.info(f"Processing chunk {idx + 1}/{len(chunks)}")24 unmodified lineslogger.error(f"Failed to upload chunk {idx + 1} to Hugging Face: {e}")raise gr.Error(f"Failed to upload chunk {idx + 1} to Hugging Face: {str(e)}")# Wait 20 seconds before the next API callif idx < len(chunks) - 1: # No need to wait after the last chunklogger.info("Waiting 20 seconds before the next API call...")time.sleep(20)except Exception as e:logger.error(f"Failed to process chunk {idx + 1}: {e}")48 unmodified lines4950515253545514 unmodified lines7071727374757624 unmodified lines10110210310410510610710810911048 unmodified lines# Split the text into chunks of 1500 wordswords = text.split()chunks = [" ".join(words[i:i + 1500]) for i in range(0, len(words), 1250)]logger.info(f"Segmented text into {len(chunks)} chunks.")return chunks14 unmodified lines# Repository name on Hugging Face Hubrepo_name = "TeacherPuffy/book2"# Process each chunk with a 15-second delay between API callsresults = []for idx, chunk in enumerate(chunks):logger.info(f"Processing chunk {idx + 1}/{len(chunks)}")24 unmodified lineslogger.error(f"Failed to upload chunk {idx + 1} to Hugging Face: {e}")raise gr.Error(f"Failed to upload chunk {idx + 1} to Hugging Face: {str(e)}")# Wait 15 seconds before the next API callif idx < len(chunks) - 1: # No need to wait after the last chunklogger.info("Waiting 15 seconds before the next API call...")time.sleep(15)except Exception as e:logger.error(f"Failed to process chunk {idx + 1}: {e}")
app.py+5-5