Spaces:
Sleeping
Sleeping
Rename project to "capture-page-tools" and implement Gradio app for webpage screenshot capture
Browse files- .github/workflows/deploy-to-huggingface.yml +1 -1
- Dockerfile +1 -1
- main.py +1 -1
- pyproject.toml +3 -1
- src/modules/apps/__init__.py +89 -0
- src/utils/__init__.py +1 -1
- uv.lock +0 -0
.github/workflows/deploy-to-huggingface.yml
CHANGED
|
@@ -43,7 +43,7 @@ jobs:
|
|
| 43 |
SPACE_NAME: ${{ secrets.SPACE_NAME }}
|
| 44 |
run: |
|
| 45 |
# Create repository URL
|
| 46 |
-
REPO_URL="https://huggingface.co/spaces/$HF_USERNAME/
|
| 47 |
|
| 48 |
# Add Hugging Face as a remote and push
|
| 49 |
git remote add space $REPO_URL || git remote set-url space $REPO_URL
|
|
|
|
| 43 |
SPACE_NAME: ${{ secrets.SPACE_NAME }}
|
| 44 |
run: |
|
| 45 |
# Create repository URL
|
| 46 |
+
REPO_URL="https://huggingface.co/spaces/$HF_USERNAME/capture-page-tools"
|
| 47 |
|
| 48 |
# Add Hugging Face as a remote and push
|
| 49 |
git remote add space $REPO_URL || git remote set-url space $REPO_URL
|
Dockerfile
CHANGED
|
@@ -32,7 +32,7 @@ ENTRYPOINT []
|
|
| 32 |
|
| 33 |
RUN python setup.py
|
| 34 |
|
| 35 |
-
EXPOSE
|
| 36 |
# Run the FastAPI application by default
|
| 37 |
# Uses `fastapi dev` to enable hot-reloading when the `watch` sync occurs
|
| 38 |
# Uses `--host 0.0.0.0` to allow access from outside the container
|
|
|
|
| 32 |
|
| 33 |
RUN python setup.py
|
| 34 |
|
| 35 |
+
EXPOSE 7860
|
| 36 |
# Run the FastAPI application by default
|
| 37 |
# Uses `fastapi dev` to enable hot-reloading when the `watch` sync occurs
|
| 38 |
# Uses `--host 0.0.0.0` to allow access from outside the container
|
main.py
CHANGED
|
@@ -10,7 +10,7 @@ def main() -> None:
|
|
| 10 |
"""Main application entry point."""
|
| 11 |
try:
|
| 12 |
print("Start app...")
|
| 13 |
-
import src.modules.
|
| 14 |
|
| 15 |
except Exception as e:
|
| 16 |
logging.error(f"Application failed to start: {e}", exc_info=True)
|
|
|
|
| 10 |
"""Main application entry point."""
|
| 11 |
try:
|
| 12 |
print("Start app...")
|
| 13 |
+
import src.modules.apps
|
| 14 |
|
| 15 |
except Exception as e:
|
| 16 |
logging.error(f"Application failed to start: {e}", exc_info=True)
|
pyproject.toml
CHANGED
|
@@ -1,14 +1,16 @@
|
|
| 1 |
[project]
|
| 2 |
-
name = "
|
| 3 |
version = "0.1.0"
|
| 4 |
description = "Add your description here"
|
| 5 |
readme = "README.md"
|
| 6 |
requires-python = ">=3.11"
|
| 7 |
dependencies = [
|
| 8 |
"fastapi[standard]>=0.115.8",
|
|
|
|
| 9 |
"ipykernel>=6.29.5",
|
| 10 |
"numpy>=2.2.3",
|
| 11 |
"pytest>=8.3.4",
|
|
|
|
| 12 |
]
|
| 13 |
|
| 14 |
[tool.black]
|
|
|
|
| 1 |
[project]
|
| 2 |
+
name = "capture-page-tools"
|
| 3 |
version = "0.1.0"
|
| 4 |
description = "Add your description here"
|
| 5 |
readme = "README.md"
|
| 6 |
requires-python = ">=3.11"
|
| 7 |
dependencies = [
|
| 8 |
"fastapi[standard]>=0.115.8",
|
| 9 |
+
"gradio>=5.3.0",
|
| 10 |
"ipykernel>=6.29.5",
|
| 11 |
"numpy>=2.2.3",
|
| 12 |
"pytest>=8.3.4",
|
| 13 |
+
"selenium>=4.29.0",
|
| 14 |
]
|
| 15 |
|
| 16 |
[tool.black]
|
src/modules/apps/__init__.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tempfile
|
| 3 |
+
import os
|
| 4 |
+
from selenium import webdriver
|
| 5 |
+
from selenium.webdriver.chrome.options import Options
|
| 6 |
+
print("Gradio app loaded.")
|
| 7 |
+
def capture_page(url: str, output_file: str = "screenshot.png"):
|
| 8 |
+
"""
|
| 9 |
+
Captures a screenshot of the given webpage.
|
| 10 |
+
|
| 11 |
+
:param url: The URL of the webpage to capture.
|
| 12 |
+
:param output_file: The filename to save the screenshot.
|
| 13 |
+
"""
|
| 14 |
+
options = Options()
|
| 15 |
+
options.add_argument("--headless") # Run in headless mode
|
| 16 |
+
options.add_argument("--window-size=1920,1080") # Set window size
|
| 17 |
+
|
| 18 |
+
driver = webdriver.Chrome(options=options)
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
driver.get(url)
|
| 22 |
+
driver.save_screenshot(output_file)
|
| 23 |
+
print(f"Screenshot saved: {output_file}")
|
| 24 |
+
finally:
|
| 25 |
+
driver.quit()
|
| 26 |
+
|
| 27 |
+
def capture_and_show(url: str):
|
| 28 |
+
"""Capture webpage and return the image"""
|
| 29 |
+
try:
|
| 30 |
+
# Create temporary file for the screenshot
|
| 31 |
+
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp:
|
| 32 |
+
temp_path = tmp.name
|
| 33 |
+
|
| 34 |
+
# Capture the webpage
|
| 35 |
+
capture_page(url, temp_path)
|
| 36 |
+
|
| 37 |
+
# Return the image path
|
| 38 |
+
return temp_path
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"Error capturing page: {str(e)}"
|
| 41 |
+
|
| 42 |
+
def create_gradio_app():
|
| 43 |
+
"""Create the main Gradio application with all components"""
|
| 44 |
+
with gr.Blocks() as app:
|
| 45 |
+
gr.Markdown("# Webpage Screenshot Capture")
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
+
url_input = gr.Textbox(
|
| 49 |
+
label="Website URL",
|
| 50 |
+
placeholder="Enter website URL (e.g., https://www.example.com)",
|
| 51 |
+
scale=4
|
| 52 |
+
)
|
| 53 |
+
capture_btn = gr.Button("Capture", scale=1)
|
| 54 |
+
|
| 55 |
+
with gr.Row():
|
| 56 |
+
output_image = gr.Image(
|
| 57 |
+
label="Captured Screenshot",
|
| 58 |
+
type="filepath"
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
# Connect the components
|
| 62 |
+
capture_btn.click(
|
| 63 |
+
fn=capture_and_show,
|
| 64 |
+
inputs=[url_input],
|
| 65 |
+
outputs=[output_image]
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
return app
|
| 69 |
+
|
| 70 |
+
app = create_gradio_app()
|
| 71 |
+
|
| 72 |
+
# Configure server settings for Docker deployment
|
| 73 |
+
server_port = 7860 # Standard Gradio port
|
| 74 |
+
server_name = "0.0.0.0" # Allow external connections
|
| 75 |
+
|
| 76 |
+
def main():
|
| 77 |
+
"""Launch the Gradio application"""
|
| 78 |
+
print("Starting Gradio server...")
|
| 79 |
+
app.launch(
|
| 80 |
+
server_name=server_name,
|
| 81 |
+
server_port=server_port,
|
| 82 |
+
share=False, # Disable sharing as we're running in Docker
|
| 83 |
+
auth=None, # Can be configured if authentication is needed
|
| 84 |
+
ssl_verify=False, # Disable SSL verification for internal Docker network
|
| 85 |
+
show_error=True,
|
| 86 |
+
favicon_path=None
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
main()
|
src/utils/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
"""
|
| 2 |
Main application package.
|
| 3 |
This is the root package of the application.
|
| 4 |
-
"""
|
|
|
|
| 1 |
"""
|
| 2 |
Main application package.
|
| 3 |
This is the root package of the application.
|
| 4 |
+
"""
|
uv.lock
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|