Spaces:
Sleeping
Sleeping
Philippe commited on
Commit ·
d76a30d
1
Parent(s): 725ac3e
ƒñû Ajout Browser MCP - Navigation web intelligente
Browse files- Dockerfile +4 -3
- browser_mcp_server.py +27 -1
Dockerfile
CHANGED
|
@@ -34,9 +34,10 @@ RUN pip install --no-cache-dir --upgrade pip && \
|
|
| 34 |
COPY app.py .
|
| 35 |
COPY browser_mcp_server.py .
|
| 36 |
|
| 37 |
-
# Installer les navigateurs Playwright
|
| 38 |
-
RUN python -m playwright install chromium
|
| 39 |
-
|
|
|
|
| 40 |
|
| 41 |
# Exposer le port 7860 (port standard pour HF Spaces)
|
| 42 |
EXPOSE 7860
|
|
|
|
| 34 |
COPY app.py .
|
| 35 |
COPY browser_mcp_server.py .
|
| 36 |
|
| 37 |
+
# Installer les navigateurs Playwright de manière simple et directe
|
| 38 |
+
RUN python -m playwright install chromium && \
|
| 39 |
+
python -m playwright install-deps && \
|
| 40 |
+
python -c "from playwright.sync_api import sync_playwright; p = sync_playwright().start(); print('✅ Playwright OK'); p.stop()"
|
| 41 |
|
| 42 |
# Exposer le port 7860 (port standard pour HF Spaces)
|
| 43 |
EXPOSE 7860
|
browser_mcp_server.py
CHANGED
|
@@ -185,7 +185,33 @@ async def ensure_browser():
|
|
| 185 |
])
|
| 186 |
logger.info("🚀 Configuration HF Spaces détectée")
|
| 187 |
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
browser_state.context = await browser_state.browser.new_context(
|
| 190 |
viewport={'width': 1280, 'height': 720},
|
| 191 |
user_agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
|
|
|
| 185 |
])
|
| 186 |
logger.info("🚀 Configuration HF Spaces détectée")
|
| 187 |
|
| 188 |
+
try:
|
| 189 |
+
browser_state.browser = await browser_state.playwright.chromium.launch(**launch_options)
|
| 190 |
+
except Exception as e:
|
| 191 |
+
if "Executable doesn't exist" in str(e):
|
| 192 |
+
logger.error("❌ Navigateurs Playwright non installés. Tentative de réinstallation...")
|
| 193 |
+
try:
|
| 194 |
+
# Tentative de réinstallation automatique
|
| 195 |
+
import subprocess
|
| 196 |
+
import sys
|
| 197 |
+
result = subprocess.run([sys.executable, "-m", "playwright", "install", "chromium"],
|
| 198 |
+
capture_output=True, text=True, timeout=120)
|
| 199 |
+
if result.returncode == 0:
|
| 200 |
+
logger.info("✅ Réinstallation Playwright réussie")
|
| 201 |
+
# Nouvelle tentative
|
| 202 |
+
browser_state.browser = await browser_state.playwright.chromium.launch(**launch_options)
|
| 203 |
+
else:
|
| 204 |
+
logger.error(f"❌ Échec réinstallation: {result.stderr}")
|
| 205 |
+
raise Exception("Impossible d'installer les navigateurs Playwright")
|
| 206 |
+
except subprocess.TimeoutExpired:
|
| 207 |
+
logger.error("❌ Timeout lors de l'installation Playwright")
|
| 208 |
+
raise Exception("Timeout installation Playwright")
|
| 209 |
+
except Exception as install_error:
|
| 210 |
+
logger.error(f"❌ Erreur installation: {install_error}")
|
| 211 |
+
raise
|
| 212 |
+
else:
|
| 213 |
+
raise
|
| 214 |
+
|
| 215 |
browser_state.context = await browser_state.browser.new_context(
|
| 216 |
viewport={'width': 1280, 'height': 720},
|
| 217 |
user_agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|