Update app.py
Browse files53 unmodified lines54555657585970 unmodified lines13013113213313413513613713825 unmodified lines16416516616716816917053 unmodified linesraise ValueError(f"task_type must be one of: {valid_types}")return vclass S3ModelLoader:def __init__(self, bucket_name, s3_client):self.bucket_name = bucket_name70 unmodified linesraise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")async def stream_text(model, tokenizer, input_text, generation_config, stop_sequences, device, chunk_delay):# Get the maximum model input lengthmax_model_length = model.config.max_position_embeddingsencoded_input = tokenizer(input_text, return_tensors="pt", max_length=max_model_length, truncation=True).to(device)def stop_criteria(input_ids, scores):25 unmodified lines)except IndexError as e:print(f"IndexError during generation: {e}")break # Exit the loop if there's an index errornew_token_ids = outputs.sequences[0][encoded_input.input_ids.shape[-1]:]53 unmodified lines54555657585960616263646570 unmodified lines13613713813914014114225 unmodified lines16816917017117217317453 unmodified linesraise ValueError(f"task_type must be one of: {valid_types}")return v@field_validator("max_new_tokens")def max_new_tokens_must_be_within_limit(cls, v):if v > 4:raise ValueError("max_new_tokens cannot be greater than 4.")return vclass S3ModelLoader:def __init__(self, bucket_name, s3_client):self.bucket_name = bucket_name70 unmodified linesraise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")async def stream_text(model, tokenizer, input_text, generation_config, stop_sequences, device, chunk_delay):max_model_length = model.config.max_position_embeddingsencoded_input = tokenizer(input_text, return_tensors="pt", max_length=max_model_length, truncation=True).to(device)def stop_criteria(input_ids, scores):25 unmodified lines)except IndexError as e:print(f"IndexError during generation: {e}")breaknew_token_ids = outputs.sequences[0][encoded_input.input_ids.shape[-1]:]
app.py+7-3