yongyeol commited on
Commit
0c745fd
Β·
verified Β·
1 Parent(s): a8d6f3b

Upload 6 files

Browse files
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