Skip to content

๐ŸŒฑ [ํ‚ค์›€ ํ‚ค์˜ค์Šคํฌ] ๋””์ง€ํ„ธ ์•ฝ์ž๋ฅผ ์œ„ํ•œ AI ํ™”๋ฉด ํ‚ค์›€ ํ‚ค์˜ค์Šคํฌ

Notifications You must be signed in to change notification settings

Kiwoom-Kiosk/Kiwoom-Kiosk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

39 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Kiwoom-Kiosk

๐ŸŒฑ [ํ‚ค์›€ ํ‚ค์˜ค์Šคํฌ] ๋””์ง€ํ„ธ ์•ฝ์ž๋ฅผ ์œ„ํ•œ AI ํ™”๋ฉด ํ‚ค์›€ ํ‚ค์˜ค์Šคํฌ


OpenSource Programming Team Project

ํ”„๋กœ์ ํŠธ ์†Œ๊ฐœ ์ฃผ์š” ๊ธฐ๋Šฅ ์ œ์ž‘๊ธฐ๊ฐ„ ์‚ฌ์šฉ ์Šคํƒ
"ํ‚ค์›€ ํ‚ค์˜ค์Šคํฌ"
๋””์ง€ํ„ธ ์•ฝ์ž๋ฅผ ์œ„ํ•œ
AI ํ™”๋ฉด ํ‚ค์›€ ํ‚ค์˜ค์Šคํฌ
๋”ฅ๋Ÿฌ๋‹_์—ฐ๋ น์ธต ์ด๋ฏธ์ง€ ์ธ์‹
ํ”„๋ก ํŠธ_ํ‚ค์˜ค์Šคํฌ ํ™”๋ฉด ์ œ์ž‘
๋ฐฑ_ํ‚ค์˜ค์Šคํฌ ๊ธฐ๋Šฅ ๊ตฌํ˜„
2024.05.20 ~ 2024.06.19


๐Ÿ‘ฅ ํŒ€์› ์†Œ๊ฐœ

๐Ÿฆ…๊น€์ง€์ˆ˜๐Ÿฆ… ๐Ÿป๋ฐ•์ƒ์•„๐Ÿป ๐Ÿณ์–‘๋‹ค์—ฐ๐Ÿณ
Deeplearning / BE Deeplearning / FE Deeplearning / BE

์‹œ์—ฐ ์˜์ƒ

ezgif-2-e7f3c45a0f ezgif-2-cf3e18e03f
50์„ธ ๋ฏธ๋งŒ ์‚ฌ์šฉ์ž UI 50์„ธ ์ด์ƒ ์‚ฌ์šฉ์ž UI

ํ”„๋กœ์ ํŠธ ๊ฐœ์š”

1๏ธโƒฃ ๊ธฐ์ˆ ๊ฐœ๋ฐœ ๋ฐฐ๊ฒฝ

  • ๋””์ง€ํ„ธ ์ „ํ™˜๊ณผ ์˜จ๋ผ์ธ ์„œ๋น„์Šค ํ™•์‚ฐ์œผ๋กœ ์ธํ•ด ๋‹ค์–‘ํ•œ ์—ฐ๋ น๋Œ€์˜ ์‚ฌ๋žŒ๋“ค์ด ํ‚ค์˜ค์Šคํฌ์™€ ๊ฐ™์€ ๋””์ง€ํ„ธ ๊ธฐ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋นˆ๋„๊ฐ€ ์ฆ๊ฐ€ํ•˜๊ณ  ์žˆ์Œ.
  • ๊ณ ๋ น์ž๋‚˜ ๋””์ง€ํ„ธ ์•ฝ์ž๋“ค์€ ์ž‘์€ ํ…์ŠคํŠธ์™€ ๋ณต์žกํ•œ UI ๋•Œ๋ฌธ์— ๋””์ง€ํ„ธ ๊ธฐ๊ธฐ ์‚ฌ์šฉ์— ์–ด๋ ค์›€์„ ๊ฒช๊ณ  ์žˆ์Œ.
    • ์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์—ฐ๋ น๋Œ€์— ๋งž์ถ˜ ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค(UI)๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ธฐ์ˆ ์ด ํ•„์š”ํ•จ.
    • ์ธ๊ณต์ง€๋Šฅ๊ณผ ์•ˆ๋ฉด ์ธ์‹ ๊ธฐ์ˆ ์„ ํ™œ์šฉํ•˜์—ฌ ์—ฐ๋ น๋Œ€๋ฅผ ์˜ˆ์ธกํ•˜๊ณ , ์ด์— ๋งž์ถฐ UI์˜ ํ…์ŠคํŠธ ๋ณผ๋ฅจ ํฌ๊ธฐ๋ฅผ ์ž๋™์œผ๋กœ ์กฐ์ ˆํ•˜๋Š” ์‹œ์Šคํ…œ์ด ํšจ๊ณผ์ ์ธ ๋Œ€์•ˆ์ด ๋  ์ˆ˜ ์žˆ์Œ.

