Spaces:
Running
Running
| import os | |
| import sys | |
| os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0" | |
| os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" | |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) | |
| from app.models.text_classifier_ensemble import ensemble_predict | |
| from sklearn.datasets import fetch_20newsgroups | |
| print("Downloading/Loading 20 Newsgroups (Real Human Text)...") | |
| newsgroups = fetch_20newsgroups(subset='train', categories=['sci.space', 'comp.graphics'], remove=('headers', 'footers', 'quotes')) | |
| human_texts = [] | |
| # Grab 3 decent-sized human texts | |
| for text in newsgroups.data: | |
| words = text.split() | |
| if 50 < len(words) < 200: | |
| human_texts.append(" ".join(words)) | |
| if len(human_texts) >= 2: | |
| break | |
| ai_texts = [ | |
| "The exploration of space has always been a fundamental endeavor for humanity. In recent decades, advancements in propulsion technology and satellite imaging have revolutionized our understanding of the cosmos. Organizations like NASA and private entities such as SpaceX have spearheaded missions that extend our reach beyond low Earth orbit. For instance, the deployment of the James Webb Space Telescope has provided unprecedented views of early galaxies, offering insights into the formation of the universe. Furthermore, the Artemis program aims to establish a sustainable human presence on the Moon, serving as a stepping stone for future crewed missions to Mars. These technological milestones not only push the boundaries of scientific knowledge but also inspire future generations to look toward the stars.", | |
| "Computer graphics have fundamentally transformed the way we interact with digital media, bridging the gap between imagination and visual reality. Early rendering techniques relied on basic rasterization, which limited the complexity of 3D models. However, the advent of hardware-accelerated ray tracing has allowed for physically accurate lighting, reflections, and shadows in real-time applications. Modern graphics processing units (GPUs) utilize parallel processing architectures to handle millions of polygons per frame, enabling photorealistic environments in video games and architectural visualizations. Additionally, machine learning algorithms are now being integrated to upscale textures and generate assets dynamically. As virtual and augmented reality platforms continue to evolve, the demand for highly efficient, immersive graphics rendering will undoubtedly drive the next era of technological innovation." | |
| ] | |
| print("\n=== TESTING REAL HUMAN TEXTS (From 1999 Newsgroups) ===") | |
| for i, text in enumerate(human_texts): | |
| print(f"\n[HUMAN TEXT {i+1}] Snippet: {text[:80]}...") | |
| res = ensemble_predict(text) | |
| print(f" -> Verdict: {res.get('verdict')} | Score: {res.get('score'):.4f}") | |
| print(f" -> Signals: {res.get('signals')}") | |
| print("\n=== TESTING AI TEXTS (Generated by modern LLM) ===") | |
| for i, text in enumerate(ai_texts): | |
| print(f"\n[AI TEXT {i+1}] Snippet: {text[:80]}...") | |
| res = ensemble_predict(text) | |
| print(f" -> Verdict: {res.get('verdict')} | Score: {res.get('score'):.4f}") | |
| print(f" -> Signals: {res.get('signals')}") | |