Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,53 +0,0 @@
|
|
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 |
-
|
11 |
-
model = load_model('deep_learning_model(okt_drop).h5')
|
12 |
-
|
13 |
-
with open('tokenizer(okt_drop).json', 'r', encoding='utf-8') as f:
|
14 |
-
tokenizer_data = f.read()
|
15 |
-
|
16 |
-
tokenizer = tokenizer_from_json(tokenizer_data)
|
17 |
-
|
18 |
-
def calculate_sentence_stats(paragraph):
|
19 |
-
paragraph = re.sub(r'\.{2,}', '.', paragraph)
|
20 |
-
sentences = re.split(r'[.!?]', paragraph)
|
21 |
-
sentence_lengths = [len(s.strip()) for s in sentences if s.strip()]
|
22 |
-
sentence_count = len(sentence_lengths)
|
23 |
-
average_length = sum(sentence_lengths) / len(sentence_lengths) if sentence_lengths else 0
|
24 |
-
return sentence_count, average_length
|
25 |
-
|
26 |
-
def process_text(text):
|
27 |
-
okt = Okt()
|
28 |
-
texts = ' '.join(okt.nouns(text))
|
29 |
-
sequences = tokenizer.texts_to_sequences([texts])
|
30 |
-
max_len = 301
|
31 |
-
X = pad_sequences(sequences, maxlen=max_len)
|
32 |
-
return X
|
33 |
-
|
34 |
-
def predict_text(text, grade):
|
35 |
-
X = process_text(text)
|
36 |
-
sentence_count, sentence_average = calculate_sentence_stats(text)
|
37 |
-
length = len(text)
|
38 |
-
emoticon = 0
|
39 |
-
numeric_features = np.array([[int(grade), length, emoticon, sentence_count, sentence_average]])
|
40 |
-
scaler = StandardScaler()
|
41 |
-
numeric_features = scaler.fit_transform(numeric_features)
|
42 |
-
prediction = model.predict([X, numeric_features])
|
43 |
-
predicted_label = '인공지능이 생성한 독서감상문입니다.' if prediction[0][0] > 0.5 else '사람이 작성한 독서감상문입니다.'
|
44 |
-
return predicted_label
|
45 |
-
|
46 |
-
iface = gr.Interface(
|
47 |
-
fn=predict_text,
|
48 |
-
inputs=[gr.Textbox(lines=10, placeholder="Enter Text Here..."), gr.Textbox(label="Grade")],
|
49 |
-
outputs="text",
|
50 |
-
title="독서감상문 분석기",
|
51 |
-
description="이 독서감상문이 학생에 의해 작성되었는지, 인공지능에 의해 생성되었는지 분석합니다."
|
52 |
-
)
|
53 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|