2๏ธโƒฃ ๊ธฐ์ˆ ๊ฐœ๋ฐœ ๋ชฉํ‘œ

  • ๋ณธ ์—ฐ๊ตฌ๊ฐœ๋ฐœ์—์„œ๋Š” ์•ˆ๋ฉด ์ธ์‹ ๊ธฐ๋ฐ˜์˜ ์—ฐ๋ น๋Œ€ ์˜ˆ์ธก ๊ธฐ์ˆ ์„ ๊ฐœ๋ฐœํ•˜๊ณ , ์ด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ํ‚ค์˜ค์Šคํฌ UI์˜ ํ…์ŠคํŠธ ํฌ๊ธฐ๋ฅผ ์ž๋™ ์กฐ์ ˆํ•˜๋Š” ์‹œ์Šคํ…œ์„ ๊ตฌ์ถ•ํ•˜๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœ ํ•จ.
  • ์ถ”๊ฐ€์ ์œผ๋กœ ์‚ฌ์šฉ์ž์˜ ์—ฐ๋ น๋Œ€์— ๋”ฐ๋ผ ์ตœ์ ํ™”๋œ UI ์š”์†Œ๋ฅผ ์ •์˜ํ•˜๊ณ , ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์„ ๊ฐœ์„ ํ•˜๊ณ ์ž ํ•จ.

3๏ธโƒฃ ๊ธฐ๋Œ€ํšจ๊ณผ

๐Ÿ“ฑ [๊ธฐ์ˆ ์  ๊ธฐ๋Œ€ํšจ๊ณผ]

  • ์ธ๊ณต์ง€๋Šฅ ๊ธฐ๋ฐ˜ ์•ˆ๋ฉด ์ธ์‹ ๋ฐ ์—ฐ๋ น๋Œ€ ์˜ˆ์ธก ๊ธฐ์ˆ  ํ™•๋ณด.
  • ์—ฐ๋ น๋Œ€ ๋งž์ถคํ˜• UI ์ž๋™ ์กฐ์ ˆ ๊ธฐ์ˆ ์„ ํ†ตํ•ด ๋‹ค์–‘ํ•œ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ ํ•ฉํ•œ ํ‚ค์˜ค์Šคํฌ ํ™˜๊ฒฝ ์ œ๊ณต.
  • ๋‹ค์–‘ํ•œ ๋””์ง€ํ„ธ ๊ธฐ๊ธฐ ๋ฐ ์„œ๋น„์Šค์— ์ ์šฉ ๊ฐ€๋Šฅํ•œ ๋งž์ถคํ˜• ์ธํ„ฐํŽ˜์ด์Šค ๊ธฐ์ˆ  ํ™•๋ณด.

