Spaces:
Paused
Paused
Update app.py
Browse files9 unmodified lines1011121314151617181920218 unmodified lines3031323334353611 unmodified lines4849505152535455569 unmodified lineslogging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")logger = logging.getLogger(__name__)# Initialize the Gradio clientclient = Client("MiniMaxAI/MiniMax-Text-01")# Function to call the API and get the resultdef call_api(prompt):try:logger.info(f"Calling API with prompt: {prompt[:100]}...") # Log the first 100 chars of the promptresult = client.predict(message=prompt,8 unmodified lineslogger.error(f"API call failed: {e}")raise gr.Error(f"API call failed: {str(e)}")# Function to segment the text file into chunks of 3000 wordsdef segment_text(file_path):try:logger.info(f"Reading file: {file_path}")11 unmodified lineslogger.error(f"Failed to read file: {e}")raise gr.Error(f"Failed to read file: {str(e)}")# Split the text into chunks of 3000 wordswords = text.split()chunks = [" ".join(words[i:i + 3000]) for i in range(0, len(words), 3000)]logger.info(f"Segmented text into {len(chunks)} chunks.")return chunks9 unmodified lines10111213141516171819208 unmodified lines2930313233343511 unmodified lines4748495051525354559 unmodified lineslogging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")logger = logging.getLogger(__name__)# Function to call the API and get the resultdef call_api(prompt):try:# Reload the Gradio client for each chunkclient = Client("MiniMaxAI/MiniMax-Text-01")logger.info(f"Calling API with prompt: {prompt[:100]}...") # Log the first 100 chars of the promptresult = client.predict(message=prompt,8 unmodified lineslogger.error(f"API call failed: {e}")raise gr.Error(f"API call failed: {str(e)}")# Function to segment the text file into chunks of 1500 wordsdef segment_text(file_path):try:logger.info(f"Reading file: {file_path}")11 unmodified lineslogger.error(f"Failed to read file: {e}")raise gr.Error(f"Failed to read file: {str(e)}")# 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 chunks
app.py+5-6