Spaces:
Running
Running
File size: 923 Bytes
ae95bfb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import gradio as gr
import asyncio
from crawl4ai import AsyncWebCrawler
from crawl4ai import CrawlerRunConfig, CacheMode
from crawl4ai.markdown_generation_strategy import DefaultMarkdownGenerator
def crawl_url_to_markdown(url):
async def _crawl(u):
config = CrawlerRunConfig(
cache_mode=CacheMode.BYPASS,
markdown_generator=DefaultMarkdownGenerator()
)
async with AsyncWebCrawler() as crawler:
result = await crawler.arun(u, config=config)
return result.markdown_v2.raw_markdown
return asyncio.run(_crawl(url))
demo = gr.Interface(
fn=crawl_url_to_markdown,
inputs="text",
outputs="text",
title="Crawl4AI to Markdown",
description="Enter a URL to crawl, returns page as Markdown"
)
if __name__ == "__main__":
# Launch on 0.0.0.0:7860 for Hugging Face Spaces
demo.launch(server_name="0.0.0.0", server_port=7860)
|