Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from scraper import scrape_to_markdown | |
| import mistune | |
| def process(url: str): | |
| """ | |
| Get website link -> Extract content -> Save in Markdown file -> Generate HTML for display in user interface. | |
| """ | |
| # اجرای تابع وباسکرپر | |
| result = scrape_to_markdown(url) | |
| # اگر خروجی tuple بود، فقط markdown (عنصر اول) رو نگه داریم | |
| md = result[0] if isinstance(result, tuple) else result | |
| # ذخیرهسازی در فایل Markdown | |
| filename = "output.md" | |
| with open(filename, "w", encoding="utf-8") as f: | |
| f.write(md) | |
| # تبدیل به HTML برای نمایش | |
| html = mistune.create_markdown()(md) | |
| return md, filename, html | |
| # رابط کاربری Gradio | |
| with gr.Blocks(css="style.css") as demo: | |
| gr.Markdown("## 🌐 Web to Markdown Scraper and Converter") | |
| with gr.Row(): | |
| url_input = gr.Textbox(label="🔗 Enter the website link", placeholder="https://example.com") | |
| submit_btn = gr.Button("🔥 Content Extraction") | |
| with gr.Tab("📄 Markdown"): | |
| md_output = gr.Textbox(label="Markdown Content", lines=20) | |
| with gr.Tab("💾 Download"): | |
| file_output = gr.File(label="Download Markdown file") | |
| with gr.Tab("🌍 Preview HTML"): | |
| html_output = gr.HTML(label="HTML View") | |
| submit_btn.click(process, inputs=url_input, outputs=[md_output, file_output, html_output]) | |
| if __name__ == "__main__": | |
| demo.launch() |