tfrere commited on
Commit
dc37e9e
·
1 Parent(s): a798955

update title and english translate

Browse files
Files changed (2) hide show
  1. README.md +35 -35
  2. app/server.py +5 -5
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: minimal-browser-screenshot-experiment
3
  emoji: 💻
4
  colorFrom: blue
5
  colorTo: red
@@ -8,72 +8,72 @@ app_file: app/server.py
8
  pinned: false
9
  ---
10
 
11
- # Minimal Browser Screenshot Experiment avec Helium
12
 
13
- Cette application web permet de prendre des captures d'écran de sites web en utilisant un navigateur headless et de les afficher directement dans l'interface utilisateur.
14
 
15
- ## Fonctionnalités
16
 
17
- - Interface web simple et responsive
18
- - Saisie d'URL avec valeur par défaut pointant vers Open LLM Leaderboard
19
- - Capture d'écran via Helium (navigateur Chrome)
20
- - Affichage des résultats dans l'interface
21
 
22
- ## Technologies utilisées
23
 
24
  - **Backend**: FastAPI, Helium
25
- - **Frontend**: HTML/JS avec Tailwind CSS
26
- - **Gestion des dépendances**: Poetry
27
- - **Déploiement**: Docker, Hugging Face Spaces
28
 
29
- ## Installation locale
30
 
31
- ### Prérequis
32
 
33
  - Python 3.10+
34
  - Poetry
35
- - Docker (optionnel)
36
 
37
- ### Installation avec Poetry
38
 
39
  ```bash
40
- # Cloner le dépôt
41
  git clone [repo-url]
42
  cd minimal-browser-screenshot-experiment
43
 
44
- # Installer les dépendances
45
  poetry install
46
 
47
- # Lancer l'application
48
  poetry run uvicorn app.server:app --host 0.0.0.0 --port 7860
49
  ```
50
 
51
- ### Utilisation de Docker
52
 
53
  ```bash
54
- # Construire l'image Docker
55
  docker build -t minimal-browser-screenshot .
56
 
57
- # Lancer le conteneur
58
  docker run -p 7860:7860 minimal-browser-screenshot
59
  ```
60
 
61
- ## Déploiement sur Hugging Face Spaces
62
 
63
- Cette application est conçue pour être facilement déployée sur un Hugging Face Space.
64
 
65
- 1. Créer un nouveau Space de type Docker
66
- 2. Associer ce dépôt GitHub à votre Space
67
- 3. Le Space utilisera automatiquement le Dockerfile fourni pour construire et déployer l'application
68
 
69
- ## Utilisation
70
 
71
- 1. Accéder à l'application via votre navigateur
72
- 2. Saisir l'URL du site dont vous souhaitez prendre une capture d'écran (par défaut: Open LLM Leaderboard)
73
- 3. Cliquer sur "Take a screenshot"
74
- 4. Attendre quelques secondes que le navigateur headless charge la page et prenne la capture d'écran
75
- 5. La capture d'écran apparaît dans l'interface
76
 
77
- ## À propos d'Helium
78
 
79
- Helium est une bibliothèque Python qui simplifie l'automatisation des navigateurs. C'est une couche d'abstraction au-dessus de Selenium qui offre une API plus simple et plus intuitive. Helium a été choisi pour remplacer Playwright dans ce projet pour démontrer sa facilité d'utilisation.
 
1
  ---
2
+ title: minimal-helium-experiment
3
  emoji: 💻
4
  colorFrom: blue
5
  colorTo: red
 
8
  pinned: false
9
  ---
10
 
11
+ # Minimal Browser Screenshot Experiment with Helium
12
 
13
+ This web application allows taking screenshots of websites using a headless browser and displaying them directly in the user interface.
14
 
15
+ ## Features
16
 
17
+ - Simple and responsive web interface
18
+ - URL input with default value pointing to Open LLM Leaderboard
19
+ - Screenshot capture via Helium (Chrome browser)
20
+ - Display of results in the interface
21
 
22
+ ## Technologies Used
23
 
24
  - **Backend**: FastAPI, Helium
25
+ - **Frontend**: HTML/JS with Tailwind CSS
26
+ - **Dependency Management**: Poetry
27
+ - **Deployment**: Docker, Hugging Face Spaces
28
 
29
+ ## Local Installation
30
 
31
+ ### Prerequisites
32
 
33
  - Python 3.10+
34
  - Poetry
35
+ - Docker (optional)
36
 
37
+ ### Installation with Poetry
38
 
39
  ```bash
40
+ # Clone the repository
41
  git clone [repo-url]
42
  cd minimal-browser-screenshot-experiment
43
 
44
+ # Install dependencies
45
  poetry install
46
 
47
+ # Launch the application
48
  poetry run uvicorn app.server:app --host 0.0.0.0 --port 7860
49
  ```
50
 
51
+ ### Using Docker
52
 
53
  ```bash
54
+ # Build the Docker image
55
  docker build -t minimal-browser-screenshot .
56
 
57
+ # Run the container
58
  docker run -p 7860:7860 minimal-browser-screenshot
59
  ```
60
 
61
+ ## Deployment on Hugging Face Spaces
62
 
63
+ This application is designed to be easily deployed on a Hugging Face Space.
64
 
65
+ 1. Create a new Docker-type Space
66
+ 2. Associate this GitHub repository with your Space
67
+ 3. The Space will automatically use the provided Dockerfile to build and deploy the application
68
 
69
+ ## Usage
70
 
71
+ 1. Access the application through your browser
72
+ 2. Enter the URL of the site you want to screenshot (default: Open LLM Leaderboard)
73
+ 3. Click "Take a screenshot"
74
+ 4. Wait a few seconds for the headless browser to load the page and take the screenshot
75
+ 5. The screenshot appears in the interface
76
 
77
+ ## About Helium
78
 
79
+ Helium is a Python library that simplifies browser automation. It's an abstraction layer on top of Selenium that offers a simpler and more intuitive API. Helium was chosen to replace Playwright in this project to demonstrate its ease of use.
app/server.py CHANGED
@@ -51,25 +51,25 @@ async def take_screenshot(url: str = Form(...)):
51
  logger.info(f"HOME env: {os.environ.get('HOME')}")
52
  logger.info(f"Current working directory: {os.getcwd()}")
53
 
54
- # Lancer Chrome avec des options simples
55
  logger.info("Launching Chrome browser")
56
  driver = start_chrome(headless=True)
57
 
58
  try:
59
- # Aller à l'URL
60
  logger.info(f"Navigating to URL: {url}")
61
  go_to(url)
62
 
63
- # Attendre que la page soit chargée
64
  logger.info("Waiting for page to load")
65
  time.sleep(3)
66
 
67
- # Prendre la capture d'écran
68
  logger.info(f"Taking screenshot at {filepath}")
69
  driver.save_screenshot(filepath)
70
  logger.info(f"Screenshot saved to {filepath}")
71
  finally:
72
- # Toujours fermer le navigateur
73
  kill_browser()
74
  logger.info("Browser closed")
75
 
 
51
  logger.info(f"HOME env: {os.environ.get('HOME')}")
52
  logger.info(f"Current working directory: {os.getcwd()}")
53
 
54
+ # Launch Chrome with simple options
55
  logger.info("Launching Chrome browser")
56
  driver = start_chrome(headless=True)
57
 
58
  try:
59
+ # Navigate to URL
60
  logger.info(f"Navigating to URL: {url}")
61
  go_to(url)
62
 
63
+ # Wait for page to load
64
  logger.info("Waiting for page to load")
65
  time.sleep(3)
66
 
67
+ # Take the screenshot
68
  logger.info(f"Taking screenshot at {filepath}")
69
  driver.save_screenshot(filepath)
70
  logger.info(f"Screenshot saved to {filepath}")
71
  finally:
72
+ # Always close the browser
73
  kill_browser()
74
  logger.info("Browser closed")
75