๐Ÿงฉ [์‚ฌํšŒ์  ๊ธฐ๋Œ€ํšจ๊ณผ]

  • ์—ฐ๋ น๋Œ€์— ๋งž์ถ˜ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜ ์ œ๊ณต์„ ํ†ตํ•ด ๋””์ง€ํ„ธ ์•ฝ์ž์˜ ๋””์ง€ํ„ธ ๊ธฐ๊ธฐ ์ ‘๊ทผ์„ฑ ํ–ฅ์ƒ.
  • ๊ณ ๋ น์ž ๋ฐ ๋””์ง€ํ„ธ ์•ฝ์ž์˜ ์‚ฌํšŒ์ ยท๊ด€๊ณ„์  ๊ณ ๋ฆฝ๊ฐ ์™„ํ™” ๋ฐ ๋””์ง€ํ„ธ ์†Œ์™ธ ๋ฐฉ์ง€.
  • ์‚ฌ์šฉ์ž์˜ ๋งŒ์กฑ๋„ ๋ฐ ํŽธ์˜์„ฑ ์ฆ๋Œ€๋ฅผ ํ†ตํ•œ ๋””์ง€ํ„ธ ์„œ๋น„์Šค์˜ ์ด์šฉ๋ฅ  ํ–ฅ์ƒ.

4๏ธโƒฃ ์„œ๋น„์Šค ์•„ํ‚คํ…์ฒ˜ ๊ณ„ํš

KakaoTalk_Photo_2024-06-19-00-51-30


5๏ธโƒฃ ์ผ์ •๊ณ„ํš ๊ฐ„ํŠธ์ฐจํŠธ



CNN ๋ชจ๋ธ ๊ตฌํ˜„

๐Ÿ”—Kiwoom-Kiosk ๋‚˜์ด ์˜ˆ์ธก ๋ชจ๋ธ ์ƒ์„ธ๋ณด๊ธฐ

๐Ÿ“Œ ์ˆซ์ž๋กœ ํ‘œํ˜„๋œ ์ธ์ข…, ์„ฑ๋ณ„ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ / ๋ฐ์ดํ„ฐ์…‹ ํด๋”์—์„œ ํŒŒ์ผ๋ช…์„ ๋ถ„์„ํ•˜์—ฌ ๋‚˜์ด, ์„ฑ๋ณ„, ์ธ์ข… ์ •๋ณด ์ถ”์ถœ

dataset_dict = {
    'race_id': {
        0: 'white',
        1: 'black',
        2: 'asian',
        3: 'indian',
        4: 'others'
    },
    'gender_id': {
        0: 'male',
        1: 'female'
    }
}

def parse_dataset(dataset_path, ext='jpg'):
    def parse_info_from_file(path):
        try:
            filename = os.path.split(path)[1]
            filename = os.path.splitext(filename)[0]
            age, gender, race, _ = filename.split('_')
            return int(age), dataset_dict['gender_id'][int(gender)], dataset_dict['race_id'][int(race)]
        except Exception as ex:
            return None, None, None

    files = glob(os.path.join(dataset_path, "*.%s" % ext))

    records = []
    for file in files:
        info = parse_info_from_file(file)
        records.append(info)

    df = pd.DataFrame(records)
    df['file'] = files
    df.columns = ['age', 'gender', 'race', 'file']
    df = df.dropna()

    return df

df = parse_dataset('UTKFace')

df.head()
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2024-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 1 11 34



๐Ÿ“Œ ์ด๋ฏธ์ง€ ์ „์ฒ˜๋ฆฌ, ๋ชจ๋ธ ๊ตฌ์„ฑ ๋ฐ ํ•™์Šต

def load_and_preprocess_image(filepath, target_size=(200, 200)):
    img = cv2.imread(filepath)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    img = cv2.resize(img, target_size)
    return img

files = df['file'].tolist()
ages = df['age'].tolist()

images = [load_and_preprocess_image(file) for file in files]
age = np.array(ages, dtype=np.int64)
images = np.array(images)

x_train_age, x_test_age, y_train_age, y_test_age = train_test_split(images, age, random_state=42, test_size=0.2)

