rblueeyes commited on
Commit
edb4f04
·
verified ·
1 Parent(s): 1453698

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -5
app.py CHANGED
@@ -2,9 +2,22 @@ import re
2
  import gradio as gr
3
  from transformers import pipeline
4
  import os
 
5
 
 
 
 
6
  os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
7
 
 
 
 
 
 
 
 
 
 
8
  # ======================
9
  # MODEL (LOAD SEKALI)
10
  # ======================
@@ -93,7 +106,7 @@ def rating_usia(kategori):
93
  return 0
94
 
95
  # ======================
96
- # CORE ANALYSIS
97
  # ======================
98
  def analyze_text(judul, isi):
99
  kalimat = split_kalimat(isi)
@@ -101,7 +114,12 @@ def analyze_text(judul, isi):
101
 
102
  detected = set()
103
 
 
 
 
104
  for w in windows:
 
 
105
  for kategori, desc in SEMANTIC_EVENT.items():
106
  res = classifier(
107
  w,
@@ -110,21 +128,39 @@ def analyze_text(judul, isi):
110
  )
111
  score = max(res["scores"])
112
 
 
 
 
113
  if score < THRESHOLD[kategori]:
 
114
  continue
115
 
116
  if score < 0.60:
117
- if event_completeness(w) < 2:
 
 
 
 
 
 
 
118
  continue
119
- if is_metaphor(w):
 
 
120
  continue
121
 
 
122
  detected.add(kategori)
123
 
 
 
 
 
124
  return rating_usia(detected), ", ".join(sorted(detected))
125
 
126
  # ======================
127
- # GRADIO UI + API
128
  # ======================
129
  demo = gr.Interface(
130
  fn=analyze_text,
@@ -139,10 +175,13 @@ demo = gr.Interface(
139
  title="READEAR — Semantic Content Rating"
140
  )
141
 
 
 
 
142
  if __name__ == "__main__":
143
  demo.launch(
144
  server_name="0.0.0.0",
145
- server_port=7860, # HF default
146
  ssr_mode=False,
147
  show_error=True
148
  )
 
2
  import gradio as gr
3
  from transformers import pipeline
4
  import os
5
+ import logging
6
 
7
+ # ======================
8
+ # ENV + LOGGING
9
+ # ======================
10
  os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
11
 
12
+ logging.basicConfig(
13
+ filename="debug.log",
14
+ level=logging.INFO,
15
+ format="%(asctime)s | %(message)s"
16
+ )
17
+
18
+ def log(msg):
19
+ logging.info(msg)
20
+
21
  # ======================
22
  # MODEL (LOAD SEKALI)
23
  # ======================
 
106
  return 0
107
 
108
  # ======================
109
+ # CORE ANALYSIS + DEBUG
110
  # ======================
111
  def analyze_text(judul, isi):
112
  kalimat = split_kalimat(isi)
 
114
 
115
  detected = set()
116
 
117
+ log("=" * 80)
118
+ log(f"JUDUL: {judul}")
119
+
120
  for w in windows:
121
+ log(f"\n[WINDOW]\n{w}")
122
+
123
  for kategori, desc in SEMANTIC_EVENT.items():
124
  res = classifier(
125
  w,
 
128
  )
129
  score = max(res["scores"])
130
 
131
+ log(f" - kategori: {kategori}")
132
+ log(f" score: {round(score, 3)} | threshold: {THRESHOLD[kategori]}")
133
+
134
  if score < THRESHOLD[kategori]:
135
+ log(" ❌ FAIL: threshold")
136
  continue
137
 
138
  if score < 0.60:
139
+ completeness = event_completeness(w)
140
+ metaphor = is_metaphor(w)
141
+
142
+ log(f" completeness: {completeness}")
143
+ log(f" metaphor: {metaphor}")
144
+
145
+ if completeness < 2:
146
+ log(" ❌ FAIL: event completeness")
147
  continue
148
+
149
+ if metaphor:
150
+ log(" ❌ FAIL: metaphor")
151
  continue
152
 
153
+ log(" ✅ ACCEPTED")
154
  detected.add(kategori)
155
 
156
+ log(f"\nFINAL KATEGORI: {list(detected)}")
157
+ log(f"RATING USIA: {rating_usia(detected)}")
158
+ log("=" * 80)
159
+
160
  return rating_usia(detected), ", ".join(sorted(detected))
161
 
162
  # ======================
163
+ # GRADIO UI (TIDAK DIUBAH)
164
  # ======================
165
  demo = gr.Interface(
166
  fn=analyze_text,
 
175
  title="READEAR — Semantic Content Rating"
176
  )
177
 
178
+ # ======================
179
+ # ENTRY POINT (STABIL HF)
180
+ # ======================
181
  if __name__ == "__main__":
182
  demo.launch(
183
  server_name="0.0.0.0",
184
+ server_port=7860,
185
  ssr_mode=False,
186
  show_error=True
187
  )