diff --git a/Cloud Storage/.idea/.gitignore b/Cloud Storage/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/Cloud Storage/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Cloud Storage/.idea/.name b/Cloud Storage/.idea/.name new file mode 100644 index 00000000..db3e26a6 --- /dev/null +++ b/Cloud Storage/.idea/.name @@ -0,0 +1 @@ +upload.py \ No newline at end of file diff --git a/Cloud Storage/.idea/S3.iml b/Cloud Storage/.idea/S3.iml new file mode 100644 index 00000000..d0876a78 --- /dev/null +++ b/Cloud Storage/.idea/S3.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Cloud Storage/.idea/inspectionProfiles/Project_Default.xml b/Cloud Storage/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..7dab4e81 --- /dev/null +++ b/Cloud Storage/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/Cloud Storage/.idea/inspectionProfiles/profiles_settings.xml b/Cloud Storage/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..105ce2da --- /dev/null +++ b/Cloud Storage/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/Cloud Storage/.idea/misc.xml b/Cloud Storage/.idea/misc.xml new file mode 100644 index 00000000..a377feb7 --- /dev/null +++ b/Cloud Storage/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/Cloud Storage/.idea/modules.xml b/Cloud Storage/.idea/modules.xml new file mode 100644 index 00000000..192882ce --- /dev/null +++ b/Cloud Storage/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Cloud Storage/Guide.txt b/Cloud Storage/Guide.txt new file mode 100644 index 00000000..ceda8a08 --- /dev/null +++ b/Cloud Storage/Guide.txt @@ -0,0 +1,25 @@ + + +1]Prerequisites before execution : + a) VSCODE, PyCharm or any IDE to run the python program + +2]Steps to execute the program : + a) UPLOAD (Only for 1 demo test) : + 1. Open Cloud Storage folder in your IDE + 2. On terminal run the upload.py file. + 3. You will get localhost (e.g. * Running on http://127.0.0.1:5000) + 4. Follow the link in your browser. + 5. Fill dummy details for the test. + 6. Click the submit button. + 7. You will get the notification of 'PDF file uploaded to S3 successfully' message. + 8. If you want to upload again, you have to change the name of file in the code manually so that previous file would not get overwritten. + + b) LIST : + 1. Open Cloud Storage folder in your IDE + 2. On terminal run the list.py file. + 3. You will get localhost (e.g. * Running on http://127.0.0.1:5000) + 4. Follow the link in your browser. + 5. You will see the file in PDF format that you just uploaded. (Generally this shows all the files that are uploaded on the cloud, for this demo you will see only one) + 6. By clicking on the name, the pdf file will get downloaded in your system. + 7. You can verify the content that you uploaded in cloud is correct or not. + n diff --git a/Cloud Storage/README.md b/Cloud Storage/README.md new file mode 100644 index 00000000..840b516b --- /dev/null +++ b/Cloud Storage/README.md @@ -0,0 +1,36 @@ +# Cloud Storage Demo + +This project demonstrates a simple cloud storage setup where users can upload and list PDF files stored on the cloud. + +## Prerequisites + +Before executing the program, make sure you have: + +- **An IDE**: VS Code, PyCharm, or any other IDE to run Python programs. + +## Steps to Execute the Program + +### 1. Upload (For 1 Demo Test) + +1. Open the `Cloud Storage` folder in your IDE. +2. In the terminal, run the `upload.py` file. +3. You should see an output indicating the localhost address (e.g., `* Running on http://127.0.0.1:5000`). +4. Follow the link in your browser. +5. Fill in dummy details for the test. +6. Click the **Submit** button. +7. You will receive a notification message: `'PDF file uploaded to S3 successfully'`. +8. **Note**: If you want to upload again, you must change the file name in the code manually to prevent overwriting the previous file. + +### 2. List + +1. Open the `Cloud Storage` folder in your IDE. +2. In the terminal, run the `list.py` file. +3. You should see an output indicating the localhost address (e.g., `* Running on http://127.0.0.1:5000`). +4. Follow the link in your browser. +5. You will see the uploaded PDF file (this displays all files uploaded to the cloud; for this demo, you’ll see only one). +6. Click on the file name to download the PDF file to your system. +7. Verify the content to ensure it matches what was uploaded to the cloud. + +## Notes + +- For this demo, only one file is shown; however, this setup generally supports multiple files on the cloud. diff --git a/Cloud Storage/__pycache__/secret.cpython-311.pyc b/Cloud Storage/__pycache__/secret.cpython-311.pyc new file mode 100644 index 00000000..2113a3d5 Binary files /dev/null and b/Cloud Storage/__pycache__/secret.cpython-311.pyc differ diff --git a/Cloud Storage/__pycache__/secret.cpython-312.pyc b/Cloud Storage/__pycache__/secret.cpython-312.pyc new file mode 100644 index 00000000..80f0f2e8 Binary files /dev/null and b/Cloud Storage/__pycache__/secret.cpython-312.pyc differ diff --git a/Cloud Storage/list.py b/Cloud Storage/list.py new file mode 100644 index 00000000..97a0dee2 --- /dev/null +++ b/Cloud Storage/list.py @@ -0,0 +1,43 @@ +from flask import Flask, render_template, send_file +import boto3 +from botocore.exceptions import NoCredentialsError +from secret import access_key, secret_access_key + +app = Flask(__name__) + + +s3 = boto3.client('s3', aws_access_key_id=access_key, aws_secret_access_key=secret_access_key) + + +S3_BUCKET = 'medical-reports-ssip' + +@app.route('/') +def list_reports(): + try: + + response = s3.list_objects(Bucket=S3_BUCKET) + + if 'Contents' in response: + reports = [obj['Key'] for obj in response['Contents']] + else: + reports = [] + + return render_template('list.html', reports=reports) + except NoCredentialsError: + return "AWS credentials not available." + except Exception as e: + print("Error listing S3 objects:", str(e)) + return "An error occurred while listing S3 objects." + +@app.route('/download_report/') +def download_report(filename): + try: + + s3.download_file(S3_BUCKET, filename, 'downloaded_report.pdf') + + return send_file('downloaded_report.pdf', as_attachment=True) + except NoCredentialsError: + return "AWS credentials not available." + +if __name__ == '__main__': + app.run(debug=True) diff --git a/Cloud Storage/secret.py b/Cloud Storage/secret.py new file mode 100644 index 00000000..ed2b12bc --- /dev/null +++ b/Cloud Storage/secret.py @@ -0,0 +1,2 @@ +access_key="" +secret_access_key="" diff --git a/Cloud Storage/templates/form.html b/Cloud Storage/templates/form.html new file mode 100644 index 00000000..86a3fa53 --- /dev/null +++ b/Cloud Storage/templates/form.html @@ -0,0 +1,213 @@ + + + + + + + + + +
+

Medical Report Form

+
+
+ + +
+
+ + + +
+
+ + +
+ +
+ + +
+ + +
+ + +
+ +
+ + +
+ + +
+ + + + +
+ + + +
+ + +
+ + + + + + +
+
+ + + + + + diff --git a/Cloud Storage/templates/list.html b/Cloud Storage/templates/list.html new file mode 100644 index 00000000..0d14aa4a --- /dev/null +++ b/Cloud Storage/templates/list.html @@ -0,0 +1,44 @@ + + + + + + +
+

List of Medical Reports

+
    + {% for report in reports %} +
  • + {{ report }} +
  • + {% endfor %} +
+
+ + diff --git a/Cloud Storage/upload.py b/Cloud Storage/upload.py new file mode 100644 index 00000000..576a493e --- /dev/null +++ b/Cloud Storage/upload.py @@ -0,0 +1,67 @@ +from flask import Flask, request, jsonify, render_template +import boto3 +import io +from fpdf import FPDF +from secret import access_key, secret_access_key + +app = Flask(__name__) + + +s3 = boto3.client('s3', aws_access_key_id=access_key, aws_secret_access_key=secret_access_key) + + +S3_BUCKET = 'medical-reports-ssip' + +class PDF(FPDF): + def header(self): + self.set_font('Arial', 'B', 12) + self.cell(0, 10, 'Medical Report', 0, 1, 'C') + + def chapter_title(self, title): + self.set_font('Arial', 'B', 12) + self.cell(0, 10, title, 0, 1, 'L') + self.ln(10) + + def medical_data(self, data): + self.set_font('Arial', '', 12) + for key, value in data.items(): + if key == "medicines": + self.chapter_title("Medicines") + for medicine in value: + self.cell(0, 10, f"Prescription: {medicine['medicine-prescription']}", 0, 1) + self.cell(0, 10, f"Medication Timing: {medicine['medication-timing']}", 0, 1) + else: + self.cell(0, 10, f"{key.capitalize()}: {value}", 0, 1) + +@app.route('/') +def form(): + return render_template('form.html') + +@app.route('/submit', methods=['POST']) +def submit(): + try: + data = request.get_json() + + if data: + pdf = PDF() + pdf.add_page() + pdf.set_auto_page_break(auto=True, margin=15) + pdf.medical_data(data) + + + pdf_file = 'medical_report.pdf' + pdf.output(pdf_file) + + + try: + s3.upload_file(pdf_file, S3_BUCKET, 'demo.pdf', ExtraArgs={'ContentType': 'application/pdf'}) + return jsonify({"message": "PDF file uploaded to S3 successfully."}) + except Exception as e: + return jsonify({"error": f"Failed to upload the PDF to S3: {str(e)}"}) + else: + return jsonify({"error": "No JSON data received."}) + except Exception as e: + return jsonify({"error": f"An error occurred: {str(e)}"}) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/moderation_aws/app.log b/moderation_aws/app.log new file mode 100644 index 00000000..2c8fbd3f --- /dev/null +++ b/moderation_aws/app.log @@ -0,0 +1,91 @@ +2024-02-09 22:59:39,855 - WARNING - * Debugger is active! +2024-02-09 22:59:39,855 - INFO - * Debugger PIN: 125-297-349 +2024-02-09 23:01:02,044 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on http://127.0.0.1:5000 +2024-02-09 23:01:02,045 - INFO - Press CTRL+C to quit +2024-02-09 23:01:02,048 - INFO - * Restarting with stat +2024-02-09 23:01:02,955 - WARNING - * Debugger is active! +2024-02-09 23:01:02,955 - INFO - * Debugger PIN: 125-297-349 +2024-02-09 23:01:14,286 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on http://127.0.0.1:5000 +2024-02-09 23:01:14,289 - INFO - Press CTRL+C to quit +2024-02-09 23:01:14,291 - INFO - * Restarting with stat +2024-02-09 23:01:15,198 - WARNING - * Debugger is active! +2024-02-09 23:01:15,203 - INFO - * Debugger PIN: 125-297-349 +2024-02-09 23:02:22,932 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on http://127.0.0.1:5000 +2024-02-09 23:02:22,932 - INFO - Press CTRL+C to quit +2024-02-09 23:02:22,935 - INFO - * Restarting with stat +2024-02-09 23:02:23,882 - WARNING - * Debugger is active! +2024-02-09 23:02:23,887 - INFO - * Debugger PIN: 125-297-349 +2024-02-09 23:09:00,661 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on http://127.0.0.1:5000 +2024-02-09 23:09:00,661 - INFO - Press CTRL+C to quit +2024-02-09 23:09:00,665 - INFO - * Restarting with stat +2024-02-09 23:09:01,538 - WARNING - * Debugger is active! +2024-02-09 23:09:01,544 - INFO - * Debugger PIN: 126-934-418 +2024-02-09 23:09:52,049 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on http://127.0.0.1:5000 +2024-02-09 23:09:52,049 - INFO - Press CTRL+C to quit +2024-02-09 23:09:52,057 - INFO - * Restarting with stat +2024-02-09 23:09:54,505 - WARNING - * Debugger is active! +2024-02-09 23:09:54,509 - INFO - * Debugger PIN: 126-934-418 +2024-02-09 23:11:06,674 - INFO - 127.0.0.1 - - [09/Feb/2024 23:11:06] "GET / HTTP/1.1" 200 - +2024-02-09 23:11:06,881 - INFO - 127.0.0.1 - - [09/Feb/2024 23:11:06] "GET /favicon.ico HTTP/1.1" 404 - +2024-02-09 23:11:17,528 - INFO - 127.0.0.1 - - [09/Feb/2024 23:11:17] "POST /upload HTTP/1.1" 200 - +2024-02-09 23:12:59,190 - INFO - * Detected change in 'C:\\Users\\athar\\OneDrive\\Desktop\\awsPy\\HackFusion\\app.py', reloading +2024-02-09 23:12:59,512 - INFO - * Restarting with stat +2024-02-09 23:13:37,146 - INFO - * Restarting with stat +2024-02-09 23:13:38,149 - WARNING - * Debugger is active! +2024-02-09 23:13:38,150 - INFO - * Debugger PIN: 126-934-418 +2024-02-09 23:13:42,897 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on http://127.0.0.1:5000 +2024-02-09 23:13:42,897 - INFO - Press CTRL+C to quit +2024-02-09 23:13:42,899 - INFO - * Restarting with stat +2024-02-09 23:13:43,750 - WARNING - * Debugger is active! +2024-02-09 23:13:43,753 - INFO - * Debugger PIN: 126-934-418 +2024-02-09 23:16:38,803 - INFO - * Detected change in 'C:\\Users\\athar\\OneDrive\\Desktop\\awsPy\\HackFusion\\app.py', reloading +2024-02-09 23:16:38,970 - INFO - * Restarting with stat +2024-02-09 23:17:00,107 - INFO - * Restarting with stat +2024-02-09 23:17:01,074 - WARNING - * Debugger is active! +2024-02-09 23:17:01,076 - INFO - * Debugger PIN: 126-934-418 +2024-02-09 23:17:02,041 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on http://127.0.0.1:5000 +2024-02-09 23:17:02,041 - INFO - Press CTRL+C to quit +2024-02-09 23:17:02,043 - INFO - * Restarting with stat +2024-02-09 23:17:02,911 - WARNING - * Debugger is active! +2024-02-09 23:17:02,915 - INFO - * Debugger PIN: 126-934-418 +2024-02-09 23:17:16,447 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on http://127.0.0.1:5000 +2024-02-09 23:17:16,447 - INFO - Press CTRL+C to quit +2024-02-09 23:17:16,447 - INFO - * Restarting with stat +2024-02-09 23:17:17,320 - WARNING - * Debugger is active! +2024-02-09 23:17:17,326 - INFO - * Debugger PIN: 126-934-418 +2024-02-09 23:17:33,132 - INFO - 127.0.0.1 - - [09/Feb/2024 23:17:33] "GET / HTTP/1.1" 200 - +2024-02-09 23:17:44,005 - INFO - 127.0.0.1 - - [09/Feb/2024 23:17:44] "POST /upload HTTP/1.1" 200 - +2024-02-09 23:29:32,252 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on http://127.0.0.1:5000 +2024-02-09 23:29:32,252 - INFO - Press CTRL+C to quit +2024-02-09 23:29:32,255 - INFO - * Restarting with stat +2024-02-09 23:29:33,130 - WARNING - * Debugger is active! +2024-02-09 23:29:33,133 - INFO - * Debugger PIN: 126-934-418 +2024-02-09 23:29:42,311 - INFO - 127.0.0.1 - - [09/Feb/2024 23:29:42] "GET / HTTP/1.1" 200 - +2024-02-09 23:29:49,567 - INFO - 127.0.0.1 - - [09/Feb/2024 23:29:49] "POST /upload HTTP/1.1" 200 - +2024-02-09 23:33:37,487 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on http://127.0.0.1:5000 +2024-02-09 23:33:37,487 - INFO - Press CTRL+C to quit +2024-02-09 23:33:37,487 - INFO - * Restarting with stat +2024-02-09 23:33:38,452 - WARNING - * Debugger is active! +2024-02-09 23:33:38,452 - INFO - * Debugger PIN: 126-934-418 +2024-02-09 23:33:40,579 - INFO - 127.0.0.1 - - [09/Feb/2024 23:33:40] "GET / HTTP/1.1" 200 - +2024-02-09 23:33:47,285 - INFO - 127.0.0.1 - - [09/Feb/2024 23:33:47] "POST /upload HTTP/1.1" 200 - +2024-02-09 23:40:15,573 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on http://127.0.0.1:5000 +2024-02-09 23:40:15,573 - INFO - Press CTRL+C to quit +2024-02-09 23:40:15,576 - INFO - * Restarting with stat +2024-02-09 23:40:16,418 - WARNING - * Debugger is active! +2024-02-09 23:40:16,421 - INFO - * Debugger PIN: 126-934-418 +2024-02-09 23:40:22,654 - INFO - 127.0.0.1 - - [09/Feb/2024 23:40:22] "GET / HTTP/1.1" 200 - +2024-02-09 23:40:28,870 - INFO - 127.0.0.1 - - [09/Feb/2024 23:40:28] "POST /upload HTTP/1.1" 200 - +2024-02-10 00:44:16,987 - INFO - * Detected change in 'C:\\Users\\athar\\OneDrive\\Desktop\\awsPy\\HackFusion\\app.py', reloading +2024-02-10 00:44:17,118 - INFO - * Restarting with stat diff --git a/moderation_aws/audio_from_video.py b/moderation_aws/audio_from_video.py new file mode 100644 index 00000000..4f2fea75 --- /dev/null +++ b/moderation_aws/audio_from_video.py @@ -0,0 +1,125 @@ +import boto3 +import os +import io +import datetime +from IPython.display import HTML, display +import uuid +import json +import time + +# Set variables +region = '' +role = "" +bucket_name = '' # Provide your bucket name here +s3_key = '' + + +os.environ["REGION"] = region + +print(f"Region is: {region}\nRole is: {role}") + +rekognition = boto3.client('rekognition', region_name=region) +comprehend = boto3.client('comprehend', region_name=region) +transcribe = boto3.client('transcribe', region_name=region) +s3 = boto3.client('s3', region_name=region) + +video_path = r'' + +# Start moderation label detection +startModerationLabelDetection = rekognition.start_content_moderation( + Video={ + 'S3Object': { + 'Bucket': bucket_name, + 'Name': s3_key + } + } +) + +moderationJobId = startModerationLabelDetection['JobId'] +display("Job Id: {0}".format(moderationJobId)) + +# Get content moderation results +getContentModeration = rekognition.get_content_moderation( + JobId=moderationJobId, + SortBy='TIMESTAMP' +) + +while getContentModeration['JobStatus'] == 'IN_PROGRESS': + time.sleep(5) + print('.', end='') + getContentModeration = rekognition.get_content_moderation( + JobId=moderationJobId, + SortBy='TIMESTAMP' + ) + +display(getContentModeration['JobStatus']) + +label_html = '''''' +for label in getContentModeration["ModerationLabels"]: + if len(label["ModerationLabel"]["ParentName"]) > 0: + label_html += f'''[{label['Timestamp']} ms]: + {label['ModerationLabel']['Name']}, confidence: {round(label['ModerationLabel']['Confidence'],2)}%
+ ''' +display(HTML(label_html)) + +# Start text detection +getTextDetection = rekognition.start_text_detection( + Video={ + 'S3Object': { + 'Bucket': bucket_name, + 'Name': s3_key + } + } +) + +textJobId = getTextDetection['JobId'] +display("Job Id: {0}".format(textJobId)) + +# Get text detection results +getTextDetection = rekognition.get_text_detection(JobId=textJobId) + +while getTextDetection['JobStatus'] == 'IN_PROGRESS': + time.sleep(5) + print('.', end='') + + getTextDetection = rekognition.get_text_detection(JobId=textJobId) + +display(getTextDetection['JobStatus']) + +text_html = '''''' +for txt in getTextDetection["TextDetections"]: + if txt["TextDetection"]["Type"] == 'LINE': + text_html += f'''[{txt['Timestamp']} ms]: + {txt["TextDetection"]["DetectedText"]}, confidence: {round(txt["TextDetection"]["Confidence"],2)}%
+ ''' +display(HTML(text_html)) + +# Start transcription job +job_name = f'video_moderation_{str(uuid.uuid1())[0:4]}' + +transcribe.start_transcription_job( + TranscriptionJobName=job_name, + Media={'MediaFileUri': f's3://{bucket_name}/{s3_key}'}, # S3 URI to the video + OutputBucketName='suii', # Specify your output bucket name here + OutputKey='transcriptions/output.json', # Optional: Specify your output key (path) here + MediaFormat='mp4', + LanguageCode='en-US' +) + + +getTranscription = transcribe.get_transcription_job(TranscriptionJobName=job_name) + +while getTranscription['TranscriptionJob']['TranscriptionJobStatus'] == 'IN_PROGRESS': + time.sleep(5) + print('.', end='') + + getTranscription = transcribe.get_transcription_job(TranscriptionJobName=job_name) + +display(getTranscription['TranscriptionJob']['TranscriptionJobStatus']) + +filename = f'transcriptions/output.json' +s3_clientobj = boto3.client('s3', region_name=region).get_object(Bucket=bucket_name, Key=filename) +s3_clientdata = s3_clientobj["Body"].read().decode("utf-8") +original = json.loads(s3_clientdata) +output_transcript = original["results"]["transcripts"] +print(output_transcript) diff --git a/moderation_aws/image.py b/moderation_aws/image.py new file mode 100644 index 00000000..470d578e --- /dev/null +++ b/moderation_aws/image.py @@ -0,0 +1,57 @@ + +import boto3 +import sagemaker +from PIL import Image +import io + + + +# variables +role = "" + +region = '' # Set the region to ap-south-1 + +rekognition = boto3.client('rekognition', region_name=region) +comprehend = boto3.client('comprehend', region_name=region) + +print(f"SageMaker role is: {role}") + +# Load the image from local directory +local_image_path = r'' + +with open(local_image_path, 'rb') as f: + image_bytes = f.read() + +# Detect moderation labels +detectModerationLabelsResponse = rekognition.detect_moderation_labels( + Image={ + 'Bytes': image_bytes + } +) + +for label in detectModerationLabelsResponse["ModerationLabels"]: + print("- {} (Confidence: {})".format(label["Name"], label["Confidence"])) + print(" - Parent: {}".format(label["ParentName"])) + +# Detect text +detectTextResponse = rekognition.detect_text( + Image={ + 'Bytes': image_bytes + } +) + +detected_text_list = [] +textDetections = detectTextResponse['TextDetections'] +for text in textDetections: + if text['Type'] == 'LINE': + print('Detected text: ' + text['DetectedText']) + detected_text_list.append(text['DetectedText']) + +for text in detected_text_list: + response = comprehend.detect_pii_entities(Text=text, LanguageCode='en') + if len(response['Entities']) > 0: + print("Detected PII entity is: " + text[ + response['Entities'][0]['BeginOffset']:response['Entities'][0]['EndOffset']]) + print("PII type is: " + response['Entities'][0]['Type']) + print("Confidence score is: " + str(response['Entities'][0]['Score'])) +print() diff --git a/moderation_aws/moderation-audio-speech.mp3 b/moderation_aws/moderation-audio-speech.mp3 new file mode 100644 index 00000000..47d5ed2b Binary files /dev/null and b/moderation_aws/moderation-audio-speech.mp3 differ diff --git a/moderation_aws/moderation-video.mp4 b/moderation_aws/moderation-video.mp4 new file mode 100644 index 00000000..e7d0fa9d Binary files /dev/null and b/moderation_aws/moderation-video.mp4 differ diff --git a/moderation_aws/templates/home.html b/moderation_aws/templates/home.html new file mode 100644 index 00000000..d9fcab7e --- /dev/null +++ b/moderation_aws/templates/home.html @@ -0,0 +1,90 @@ + + + + + + Upload Files + + + +

Upload Files

+ +
+ + +
+ +
+ + + + + + + diff --git a/moderation_aws/video.py b/moderation_aws/video.py new file mode 100644 index 00000000..8986af9c --- /dev/null +++ b/moderation_aws/video.py @@ -0,0 +1,97 @@ +import boto3 +import time + +# Initialize AWS services +region = '' +rekognition = boto3.client('rekognition', region_name=region) +s3 = boto3.client('s3', region_name=region) + +# Define the bucket name and video file name +bucket_name = '' +video_name = '' + +# Start content moderation job +start_moderation_label_detection = rekognition.start_content_moderation( + Video={ + 'S3Object': { + 'Bucket': bucket_name, + 'Name': video_name, + } + }, +) + +moderation_job_id = start_moderation_label_detection['JobId'] +print("Job Id:", moderation_job_id) + +# Wait for content moderation job to complete +while True: + moderation_job_status = rekognition.get_content_moderation(JobId=moderation_job_id) + if moderation_job_status['JobStatus'] == 'SUCCEEDED': + break + elif moderation_job_status['JobStatus'] == 'FAILED': + print("Content moderation job failed.") + break + else: + time.sleep(5) # Wait for 5 seconds before checking job status again + +# Get the moderation labels detected in the video +moderation_labels = moderation_job_status.get('ModerationLabels', []) + +# Initialize detection flags +explicit_detected = False +suggestive_detected = False +violent_detected = False +alcohol_detected = False +drug_abuse_detected = False +offensive_detected = False +tobacco_detected = False +hate_symbols_detected = False +gambling_detected = False +graphic_content_detected = False +adult_content_detected = False + +# Categorize moderation labels +for label in moderation_labels: + label_name = label['ModerationLabel']['Name'] + if label_name.lower() == 'explicit nudity': + explicit_detected = True + elif label_name.lower() == 'suggestive': + suggestive_detected = True + elif label_name.lower() == 'violence': + violent_detected = True + elif label_name.lower() == 'alcohol': + alcohol_detected = True + elif label_name.lower() == 'drug abuse': + drug_abuse_detected = True + elif label_name.lower() == 'offensive': + offensive_detected = True + elif label_name.lower() == 'tobacco': + tobacco_detected = True + elif label_name.lower() == 'hate symbols': + hate_symbols_detected = True + elif label_name.lower() == 'gambling': + gambling_detected = True + elif label_name.lower() == 'graphic content': + graphic_content_detected = True + elif label_name.lower() == 'adult content': + adult_content_detected = True + +# Display detection results +print("Moderation labels detected:") +print(f"Explicit Nudity: {'Detected' if explicit_detected else 'Not Detected'}") +print(f"Suggestive: {'Detected' if suggestive_detected else 'Not Detected'}") +print(f"Violence: {'Detected' if violent_detected else 'Not Detected'}") +print(f"Alcohol: {'Detected' if alcohol_detected else 'Not Detected'}") +print(f"Drug Abuse: {'Detected' if drug_abuse_detected else 'Not Detected'}") +print(f"Offensive: {'Detected' if offensive_detected else 'Not Detected'}") +print(f"Tobacco: {'Detected' if tobacco_detected else 'Not Detected'}") +print(f"Hate Symbols: {'Detected' if hate_symbols_detected else 'Not Detected'}") +print(f"Gambling: {'Detected' if gambling_detected else 'Not Detected'}") +print(f"Graphic Content: {'Detected' if graphic_content_detected else 'Not Detected'}") +print(f"Adult Content: {'Detected' if adult_content_detected else 'Not Detected'}") + +# Generate a presigned URL for the video +s3_video_url = s3.generate_presigned_url('get_object', Params={'Bucket': bucket_name, 'Key': video_name}) + +# Print the video URL +print("Video URL:", s3_video_url) diff --git a/moderation_aws/yoga_swimwear_lighttext.jpg b/moderation_aws/yoga_swimwear_lighttext.jpg new file mode 100644 index 00000000..29aa600e Binary files /dev/null and b/moderation_aws/yoga_swimwear_lighttext.jpg differ