model = Sequential([
    Flatten(input_shape=(200, 200, 3)),
    Dense(512, activation='relu'),
    Dropout(0.5),
    Dense(1, activation='linear')
])

model.compile(loss='mse', optimizer=Adam(), metrics=['mae'])

history = model.fit(
    datagen.flow(x_train_age, y_train_age, batch_size=batch_size),
    validation_data=(x_valid_age, y_valid_age),
    epochs=epochs,
    callbacks=callbacks
)

# ํ•™์Šต ๊ฒฐ๊ณผ ์‹œ๊ฐํ™”
plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)
plt.plot(history.history['loss'], label='Training Loss')
plt.plot(history.history['val_loss'], label='Validation Loss')
plt.legend()
plt.title('Loss')

plt.subplot(1, 2, 2)
plt.plot(history.history['mae'], label='Training MAE')
plt.plot(history.history['val_mae'], label='Validation MAE')
plt.legend()
plt.title('Mean Absolute Error')

plt.show()
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2024-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 1 08 51



๐Ÿ“Œ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ๋กœ ๋ชจ๋ธ ํ‰๊ฐ€

loss, mae = model.evaluate(x_test_age, y_test_age, verbose=0)
print(f'Test MAE: {mae}')

new_image = load_and_preprocess_image('test_image.jpg')
predicted_age = model.predict(np.expand_dims(new_image, axis=0))
print(f'Predicted Age: {predicted_age[0][0]}')
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2024-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 1 09 14



Backend

โ›“๏ธ Django์™€ CNN ๋ชจ๋ธ์„ ์—ฐ๊ฒฐํ•˜์—ฌ ์ด๋ฏธ์ง€์—์„œ ๋‚˜์ด๋ฅผ ์˜ˆ์ธกํ•˜๋Š” ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ์„ฑ

1๏ธโƒฃ views.py

1. ์‚ฌ์šฉ์ž ์ •์˜ ์†์‹ค ํ•จ์ˆ˜ ์ •์˜

def custom_mse(y_true, y_pred):
    return MeanSquaredError()(y_true, y_pred)

custom_mse

  • ํ‰๊ท  ์ œ๊ณฑ ์˜ค์ฐจ(MSE)๋ฅผ ๊ณ„์‚ฐํ•˜๊ณ , ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณต๋˜๋Š” MeanSquaredError ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„
  • ์ถ”ํ›„ ๋ชจ๋ธ์„ ์ปดํŒŒ์ผํ•  ๋•Œ ์‚ฌ์šฉ

2. ๋ชจ๋ธ ๋กœ๋“œ ์‹œ custom_objects ์ธ์ˆ˜ ์‚ฌ์šฉ

model = load_model(settings.MODEL_PATH, custom_objects={'mse': custom_mse})

load_model

  • ๋ฏธ๋ฆฌ ํ•™์Šต๋œ ๋ชจ๋ธ์„ ๋กœ๋“œํ•˜๊ณ  settings.MODEL_PATH๋Š” ๋ชจ๋ธ ํŒŒ์ผ์˜ ๊ฒฝ๋กœ๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉฐ, custom_objects ์ธ์ˆ˜๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž ์ •์˜ ์†์‹ค ํ•จ์ˆ˜์ธ custom_mse๋ฅผ ๋ชจ๋ธ์— ์ถ”๊ฐ€
  • ๋ชจ๋ธ์„ ๋กœ๋“œํ•˜๋ฉด์„œ ์‚ฌ์šฉ์ž ์ •์˜ ์†์‹ค ํ•จ์ˆ˜๋ฅผ ์ •์˜๋œ ์ด๋ฆ„('mse')์œผ๋กœ ์ธ์‹ํ•˜๋„๋ก ๊ตฌํ˜„

3. ๋ชจ๋ธ์˜ ์ž…๋ ฅ ํฌ๊ธฐ ํ™•์ธ ๋ฐ ์ด๋ฏธ์ง€ ์ „์ฒ˜๋ฆฌ ํ•จ์ˆ˜

