Upload 6 files
Browse files- Dockerfile +28 -0
- app.py +57 -0
- deep_learning_model(okt_drop).h5 +3 -0
- requirements.txt +6 -0
- scaler.pkl +3 -0
- tokenizer(okt_drop).json +0 -0
Dockerfile
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# λ² μ΄μ€ μ΄λ―Έμ§ μ€μ
|
2 |
+
FROM python:3.10-slim
|
3 |
+
|
4 |
+
# νμ ν¨ν€μ§ μ€μΉ λ° Java μ€μΉ
|
5 |
+
RUN apt-get update && \
|
6 |
+
apt-get install -y openjdk-11-jdk curl && \
|
7 |
+
apt-get clean
|
8 |
+
|
9 |
+
# νκ²½ λ³μ μ€μ
|
10 |
+
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
|
11 |
+
ENV PATH=$JAVA_HOME/bin:$PATH
|
12 |
+
|
13 |
+
# μμ
λλ ν 리 μ€μ
|
14 |
+
WORKDIR /app
|
15 |
+
|
16 |
+
# νμν νμΌλ€ 볡μ¬
|
17 |
+
COPY app.py /app
|
18 |
+
COPY requirements.txt /app
|
19 |
+
COPY deep_learning_model(okt_drop).h5 /app
|
20 |
+
COPY tokenizer(okt_drop).json /app
|
21 |
+
COPY scaler.pkl /app
|
22 |
+
|
23 |
+
# νμν Python ν¨ν€μ§ μ€μΉ
|
24 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
25 |
+
|
26 |
+
# μ ν리μΌμ΄μ
μ€ν
|
27 |
+
CMD ["python", "app.py"]
|
28 |
+
|
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
5 |
+
from sklearn.preprocessing import StandardScaler
|
6 |
+
import json
|
7 |
+
import re
|
8 |
+
from konlpy.tag import Okt
|
9 |
+
from tensorflow.keras.preprocessing.text import tokenizer_from_json
|
10 |
+
import pickle
|
11 |
+
|
12 |
+
# λͺ¨λΈ λ° ν ν¬λμ΄μ νμΌ λ‘λ
|
13 |
+
model = load_model('deep_learning_model(okt_drop).h5', compile=False)
|
14 |
+
|
15 |
+
with open('tokenizer(okt_drop).json', 'r', encoding='utf-8') as f:
|
16 |
+
tokenizer_data = f.read()
|
17 |
+
|
18 |
+
tokenizer = tokenizer_from_json(tokenizer_data)
|
19 |
+
|
20 |
+
with open('scaler.pkl', 'rb') as f:
|
21 |
+
scaler = pickle.load(f)
|
22 |
+
|
23 |
+
def calculate_sentence_stats(paragraph):
|
24 |
+
paragraph = re.sub(r'\.{2,}', '.', paragraph)
|
25 |
+
sentences = re.split(r'[.!?]', paragraph)
|
26 |
+
sentence_lengths = [len(s.strip()) for s in sentences if s.strip()]
|
27 |
+
sentence_count = len(sentence_lengths)
|
28 |
+
average_length = sum(sentence_lengths) / len(sentence_lengths) if sentence_lengths else 0
|
29 |
+
return sentence_count, average_length
|
30 |
+
|
31 |
+
def process_text(text):
|
32 |
+
okt = Okt()
|
33 |
+
texts = ' '.join(okt.nouns(text))
|
34 |
+
sequences = tokenizer.texts_to_sequences([texts])
|
35 |
+
max_len = 301
|
36 |
+
X = pad_sequences(sequences, maxlen=max_len)
|
37 |
+
return X
|
38 |
+
|
39 |
+
def predict_text(text, grade):
|
40 |
+
X = process_text(text)
|
41 |
+
sentence_count, sentence_average = calculate_sentence_stats(text)
|
42 |
+
length = len(text)
|
43 |
+
emoticon = 0
|
44 |
+
numeric_features = np.array([[int(grade), length, emoticon, sentence_count, sentence_average]])
|
45 |
+
numeric_features = scaler.transform(numeric_features)
|
46 |
+
prediction = model.predict([X, numeric_features])
|
47 |
+
predicted_label = 'μΈκ³΅μ§λ₯μ΄ μμ±ν λ
μκ°μλ¬Έμ
λλ€.' if prediction[0][0] > 0.5 else 'μ¬λμ΄ μμ±ν λ
μκ°μλ¬Έμ
λλ€.'
|
48 |
+
return predicted_label
|
49 |
+
|
50 |
+
iface = gr.Interface(
|
51 |
+
fn=predict_text,
|
52 |
+
inputs=[gr.Textbox(lines=10, placeholder="Enter Text Here..."), gr.Textbox(label="Grade")],
|
53 |
+
outputs="text",
|
54 |
+
title="λ
μκ°μλ¬Έ λΆμκΈ°",
|
55 |
+
description="μ΄ λ
μκ°μλ¬Έμ΄ νμμ μν΄ μμ±λμλμ§, μΈκ³΅μ§λ₯μ μν΄ μμ±λμλμ§ λΆμν©λλ€."
|
56 |
+
)
|
57 |
+
iface.launch(debug=True)
|
deep_learning_model(okt_drop).h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f464139189e497a20f91ea5f511ef0e15271f45ac0dcbf4743f9f782ce79413c
|
3 |
+
size 4892352
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
numpy
|
3 |
+
tensorflow==2.15.0
|
4 |
+
scikit-learn
|
5 |
+
konlpy
|
6 |
+
h5py
|
scaler.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a2679e430d3bfdd5cef34882fef19ac9c143a3355982123d4168687f0696c660
|
3 |
+
size 720
|
tokenizer(okt_drop).json
ADDED
The diff for this file is too large to render.
See raw diff
|
|