Spaces:
Sleeping
Sleeping
Update app.py
Browse files1 unmodified line234567891082 unmodified lines939495969798991 unmodified line1011021031041051061072 unmodified lines1101111121131141151161171181191201211221231241251261271281291308 unmodified lines1391401411421431441451461471481 unmodified lineimport gradio as grfrom transformers import pipelineimport osos.environ["GRADIO_ANALYTICS_ENABLED"] = "False"# ======================# MODEL (LOAD SEKALI)# ======================82 unmodified linesreturn 0# ======================# CORE ANALYSIS# ======================def analyze_text(judul, isi):kalimat = split_kalimat(isi)1 unmodified linedetected = set()for w in windows:for kategori, desc in SEMANTIC_EVENT.items():res = classifier(w,2 unmodified lines)score = max(res["scores"])if score < THRESHOLD[kategori]:continueif score < 0.60:if event_completeness(w) < 2:continueif is_metaphor(w):continuedetected.add(kategori)return rating_usia(detected), ", ".join(sorted(detected))# ======================# GRADIO UI + API# ======================demo = gr.Interface(fn=analyze_text,8 unmodified linestitle="READEAR β Semantic Content Rating")if __name__ == "__main__":demo.launch(server_name="0.0.0.0",server_port=7860, # HF defaultssr_mode=False,show_error=True)1 unmodified line23456789101112131415161718192021222382 unmodified lines1061071081091101111121 unmodified line1141151161171181191201211221231241252 unmodified lines1281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651668 unmodified lines1751761771781791801811821831841851861871 unmodified lineimport gradio as grfrom transformers import pipelineimport osimport logging# ======================# ENV + LOGGING# ======================os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"logging.basicConfig(filename="debug.log",level=logging.INFO,format="%(asctime)s | %(message)s")def log(msg):logging.info(msg)# ======================# MODEL (LOAD SEKALI)# ======================82 unmodified linesreturn 0# ======================# CORE ANALYSIS + DEBUG# ======================def analyze_text(judul, isi):kalimat = split_kalimat(isi)1 unmodified linedetected = set()log("=" * 80)log(f"JUDUL: {judul}")for w in windows:log(f"\n[WINDOW]\n{w}")for kategori, desc in SEMANTIC_EVENT.items():res = classifier(w,2 unmodified lines)score = max(res["scores"])log(f" - kategori: {kategori}")log(f" score: {round(score, 3)} | threshold: {THRESHOLD[kategori]}")if score < THRESHOLD[kategori]:log(" β FAIL: threshold")continueif score < 0.60:completeness = event_completeness(w)metaphor = is_metaphor(w)log(f" completeness: {completeness}")log(f" metaphor: {metaphor}")if completeness < 2:log(" β FAIL: event completeness")continueif metaphor:log(" β FAIL: metaphor")continuelog(" β ACCEPTED")detected.add(kategori)log(f"\nFINAL KATEGORI: {list(detected)}")log(f"RATING USIA: {rating_usia(detected)}")log("=" * 80)return rating_usia(detected), ", ".join(sorted(detected))# ======================# GRADIO UI (TIDAK DIUBAH)# ======================demo = gr.Interface(fn=analyze_text,8 unmodified linestitle="READEAR β Semantic Content Rating")# ======================# ENTRY POINT (STABIL HF)# ======================if __name__ == "__main__":demo.launch(server_name="0.0.0.0",server_port=7860,ssr_mode=False,show_error=True)
app.py+44-5