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

update def analyze_text()

Browse files
Files changed (1) hide show
  1. app.py +40 -38
app.py CHANGED
@@ -114,50 +114,52 @@ def analyze_text(judul, 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,
126
- desc,
127
- hypothesis_template="Teks ini menggambarkan {}."
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)
 
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)