crawl4ai-demo / app.py
unclecode's picture
Initil commit
ae95bfb
raw
history blame contribute delete
923 Bytes
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)