input_shape = model.layers[0].input_shape
target_size = input_shape[1:3]

def load_and_preprocess_image(filepath, target_size=(200, 200)):
    img = cv2.imread(filepath)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    img = cv2.resize(img, target_size)
    img = img.astype('float32') / 255.0  # ์Šค์ผ€์ผ๋ง
    return img
  • input_shape: ๋ชจ๋ธ์˜ ์ฒซ ๋ฒˆ์งธ ๋ ˆ์ด์–ด์˜ ์ž…๋ ฅ ํ˜•ํƒœ๋ฅผ ํ™•์ธํ•˜๋Š” ๋ณ€์ˆ˜๋กœ, ๋ชจ๋ธ์— ์ž…๋ ฅํ•  ์ด๋ฏธ์ง€์˜ ํฌ๊ธฐ๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ
  • target_size: ์ด๋ฏธ์ง€ ์ „์ฒ˜๋ฆฌ ์‹œ ๋ฆฌ์‚ฌ์ด์ง•ํ•  ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•˜๊ณ , ๋ชจ๋ธ์˜ ์ž…๋ ฅ ํ˜•ํƒœ์™€ ์ผ์น˜์‹œํ‚ค๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ
  • load_and_preprocess_image: ์ด๋ฏธ์ง€๋ฅผ ์ „์ฒ˜๋ฆฌํ•˜๋Š” ํ•จ์ˆ˜์ด๊ณ , OpenCV๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€๋ฅผ ์ฝ๊ณ  RGB๋กœ ๋ณ€ํ™˜ํ•œ ํ›„, ์ง€์ •๋œ ํฌ๊ธฐ๋กœ ๋ฆฌ์‚ฌ์ด์ฆˆํ•˜๋ฉฐ, 0์—์„œ 1 ์‚ฌ์ด์˜ ๊ฐ’์œผ๋กœ ์ •๊ทœํ™”ํ•˜๋„๋ก ๊ตฌํ˜„

4. home ํ•จ์ˆ˜ ๋ฐ upload_image ํ•จ์ˆ˜

def home(request):
    return render(request, 'home.html')

def upload_image(request):
    if request.method == 'POST' and request.FILES['image']:
        img = request.FILES['image']
        fs = FileSystemStorage()
        filename = fs.save(img.name, img)
        uploaded_file_url = fs.url(filename)

        # ์ด๋ฏธ์ง€ ์ „์ฒ˜๋ฆฌ ๋ฐ ์˜ˆ์ธก
        img_path = os.path.join(settings.MEDIA_ROOT, filename)
        img = load_and_preprocess_image(img_path, target_size=target_size)
        img_array = np.expand_dims(img, axis=0)  # ๋ฐฐ์น˜ ์ฐจ์› ์ถ”๊ฐ€

        prediction = model.predict(img_array)
        age = int(prediction[0][0])

        return render(request, 'result.html', {
            'uploaded_file_url': uploaded_file_url,
            'age': age
        })
    return redirect('home')
  • home ํ•จ์ˆ˜: ํ™ˆ ํŽ˜์ด์ง€๋ฅผ ๋ Œ๋”๋ง
  • upload_image ํ•จ์ˆ˜: POST ์š”์ฒญ์ด ์˜ค๋ฉด ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  load_and_preprocess_image ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์ด๋ฏธ์ง€๋ฅผ ์ „์ฒ˜๋ฆฌํ•œ ํ›„, ์ „์ฒ˜๋ฆฌ๋œ ์ด๋ฏธ์ง€๋ฅผ ๋ชจ๋ธ์— ์ž…๋ ฅํ•˜์—ฌ ๋‚˜์ด๋ฅผ ์˜ˆ์ธกํ•˜๊ณ , ์˜ˆ์ธก ๊ฒฐ๊ณผ๋ฅผ result.html ํ…œํ”Œ๋ฆฟ์— ์ „๋‹ฌํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ œ๊ณต

