Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,7 +49,7 @@ def segment_text(file_path):
|
|
| 49 |
|
| 50 |
# Split the text into chunks of 1500 words
|
| 51 |
words = text.split()
|
| 52 |
-
chunks = [" ".join(words[i:i + 1500]) for i in range(0, len(words),
|
| 53 |
logger.info(f"Segmented text into {len(chunks)} chunks.")
|
| 54 |
return chunks
|
| 55 |
|
|
@@ -70,7 +70,7 @@ def process_text(file, prompt):
|
|
| 70 |
# Repository name on Hugging Face Hub
|
| 71 |
repo_name = "TeacherPuffy/book2"
|
| 72 |
|
| 73 |
-
# Process each chunk with a
|
| 74 |
results = []
|
| 75 |
for idx, chunk in enumerate(chunks):
|
| 76 |
logger.info(f"Processing chunk {idx + 1}/{len(chunks)}")
|
|
@@ -101,10 +101,10 @@ def process_text(file, prompt):
|
|
| 101 |
logger.error(f"Failed to upload chunk {idx + 1} to Hugging Face: {e}")
|
| 102 |
raise gr.Error(f"Failed to upload chunk {idx + 1} to Hugging Face: {str(e)}")
|
| 103 |
|
| 104 |
-
# Wait
|
| 105 |
if idx < len(chunks) - 1: # No need to wait after the last chunk
|
| 106 |
-
logger.info("Waiting
|
| 107 |
-
time.sleep(
|
| 108 |
|
| 109 |
except Exception as e:
|
| 110 |
logger.error(f"Failed to process chunk {idx + 1}: {e}")
|
|
|
|
| 49 |
|
| 50 |
# Split the text into chunks of 1500 words
|
| 51 |
words = text.split()
|
| 52 |
+
chunks = [" ".join(words[i:i + 1500]) for i in range(0, len(words), 1250)]
|
| 53 |
logger.info(f"Segmented text into {len(chunks)} chunks.")
|
| 54 |
return chunks
|
| 55 |
|
|
|
|
| 70 |
# Repository name on Hugging Face Hub
|
| 71 |
repo_name = "TeacherPuffy/book2"
|
| 72 |
|
| 73 |
+
# Process each chunk with a 15-second delay between API calls
|
| 74 |
results = []
|
| 75 |
for idx, chunk in enumerate(chunks):
|
| 76 |
logger.info(f"Processing chunk {idx + 1}/{len(chunks)}")
|
|
|
|
| 101 |
logger.error(f"Failed to upload chunk {idx + 1} to Hugging Face: {e}")
|
| 102 |
raise gr.Error(f"Failed to upload chunk {idx + 1} to Hugging Face: {str(e)}")
|
| 103 |
|
| 104 |
+
# Wait 15 seconds before the next API call
|
| 105 |
if idx < len(chunks) - 1: # No need to wait after the last chunk
|
| 106 |
+
logger.info("Waiting 15 seconds before the next API call...")
|
| 107 |
+
time.sleep(15)
|
| 108 |
|
| 109 |
except Exception as e:
|
| 110 |
logger.error(f"Failed to process chunk {idx + 1}: {e}")
|