To detect the file type on upload and only allow certain file types to be uploaded, you can modify the code I provided earlier to include file type checking before uploading the file. Here's an updated code snippet that demonstrates how to do this using the python-magic library:

```python
import os
import magic
import requests
from google.oauth2.credentials import Credentials

# Set up the credentials for the Google Drive API
creds = Credentials.from_authorized_user_file(os.path.expanduser('path/to/credentials.json'))

# Set the file path of the file you want to upload
file_path = 'path/to/your/large_file'

# Define the allowed file types
allowed_types = ['image/png', 'image/jpeg', 'image/gif', 'application/pdf']

# Check the file type using magic
mime = magic.Magic(mime=True)
file_type = mime.from_file(file_path)

# If the file type is not allowed, raise an exception
if file_type not in allowed_types:
    raise Exception('File type not allowed')

# Set the upload URL and metadata for the file
url = 'https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable'
headers = {'Authorization': 'Bearer ' + creds.token, 'Content-Type': 'application/json'}
params = {'name': 'your_file_name'}

# Send the initial request to start the upload and get the session URL
response = requests.post(url, headers=headers, json=params)
session_url = response.headers['Location']

# Open the file in binary mode and stream it to the session URL in chunks
with open(file_path, 'rb') as f:
    chunk_size = 1024 * 1024 * 5 # 5MB chunks
    while True:
        chunk = f.read(chunk_size)
        if not chunk:
            break
        headers = {'Content-Length': str(len(chunk)), 'Content-Range': 'bytes {}-{}/{}'.format(start, start+len(chunk)-1, total_size)}
        response = requests.put(session_url, headers=headers, data=chunk)
        start += len(chunk)
        
print('Upload complete!')
```

In this updated code snippet, we first define a list of allowed file types. We then use the python-magic library to detect the file type of the file being uploaded, and raise an exception if the file type is not allowed. If the file type is allowed, we proceed with the upload as before.

Note that in order to use python-magic, you will need to have it installed on your system. You can install it using pip by running pip install python-magic.
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence