Spaces:
Sleeping
Sleeping
Upload app_interface.py with huggingface_hub
Browse files- app_interface.py +130 -0
app_interface.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Simple web interface for CodeRefactor Gym Space.
|
| 3 |
+
This provides a basic HTML page to show the environment is running.
|
| 4 |
+
"""
|
| 5 |
+
from fastapi import FastAPI
|
| 6 |
+
from fastapi.responses import HTMLResponse
|
| 7 |
+
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
|
| 10 |
+
@app.get("/", response_class=HTMLResponse)
|
| 11 |
+
async def root():
|
| 12 |
+
"""Display environment info page."""
|
| 13 |
+
return """
|
| 14 |
+
<!DOCTYPE html>
|
| 15 |
+
<html>
|
| 16 |
+
<head>
|
| 17 |
+
<title>CodeRefactor Gym - OpenEnv Hackathon</title>
|
| 18 |
+
<style>
|
| 19 |
+
body {
|
| 20 |
+
font-family: 'Segoe UI', Arial, sans-serif;
|
| 21 |
+
max-width: 900px;
|
| 22 |
+
margin: 50px auto;
|
| 23 |
+
padding: 20px;
|
| 24 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 25 |
+
color: white;
|
| 26 |
+
}
|
| 27 |
+
.container {
|
| 28 |
+
background: rgba(255, 255, 255, 0.1);
|
| 29 |
+
backdrop-filter: blur(10px);
|
| 30 |
+
border-radius: 15px;
|
| 31 |
+
padding: 40px;
|
| 32 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 33 |
+
}
|
| 34 |
+
h1 { font-size: 2.5em; margin-bottom: 10px; }
|
| 35 |
+
h2 { color: #ffd700; margin-top: 30px; }
|
| 36 |
+
code {
|
| 37 |
+
background: rgba(0, 0, 0, 0.3);
|
| 38 |
+
padding: 2px 6px;
|
| 39 |
+
border-radius: 3px;
|
| 40 |
+
font-family: 'Courier New', monospace;
|
| 41 |
+
}
|
| 42 |
+
pre {
|
| 43 |
+
background: rgba(0, 0, 0, 0.5);
|
| 44 |
+
padding: 15px;
|
| 45 |
+
border-radius: 8px;
|
| 46 |
+
overflow-x: auto;
|
| 47 |
+
}
|
| 48 |
+
.status {
|
| 49 |
+
display: inline-block;
|
| 50 |
+
background: #00ff00;
|
| 51 |
+
color: #000;
|
| 52 |
+
padding: 5px 15px;
|
| 53 |
+
border-radius: 20px;
|
| 54 |
+
font-weight: bold;
|
| 55 |
+
}
|
| 56 |
+
a {
|
| 57 |
+
color: #ffd700;
|
| 58 |
+
text-decoration: none;
|
| 59 |
+
}
|
| 60 |
+
a:hover { text-decoration: underline; }
|
| 61 |
+
</style>
|
| 62 |
+
</head>
|
| 63 |
+
<body>
|
| 64 |
+
<div class="container">
|
| 65 |
+
<h1>🏋️ CodeRefactor Gym</h1>
|
| 66 |
+
<p><span class="status">✓ RUNNING</span></p>
|
| 67 |
+
|
| 68 |
+
<p>
|
| 69 |
+
Un environnement OpenEnv qui apprend aux agents RL à refactoriser
|
| 70 |
+
du code legacy en code moderne et maintenable.
|
| 71 |
+
</p>
|
| 72 |
+
|
| 73 |
+
<h2>📊 Caractéristiques</h2>
|
| 74 |
+
<ul>
|
| 75 |
+
<li>5 types de code legacy différents</li>
|
| 76 |
+
<li>Métriques de qualité objectives (complexité, type hints, etc.)</li>
|
| 77 |
+
<li>Rewards: -10 à +18 selon amélioration</li>
|
| 78 |
+
<li>Validation syntaxe AST Python</li>
|
| 79 |
+
</ul>
|
| 80 |
+
|
| 81 |
+
<h2>🔗 Endpoints API</h2>
|
| 82 |
+
<ul>
|
| 83 |
+
<li><code>GET /health</code> - Health check</li>
|
| 84 |
+
<li><code>POST /reset</code> - Reset environment</li>
|
| 85 |
+
<li><code>POST /step</code> - Execute action</li>
|
| 86 |
+
<li><code>GET /state</code> - Get current state</li>
|
| 87 |
+
<li><code>GET /docs</code> - API documentation (OpenAPI)</li>
|
| 88 |
+
</ul>
|
| 89 |
+
|
| 90 |
+
<h2>💻 Exemple d'utilisation</h2>
|
| 91 |
+
<pre><code>from openenv.client import Client
|
| 92 |
+
from models import CodeRefactorGymAction
|
| 93 |
+
|
| 94 |
+
# Connecter
|
| 95 |
+
client = Client(base_url="https://mo35-code-refactor-gym.hf.space")
|
| 96 |
+
|
| 97 |
+
# Reset
|
| 98 |
+
obs = client.reset()
|
| 99 |
+
print(f"Legacy code: {obs.legacy_code}")
|
| 100 |
+
|
| 101 |
+
# Refactoriser
|
| 102 |
+
action = CodeRefactorGymAction(
|
| 103 |
+
refactored_code="...",
|
| 104 |
+
reasoning="Added type hints and docstrings"
|
| 105 |
+
)
|
| 106 |
+
result = client.step(action)
|
| 107 |
+
print(f"Reward: {result.reward}")
|
| 108 |
+
print(f"Improvement: {result.improvement_score}/100")</code></pre>
|
| 109 |
+
|
| 110 |
+
<h2>📚 Documentation</h2>
|
| 111 |
+
<ul>
|
| 112 |
+
<li><a href="/docs">API Documentation (Swagger UI)</a></li>
|
| 113 |
+
<li><a href="https://github.com/meta-pytorch/OpenEnv">OpenEnv Framework</a></li>
|
| 114 |
+
</ul>
|
| 115 |
+
|
| 116 |
+
<h2>🏆 OpenEnv Hackathon 2025</h2>
|
| 117 |
+
<p>
|
| 118 |
+
Créé par <strong>mo35</strong> pour l'OpenEnv Hackathon.<br>
|
| 119 |
+
Framework: OpenEnv + TRL (GRPO) + Unsloth<br>
|
| 120 |
+
GPU: Northflank H100 80GB
|
| 121 |
+
</p>
|
| 122 |
+
</div>
|
| 123 |
+
</body>
|
| 124 |
+
</html>
|
| 125 |
+
"""
|
| 126 |
+
|
| 127 |
+
@app.get("/health")
|
| 128 |
+
async def health():
|
| 129 |
+
"""Health check endpoint."""
|
| 130 |
+
return {"status": "healthy"}
|