Skip to content

Commit 7cfa76c

Browse files
add new files
1 parent a6a04ef commit 7cfa76c

13 files changed

+177
-3
lines changed

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: uvicorn app:app --host 0.0.0.0 --port 8000

README.md

+62-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ This step includes all common steps before doing deployment on all deployments (
4040
2. Create public VPC
4141
3. Create security group for allow ssh and http/https
4242
4. Create EC2 key pair
43+
5. Iam role
4344

4445
### 1. Create route53 web address
4546

@@ -85,11 +86,15 @@ Private Backend Instances:
8586

8687

8788
1. Allow full SSH access for developers
88-
![AWS Deployment Diagram](src_img\Screenshot (54).png)
89+
90+
- use your default or previous created vpc
91+
![AWS Deployment Diagram](src_img\Screenshot (57).png)
8992

9093

9194

9295
2. Allow inbound internet access
96+
97+
- use your default or previous created vpc
9398
![AWS Deployment Diagram](src_img\Screenshot (54).png)
9499

95100

@@ -103,7 +108,62 @@ An EC2 Key Pair in AWS is a set of security credentials used to securely connect
103108

104109
When you launch an EC2 instance, AWS uses the public key to encrypt the login credentials (e.g., a password). You use the private key to decrypt this information and securely log in to the instance.
105110

111+
![AWS Deployment Diagram](src_img\Screenshot (54).png)
112+
113+
### 5. Iam role
114+
115+
An AWS IAM Role is a tool within Amazon Web Services (AWS) Identity and Access Management (IAM) that allows entities (such as users, applications, or services) to assume temporary security credentials to interact with AWS resources. IAM roles are often used to delegate permissions without needing long-term credentials
116+
117+
step 1:
118+
create EC2 role
119+
120+
step 2:
121+
add permission to "AWSElasticBeanstalkWebTier","AWSElasticBeanstalkWorkerTier","AWSElasticBeanstalkMulticontainerDocker" policy.
122+
123+
step 3:
124+
Create Role name "EC2_instances_role"
125+
126+
127+
128+
129+
130+
106131

107132
## 1. Elastic Beanstalk
108133

109-
## 2. EC2
134+
**Amazon Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS.**
135+
136+
step 1:
137+
Go to Amazon Elastic Beanstalk
138+
Create application with environment
139+
140+
step 2:
141+
use default Existing service roles.
142+
add previouse created EC2 key pair.(Common steps 4)
143+
add previouse created EC2 instance profile.(Common steps 5)
144+
145+
step 3:
146+
use default VPC or created vpc(Common steps 2)
147+
148+
step 4:
149+
add the previouse created security group.(Common steps 3)
150+
use t3.micro or t2.mico
151+
152+
153+
154+
155+
156+
157+
## 2. EC2
158+
159+
step 1:
160+
create the EC2 instance
161+
162+
163+
step 2:
164+
connected the EC2 instance
165+
166+
step 3:
167+
168+
sudo su #access root
169+
yum

app.py

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import uvicorn
2+
import tempfile
3+
import shutil
4+
import os
5+
import warnings
6+
import logging
7+
8+
9+
from logging.handlers import RotatingFileHandler
10+
from fastapi import FastAPI, File, UploadFile,Form, BackgroundTasks
11+
from fastapi.middleware.cors import CORSMiddleware
12+
from fastapi.responses import StreamingResponse,FileResponse , JSONResponse,HTMLResponse
13+
14+
15+
16+
from src_v1.help import audio_basic_process
17+
18+
warnings.filterwarnings("ignore")
19+
20+
app=FastAPI(title="Fritzband",
21+
description="FastAPI",
22+
version="0.115.4")
23+
24+
25+
# Allow all origins (replace * with specific origins if needed)
26+
app.add_middleware(
27+
CORSMiddleware,
28+
allow_origins=["*"],
29+
allow_credentials=True,
30+
allow_methods=["*"],
31+
allow_headers=["*"],
32+
)
33+
34+
35+
36+
37+
@app.get("/")
38+
async def root():
39+
40+
return {"Fast API":"API is working"}
41+
42+
43+
44+
45+
logger = logging.getLogger(__name__)
46+
logger.setLevel(logging.DEBUG)
47+
48+
formatter = logging.Formatter('%(asctime)s:%(name)s:%(message)s')
49+
stream_handler = logging.StreamHandler()
50+
stream_handler.setFormatter(formatter)
51+
52+
logger.addHandler(stream_handler)
53+
54+
55+
56+
@app.post("/audio_classification_lstm_mfcc")
57+
async def audio_classification_lstm_mfcc(audio_file: UploadFile = File(...)):
58+
try:
59+
logger.info(f"input data send to the script ******************************")
60+
# Create a temporary directory
61+
temp_dir = tempfile.mkdtemp()
62+
63+
# Create a temporary file path
64+
temp_file_path = os.path.join(temp_dir,audio_file.filename)
65+
66+
# Write the uploaded file content to the temporary file
67+
with open(temp_file_path, "wb") as temp_file:
68+
shutil.copyfileobj(audio_file.file, temp_file)
69+
70+
71+
reports=audio_basic_process(temp_file_path)
72+
73+
# Clean up: Remove the temporary directory and its contents
74+
shutil.rmtree(temp_dir)
75+
76+
except Exception as e:
77+
78+
logger.info(f"Error message {e}")
79+
return {"status":0,"Message":f"Exception error:{e}"}
80+
81+
else:
82+
83+
logger.info(f"Return output {reports} ******************************")
84+
return {"status":1,"class_details": reports}
85+
86+
87+
88+
89+
90+
91+
92+
if __name__=="__main__":
93+
94+
uvicorn.run("app:app",host="0.0.0.0", port=8000, reload=True)

requirements.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
librosa
2+
3+
uvicorn[standard]
4+
gunicorn
5+
fastapi
6+
python-multipart
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
option_settings:
22
"aws:elasticbeanstalk:container:python":
3-
WSGIPath: uvicorn app:app --host 0.0.0.0 --port 8000
3+
WSGIPath: python app.py
44

run_ebextention/run_ebextention.zip

2.19 KB
Binary file not shown.

src_img/Screenshot (56).png

173 KB
Loading

src_img/Screenshot (57).png

192 KB
Loading

src_img/Screenshot (58).png

150 KB
Loading

src_img/Screenshot (59).png

90.8 KB
Loading

src_img/Screenshot (60).png

287 KB
Loading

src_v1/__init__.py

Whitespace-only changes.

src_v1/help.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
import librosa
3+
4+
5+
6+
def audio_basic_process(audio_path):
7+
sound_sample1,sr=librosa.load(audio_path ,mono=True)
8+
9+
return {"sound_sample1":len(sound_sample1),"sr":sr}
10+
11+
12+
13+

0 commit comments

Comments
 (0)