rblueeyes commited on
Commit
a169def
·
verified ·
1 Parent(s): 7c5f4f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -4,7 +4,7 @@ import gradio as gr
4
  from transformers import pipeline
5
 
6
  # ======================
7
- # MODEL
8
  # ======================
9
  classifier = pipeline(
10
  "zero-shot-classification",
@@ -80,8 +80,8 @@ def sliding_window(kalimat, window=4):
80
  ]
81
 
82
  def event_completeness(text):
83
- score = 0
84
  text = text.lower()
 
85
  for words in EVENT_UNITS.values():
86
  if any(w in text for w in words):
87
  score += 1
@@ -111,12 +111,17 @@ def analyze_text(judul, isi):
111
 
112
  for w in windows:
113
  for kategori, desc in SEMANTIC_EVENT.items():
114
- res = classifier(w, desc, hypothesis_template="Teks ini menggambarkan {}.")
 
 
 
 
115
  score = max(res["scores"])
116
 
117
  if score < THRESHOLD[kategori]:
118
  continue
119
 
 
120
  if score < 0.60:
121
  if event_completeness(w) < 2:
122
  continue
@@ -137,12 +142,15 @@ app = Flask(__name__)
137
 
138
  @app.route("/analyze", methods=["POST"])
139
  def analyze_api():
140
- data = request.json
141
- result = analyze_text(data.get("judul", ""), data.get("isi", ""))
 
 
 
142
  return jsonify(result)
143
 
144
  # ======================
145
- # GRADIO DEMO (JANGAN DIHILANGKAN)
146
  # ======================
147
  def gradio_analyze(judul, isi):
148
  r = analyze_text(judul, isi)
@@ -162,7 +170,12 @@ demo = gr.Interface(
162
  )
163
 
164
  # ======================
165
- # ENTRY POINT
166
  # ======================
167
  if __name__ == "__main__":
168
- demo.launch(server_name="0.0.0.0", server_port=8080)
 
 
 
 
 
 
4
  from transformers import pipeline
5
 
6
  # ======================
7
+ # MODEL (LOAD SEKALI)
8
  # ======================
9
  classifier = pipeline(
10
  "zero-shot-classification",
 
80
  ]
81
 
82
  def event_completeness(text):
 
83
  text = text.lower()
84
+ score = 0
85
  for words in EVENT_UNITS.values():
86
  if any(w in text for w in words):
87
  score += 1
 
111
 
112
  for w in windows:
113
  for kategori, desc in SEMANTIC_EVENT.items():
114
+ res = classifier(
115
+ w,
116
+ desc,
117
+ hypothesis_template="Teks ini menggambarkan {}."
118
+ )
119
  score = max(res["scores"])
120
 
121
  if score < THRESHOLD[kategori]:
122
  continue
123
 
124
+ # Zona abu-abu → validasi
125
  if score < 0.60:
126
  if event_completeness(w) < 2:
127
  continue
 
142
 
143
  @app.route("/analyze", methods=["POST"])
144
  def analyze_api():
145
+ data = request.json or {}
146
+ result = analyze_text(
147
+ data.get("judul", ""),
148
+ data.get("isi", "")
149
+ )
150
  return jsonify(result)
151
 
152
  # ======================
153
+ # GRADIO DEMO (WAJIB ADA)
154
  # ======================
155
  def gradio_analyze(judul, isi):
156
  r = analyze_text(judul, isi)
 
170
  )
171
 
172
  # ======================
173
+ # ENTRY POINT (INI YANG FIX RESTART)
174
  # ======================
175
  if __name__ == "__main__":
176
+ demo.launch(
177
+ server_name="0.0.0.0",
178
+ server_port=8080,
179
+ share=False,
180
+ ssr_mode=False #INI KUNCI STABILITAS HF SPACE
181
+ )