from flask import Flask, request, render_template_string import subprocess, tempfile, os, shutil, time, json, glob app = Flask(__name__) TOOLS = [ { "name": "PENgram", "command": "pengram run {repo_path}", "output_type": "file", "output_glob": "**/*.md" }, { "name": "Cartographer", "command": "cartographer {repo_path}", "output_type": "stdout" }, { "name": "llumsum", "command": "cd {repo_path} && npx llumsum", "output_type": "file", "output_glob": "*.summary" }, { "name": "GitIngest", "command": "gitingest {repo_path}", "output_type": "stdout" }, { "name": "Repomix", "command": "cd {repo_path} && npx repomix", "output_type": "file", "output_glob": "repomix-output.xml" } ] HTML_TEMPLATE = """ Uspoo - Summarizer Battle

🔬 Summarizer Test Bench

{% if results %}

مستودع الاختبار: {{ repo_url }}

{% for r in results %} {% endfor %}
الأداة الحالة الوقت (ث) حجم المخرج (KB) المخرجات الكاملة
{{ r.name }} {{ '✅ نجحت' if r.ok else '❌ فشلت' }} {{ "%.2f"|format(r.time) if r.time else '-' }} {{ r.size if r.size else '-' }} {% if r.ok and r.output %}
عرض كامل ({{ r.output_lines }} سطر)
{{ r.output }}
{% elif not r.ok %} {{ r.error }} {% else %} لم تنتج الأداة مخرجات {% endif %}
{% endif %} """ @app.route("/") def index(): repo_url = request.args.get("repo", "").strip() results = [] if repo_url: tmpdir = tempfile.mkdtemp() repo_name = repo_url.split("/")[-1].replace(".git", "") repo_path = os.path.join(tmpdir, repo_name) clone_cmd = f"git clone --depth 1 {repo_url} {repo_path}" clone_r = subprocess.run(clone_cmd, shell=True, capture_output=True) if clone_r.returncode != 0: shutil.rmtree(tmpdir) results.append({"name": "Clone", "ok": False, "time": 0, "size": 0, "output": "", "error": "فشل استنساخ المستودع"}) else: for tool in TOOLS: start = time.time() cmd = tool["command"].format(repo_path=repo_path) try: proc = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=180) elapsed = time.time() - start output = "" if tool["output_type"] == "stdout": output = proc.stdout.strip() if proc.returncode != 0: output = proc.stderr.strip() elif tool["output_type"] == "file": # ابحث عن الملفات المطابقة في المستودع وفي أي مكان pattern = os.path.join(repo_path, tool["output_glob"]) files = glob.glob(pattern, recursive=True) if not files: # ربما الأداة تضعها في مجلد الإخراج الحالي files = glob.glob(tool["output_glob"], recursive=True) if files: # خذ أول ملف مناسب with open(files[0], "r", encoding="utf-8", errors="ignore") as f: output = f.read() ok = bool(output.strip()) and proc.returncode == 0 results.append({ "name": tool["name"], "ok": ok, "time": elapsed, "size": round(len(output) / 1024, 2) if output else 0, "output": output, "output_lines": output.count('\n') + 1 if output else 0, "error": "" if ok else (proc.stderr[:500] if proc.returncode != 0 else "No output") }) except Exception as e: elapsed = time.time() - start results.append({ "name": tool["name"], "ok": False, "time": elapsed, "size": 0, "output": "", "output_lines": 0, "error": str(e)[:500] }) shutil.rmtree(tmpdir) return render_template_string(HTML_TEMPLATE, repo_url=repo_url, results=results) if __name__ == "__main__": app.run(host="0.0.0.0", port=7860)