Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,12 +10,11 @@ import time # Import time module for adding delays
|
|
| 10 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
|
| 13 |
-
# Initialize the Gradio client
|
| 14 |
-
client = Client("MiniMaxAI/MiniMax-Text-01")
|
| 15 |
-
|
| 16 |
# Function to call the API and get the result
|
| 17 |
def call_api(prompt):
|
| 18 |
try:
|
|
|
|
|
|
|
| 19 |
logger.info(f"Calling API with prompt: {prompt[:100]}...") # Log the first 100 chars of the prompt
|
| 20 |
result = client.predict(
|
| 21 |
message=prompt,
|
|
@@ -30,7 +29,7 @@ def call_api(prompt):
|
|
| 30 |
logger.error(f"API call failed: {e}")
|
| 31 |
raise gr.Error(f"API call failed: {str(e)}")
|
| 32 |
|
| 33 |
-
# Function to segment the text file into chunks of
|
| 34 |
def segment_text(file_path):
|
| 35 |
try:
|
| 36 |
logger.info(f"Reading file: {file_path}")
|
|
@@ -48,9 +47,9 @@ def segment_text(file_path):
|
|
| 48 |
logger.error(f"Failed to read file: {e}")
|
| 49 |
raise gr.Error(f"Failed to read file: {str(e)}")
|
| 50 |
|
| 51 |
-
# Split the text into chunks of
|
| 52 |
words = text.split()
|
| 53 |
-
chunks = [" ".join(words[i:i +
|
| 54 |
logger.info(f"Segmented text into {len(chunks)} chunks.")
|
| 55 |
return chunks
|
| 56 |
|
|
|
|
| 10 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
# Function to call the API and get the result
|
| 14 |
def call_api(prompt):
|
| 15 |
try:
|
| 16 |
+
# Reload the Gradio client for each chunk
|
| 17 |
+
client = Client("MiniMaxAI/MiniMax-Text-01")
|
| 18 |
logger.info(f"Calling API with prompt: {prompt[:100]}...") # Log the first 100 chars of the prompt
|
| 19 |
result = client.predict(
|
| 20 |
message=prompt,
|
|
|
|
| 29 |
logger.error(f"API call failed: {e}")
|
| 30 |
raise gr.Error(f"API call failed: {str(e)}")
|
| 31 |
|
| 32 |
+
# Function to segment the text file into chunks of 1500 words
|
| 33 |
def segment_text(file_path):
|
| 34 |
try:
|
| 35 |
logger.info(f"Reading file: {file_path}")
|
|
|
|
| 47 |
logger.error(f"Failed to read file: {e}")
|
| 48 |
raise gr.Error(f"Failed to read file: {str(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), 1500)]
|
| 53 |
logger.info(f"Segmented text into {len(chunks)} chunks.")
|
| 54 |
return chunks
|
| 55 |
|