2๏ธโƒฃ settings.py

from pathlib import Path
import os

BASE_DIR = Path(__file__).resolve().parent.parent

# ๋ชจ๋ธ ํŒŒ์ผ ๊ฒฝ๋กœ ์„ค์ •
MODEL_PATH = os.path.join(BASE_DIR, 'age_model_vgg16.h5')

# Django ๊ธฐ๋ณธ ์„ค์ •์€ ์ƒ๋žต, ์ถ”๊ฐ€๋œ ๋ถ€๋ถ„ ์„ค๋ช…
  • MODEL_PATH: CNN ๋ชจ๋ธ ํŒŒ์ผ(age_model_vgg16.h5)์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ์„ค์ •ํ•˜๊ณ , ํ•ด๋‹น ๊ฒฝ๋กœ๋กœ ๋ชจ๋ธ์„ load_model ํ•จ์ˆ˜๋กœ ๋กœ๋“œ
  • MEDIA_ROOT ๋ฐ MEDIA_URL: settings.py์—์„œ MEDIA_ROOT๋Š” ์—…๋กœ๋“œ๋œ ํŒŒ์ผ์˜ ์ €์žฅ ๊ฒฝ๋กœ๋ฅผ ์„ค์ •ํ•˜๊ณ , MEDIA_URL์€ ์—…๋กœ๋“œ๋œ ํŒŒ์ผ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” URL์„ ์„ค์ •ํ•˜๋„๋ก ๊ตฌํ˜„
  • ์ „์ฒด์ ์ธ ๋™์ž‘ ํ๋ฆ„
    • ์‚ฌ์šฉ์ž๊ฐ€ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋ฉด, ์ด๋Š” upload_image ํ•จ์ˆ˜์—์„œ ์ฒ˜๋ฆฌํ•˜๋„๋ก ๊ตฌํ˜„ ์ด๋ฏธ์ง€๊ฐ€ ์—…๋กœ๋“œ๋˜๋ฉด ํ•ด๋‹น ์ด๋ฏธ์ง€๋ฅผ ์ „์ฒ˜๋ฆฌํ•˜๊ณ , CNN ๋ชจ๋ธ์— ์ž…๋ ฅํ•˜์—ฌ ๋‚˜์ด๋ฅผ ์˜ˆ์ธกํ•œ ํ›„, ๊ฒฐ๊ณผ๋ฅผ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ฃผ๋Š” ๋ฐฉ์‹์œผ๋กœ ๋™์ž‘



Frontend

๐Ÿ“Œ ํด๋” ๊ตฌ์กฐ

|-- ๐Ÿ“ CLIENT
|    |
|        |-- ๐Ÿ“ asset 
|    |      |
|    |      |-- ๐Ÿ“ icon
|    |      |-- ๐Ÿ“ img
|    |
|        |-- ๐Ÿ“ feature 
|    |      |-- cart.js // ์žฅ๋ฐ”๊ตฌ๋‹ˆ ์ถ”๊ฐ€ ๊ธฐ๋Šฅ 
|    |      |-- filter.js // home.html -> ๋ฉ”๋‰ด ์นดํ…Œ๊ณ ๋ฆฌ ์„ ํƒ์— ๋”ฐ๋ฅธ ํ•„ํ„ฐ ๊ธฐ๋Šฅ 
|    |      |-- shoppingList.js //  ์ƒ์ˆ˜ ๋ฐ์ดํ„ฐ ๋ฆฌ์ŠคํŠธ 
|    |      
|    | ๐Ÿ“ pages
|    |      | - predictor.html // ์—ฐ๋ น ์˜ˆ์ธก page
|    |      | - home.html // home page
|    |      
|    | ๐Ÿ“ Styles
|    |      | - predictor.css// ์—ฐ๋ น ์˜ˆ์ธก๊ธฐ page css
|    |      | - home_Eldery.css// ํ‚ค์˜ค์Šคํฌ ๋””์ง€ํ„ธ ์•ฝ์ž  ๋ทฐ css
|    |      | - home._Youth.css // ํ‚ค์˜ค์Šคํฌ ์ผ๋ฐ˜ ๋ทฐ css



