rblueeyes commited on
Commit
100b7f8
Β·
verified Β·
1 Parent(s): 116837f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -49
app.py CHANGED
@@ -2,21 +2,16 @@ import re
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)
@@ -106,7 +101,7 @@ def rating_usia(kategori):
106
  return 0
107
 
108
  # ======================
109
- # CORE ANALYSIS + DEBUG
110
  # ======================
111
  def analyze_text(judul, isi):
112
  kalimat = split_kalimat(isi)
@@ -114,55 +109,53 @@ def analyze_text(judul, isi):
114
 
115
  detected = set()
116
 
117
- with open("debug.log", "a", encoding="utf-8") as f:
118
- f.write("\n" + "="*80 + "\n")
119
- f.write(f"JUDUL: {judul}\n")
120
 
121
- for w in windows:
122
- f.write(f"\n[WINDOW]\n{w}\n")
 
123
 
124
- for kategori, desc in SEMANTIC_EVENT.items():
125
- res = classifier(
126
- w,
127
- desc,
128
- hypothesis_template="Teks ini menggambarkan {}."
129
- )
130
- score = max(res["scores"])
131
- threshold = THRESHOLD[kategori]
132
 
133
- f.write(
134
- f" - {kategori} | score={score:.3f} | threshold={threshold}\n"
135
- )
136
 
137
- if score < threshold:
138
- f.write(" ❌ FAIL: threshold\n")
139
- continue
140
 
141
- if score < 0.60:
142
- comp = event_completeness(w)
143
- meta = is_metaphor(w)
144
 
145
- f.write(f" completeness={comp}, metaphor={meta}\n")
146
 
147
- if comp < 2:
148
- f.write(" ❌ FAIL: completeness\n")
149
- continue
150
- if meta:
151
- f.write(" ❌ FAIL: metaphor\n")
152
- continue
153
 
154
- f.write(" βœ… ACCEPTED\n")
155
- detected.add(kategori)
156
 
157
- usia = rating_usia(detected)
158
- f.write(f"\nFINAL KATEGORI: {list(detected)}\n")
159
- f.write(f"RATING USIA: {usia}\n")
160
- f.write("="*80 + "\n")
161
 
162
  return usia, ", ".join(sorted(detected))
163
 
164
  # ======================
165
- # GRADIO UI (TIDAK DIUBAH)
166
  # ======================
167
  demo = gr.Interface(
168
  fn=analyze_text,
@@ -174,11 +167,11 @@ demo = gr.Interface(
174
  gr.Number(label="Rating Usia"),
175
  gr.Textbox(label="Kategori")
176
  ],
177
- title="READEAR"
178
  )
179
 
180
  # ======================
181
- # ENTRY POINT (STABIL HF)
182
  # ======================
183
  if __name__ == "__main__":
184
  demo.launch(
@@ -186,4 +179,4 @@ if __name__ == "__main__":
186
  server_port=7860,
187
  ssr_mode=False,
188
  show_error=True
189
- )
 
2
  import gradio as gr
3
  from transformers import pipeline
4
  import os
 
5
 
6
  # ======================
7
+ # ENV
8
  # ======================
9
  os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
10
+ DEBUG = True # ← MATIKAN kalau sudah selesai
 
 
 
 
 
11
 
12
  def log(msg):
13
+ if DEBUG:
14
+ print(msg, flush=True)
15
 
16
  # ======================
17
  # MODEL (LOAD SEKALI)
 
101
  return 0
102
 
103
  # ======================
104
+ # CORE ANALYSIS + DEBUG KE CONTAINER
105
  # ======================
106
  def analyze_text(judul, isi):
107
  kalimat = split_kalimat(isi)
 
109
 
110
  detected = set()
111
 
112
+ log("\n" + "=" * 80)
113
+ log(f"JUDUL: {judul}")
 
114
 
115
+ for w in windows:
116
+ log("\n[WINDOW]")
117
+ log(w)
118
 
119
+ for kategori, desc in SEMANTIC_EVENT.items():
120
+ res = classifier(
121
+ w,
122
+ desc,
123
+ hypothesis_template="Teks ini menggambarkan {}."
124
+ )
125
+ score = max(res["scores"])
126
+ threshold = THRESHOLD[kategori]
127
 
128
+ log(f" - {kategori} | score={score:.3f} | threshold={threshold}")
 
 
129
 
130
+ if score < threshold:
131
+ log(" ❌ FAIL: threshold")
132
+ continue
133
 
134
+ if score < 0.60:
135
+ comp = event_completeness(w)
136
+ meta = is_metaphor(w)
137
 
138
+ log(f" completeness={comp}, metaphor={meta}")
139
 
140
+ if comp < 2:
141
+ log(" ❌ FAIL: completeness")
142
+ continue
143
+ if meta:
144
+ log(" ❌ FAIL: metaphor")
145
+ continue
146
 
147
+ log(" βœ… ACCEPTED")
148
+ detected.add(kategori)
149
 
150
+ usia = rating_usia(detected)
151
+ log(f"\nFINAL KATEGORI: {list(detected)}")
152
+ log(f"RATING USIA: {usia}")
153
+ log("=" * 80)
154
 
155
  return usia, ", ".join(sorted(detected))
156
 
157
  # ======================
158
+ # GRADIO UI (JANGAN DIUBAH)
159
  # ======================
160
  demo = gr.Interface(
161
  fn=analyze_text,
 
167
  gr.Number(label="Rating Usia"),
168
  gr.Textbox(label="Kategori")
169
  ],
170
+ title="READEAR β€” Semantic Content Rating"
171
  )
172
 
173
  # ======================
174
+ # ENTRY POINT (ANTI-RESTART HF)
175
  # ======================
176
  if __name__ == "__main__":
177
  demo.launch(
 
179
  server_port=7860,
180
  ssr_mode=False,
181
  show_error=True
182
+ )