๐Ÿ“Œ ํ™”๋ฉด ๊ตฌํ˜„ ๊ธฐ๋Šฅ

1๏ธโƒฃ ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ api ํ†ต์‹ 

      document.getElementById("uploadForm").onsubmit = async function (event) {
        event.preventDefault();
        const formData = new FormData();
        const fileInput = document.getElementById("fileInput");
        formData.append("file", fileInput.files[0]);

        const uploadedImage = document.getElementById("uploadedImage");
        uploadedImage.src = URL.createObjectURL(fileInput.files[0]);
        uploadedImage.style.display = "block";

        const result = await uploadFile(formData);
        if (result.age !== undefined) {
          const age = result.age;
        } 
      };
  • ๋™์ž‘: ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๊ณ , FormData ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ์ดํ›„ uploadFile ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„œ๋ฒ„์— ํŒŒ์ผ์„ ์ „์†กํ•˜๊ณ , ์—ฐ๋ น ์˜ˆ์ธก ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›์•„์˜ด
  • ๊ธฐ๋Šฅ: ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•œ ํ›„์—๋Š” ์—…๋กœ๋“œ๋œ ์ด๋ฏธ์ง€๋ฅผ ํ™”๋ฉด์— ํ‘œ์‹œํ•˜๊ณ , ์˜ˆ์ธก๋œ ์—ฐ๋ น์„ ๋ฐ›์•„์„œ ์ถ”๊ฐ€์ ์ธ ์ฒ˜๋ฆฌ ์ง„ํ–‰

2๏ธโƒฃ ์—ฐ๋ น ์˜ˆ์ธก์— ๋”ฐ๋ฅธ ์ฒญ๋…„/๊ณ ๋ น ๋ถ„๋ฅ˜ ๊ฒฐ๊ณผ๋ฅผ setElderyStatus๋กœ ์ „๋‹ฌ

      function goToNextPage() {
        const fileInput = document.getElementById("fileInput");
        const result = document.getElementById("result");
        const age = result.age;
        if (age >= 50) {
         setElderyStatus(true);
        } else {
          setElderyStatus(false);
        }
      }
  • ๋™์ž‘: isEldery๋ผ๋Š” boolean ๋ณ€์ˆ˜๋ฅผ ๋ฐ›์•„์„œ, ์ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋‹ค์Œ ํŽ˜์ด์ง€ URL์„ ์ƒ์„ฑํ•˜๊ณ , ํ•ด๋‹น URL๋กœ ํŽ˜์ด์ง€๋ฅผ ์ด๋™
  • ๊ธฐ๋Šฅ: ์—ฐ๋ น ์˜ˆ์ธก ๊ฒฐ๊ณผ์— ๋”ฐ๋ผ ์ฒญ๋…„๊ณผ ๊ณ ๋ น์„ ๋ถ„๋ฅ˜ํ•˜๊ณ , ๊ทธ์— ๋”ฐ๋ฅธ ๋‹ค์Œ ํŽ˜์ด์ง€๋กœ์˜ ์ž๋™ ์ด๋™์„ ๋‹ด๋‹น

3๏ธโƒฃ ํŽ˜์ด์ง€ ๋‚ด ์˜ˆ์ธก๋œ ์—ฐ๋ น ์ถœ๋ ฅ

      function displayAge() {
        const fileInput = document.getElementById("fileInput");
        const result = document.getElementById("result");
        const age = result.age;
        if (age >= 50) {
          result.innerHTML = '<div class="large-ui">์˜ˆ์ธก ์—ฐ๋ น: ' + age + "</div>";
        } else {
          result.innerHTML = '<div class="regular-ui">์˜ˆ์ธก ์—ฐ๋ น: ' + age + "</div>";
        }
      }
  • ๋™์ž‘: ์˜ˆ์ธก๋œ ์—ฐ๋ น์„ ํ‘œ์‹œํ•˜๋Š” ํ•จ์ˆ˜๋กœ, result ์—˜๋ฆฌ๋จผํŠธ์— ์—ฐ๋ น์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ์Šคํƒ€์ผ์˜ ํ…์ŠคํŠธ๋ฅผ ์‚ฝ์ž…
  • ๊ธฐ๋Šฅ: ์˜ˆ์ธก๋œ ์—ฐ๋ น์„ ์‚ฌ์šฉ์ž์—๊ฒŒ ์‹œ๊ฐ์ ์œผ๋กœ ์ œ๊ณต. ์˜ˆ์ธก๋œ ์—ฐ๋ น์ด 50์„ธ ์ด์ƒ์ด๋ฉด ํฐ ํ…์ŠคํŠธ ์Šคํƒ€์ผ์„, ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์ผ๋ฐ˜์ ์ธ ํ…์ŠคํŠธ ์Šคํƒ€์ผ์„ ์ ์šฉ

50์„ธ ๋ฏธ๋งŒ ์‚ฌ์šฉ์ž ์—ฐ๋ น ์˜ˆ์ธก 50์„ธ ์ด์ƒ ์‚ฌ์šฉ์ž ์—ฐ๋ น ์˜ˆ์ธก

4๏ธโƒฃ ์—ฐ๋ น ์˜ˆ์ธก์— ๋”ฐ๋ฅธ ์ฒญ๋…„/๊ณ ๋ น ๋ถ„๋ฅ˜ ๊ฒฐ๊ณผ๋ฅผ isEldery๋ณ€์ˆ˜์˜ boolean ๊ฐ’์œผ๋กœ ์ž…๋ ฅ ๋ฐ›์•„ ๋ถ„๋ฅ˜์— ๋”ฐ๋ฅธ ํ‚ค์˜ค์Šคํฌ ํŽ˜์ด์ง€ ์ด๋™

      function setElderyStatus(isEldery) {
        var nextPageUrl = "/pages/home.html";
        nextPageUrl += "?isEldery=" + encodeURIComponent(isEldery);

        window.location.href = nextPageUrl;
      }
  • ๋™์ž‘: ์˜ˆ์ธก๋œ ์—ฐ๋ น์„ ๊ธฐ๋ฐ˜์œผ๋กœ setElderyStatus ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์ฒญ๋…„๊ณผ ๊ณ ๋ น์„ ๋ถ„๋ฅ˜ํ•˜๊ณ , ๊ทธ ๊ฒฐ๊ณผ์— ๋”ฐ๋ผ ๋‹ค์Œ ํŽ˜์ด์ง€๋กœ ์ด๋™
  • ๊ธฐ๋Šฅ: ์—ฐ๋ น ์˜ˆ์ธก ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›์•„์„œ ์ฒญ๋…„๊ณผ ๊ณ ๋ น์„ ๋ถ„๋ฅ˜ํ•˜๊ณ , ์ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋‹ค์Œ ๋‹จ๊ณ„์˜ ํ‚ค์˜ค์Šคํฌ ํŽ˜์ด์ง€๋กœ ์‚ฌ์šฉ์ž๋ฅผ ์ด๋™

50์„ธ ๋ฏธ๋งŒ ์‚ฌ์šฉ์ž ํ‚ค์˜ค์Šคํฌ ๋ฉ”๋‰ด 50์„ธ ์ด์ƒ ์‚ฌ์šฉ์ž ํ‚ค์˜ค์Šคํฌ ๋ฉ”๋‰ด

About

๐ŸŒฑ [ํ‚ค์›€ ํ‚ค์˜ค์Šคํฌ] ๋””์ง€ํ„ธ ์•ฝ์ž๋ฅผ ์œ„ํ•œ AI ํ™”๋ฉด ํ‚ค์›€ ํ‚ค์˜ค์Šคํฌ

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages