Download app.py from paras9909/opticparse-universal-scraper: direct link, hf CLI and curl.
- Browser
- Download file 3.93 kB
-
https://huggingface.co/spaces/paras9909/opticparse-universal-scraper/resolve/main/app.py
- Command line
-
hf download hf://spaces/paras9909/opticparse-universal-scraper/app.py
-
curl -L -o app.py https://huggingface.co/spaces/paras9909/opticparse-universal-scraper/resolve/main/app.py
3.93 kB
| import gradio as gr | |
| import urllib.request | |
| import json | |
| import time | |
| GATEWAY_URL = "https://opticparse-rapidapi-gateway.parastejpal987.workers.dev/scrape" | |
| def extract_data(target_url, extraction_prompt): | |
| if not target_url or not extraction_prompt: | |
| return {"error": "Please provide both a Target URL and an Extraction Query."} | |
| start_t = time.time() | |
| try: | |
| req_data = json.dumps({"url": target_url.strip(), "query": extraction_prompt.strip()}).encode("utf-8") | |
| req = urllib.request.Request( | |
| GATEWAY_URL, | |
| data=req_data, | |
| headers={"Content-Type": "application/json", "User-Agent": "OpticParse-HuggingFace-Demo/1.0"} | |
| ) | |
| with urllib.request.urlopen(req, timeout=15) as resp: | |
| data = json.loads(resp.read().decode("utf-8")) | |
| data["demo_latency_ms"] = int((time.time() - start_t) * 1000) | |
| data["edge_engine"] = "Cloudflare Workers AI + Playwright Visual Buffer" | |
| return data | |
| except Exception as e: | |
| return { | |
| "error": f"Live edge scrape failed: {str(e)}", | |
| "fallback_hint": "Site may require anti-bot bypass. Use opticparse-py SDK for headful residential proxy routing.", | |
| "duration_ms": int((time.time() - start_t) * 1000) | |
| } | |
| with gr.Blocks(title="OpticParse Vision AI Web Scraper", theme=gr.themes.Soft()) as demo: | |
| gr.Markdown( | |
| ''' | |
| # π OpticParse β Live Multimodal AI Web Scraper | |
| ### Extract clean, structured JSON from any website with ZERO CSS selectors. | |
| [](https://opticparse.com) | |
| [](https://rapidapi.com/studio/) | |
| [](https://opticparse-edge.parastejpal987.workers.dev) | |
| [](https://pypi.org/project/opticparse-py/) | |
| ''' | |
| ) | |
| with gr.Row(): | |
| with gr.Column(): | |
| url_input = gr.Textbox(label="π Target URL", placeholder="https://news.ycombinator.com", value="https://news.ycombinator.com") | |
| query_input = gr.Textbox(label="π¬ What to extract (Plain English)", placeholder="Extract top 5 stories with title and url", value="Extract top 5 stories with title and url") | |
| btn_run = gr.Button("β‘ Run Live Vision AI Extraction", variant="primary") | |
| with gr.Column(): | |
| output_json = gr.JSON(label="Structured JSON Output (Live Result)") | |
| btn_run.click(fn=extract_data, inputs=[url_input, query_input], outputs=output_json) | |
| gr.Markdown( | |
| ''' | |
| --- | |
| ### π€ Autonomous AI Agent & Developer Access: | |
| #### 1. Python SDK: | |
| ```bash | |
| pip install opticparse-py | |
| ``` | |
| ```python | |
| from opticparse import OpticParseClient | |
| client = OpticParseClient(api_key="your_api_key") | |
| result = client.scrape(target_url="https://example.com", extraction_query="Extract product details") | |
| ``` | |
| #### 2. Machine-to-Machine Autonomous Crypto Payments ($0.05 USDC): | |
| ```bash | |
| curl -X POST https://opticparse-edge.parastejpal987.workers.dev/api/edge/scrape \ | |
| -H "X-Payment-TxHash: <YOUR_POLYGON_OR_BASE_TX_HASH>" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"url": "https://example.com"}' | |
| ``` | |
| *Zero sign-up required. Paid directly on Polygon, Base, or Arbitrum.* | |
| π **Dashboard & API Keys:** [https://opticparse.com](https://opticparse.com) | |
| ''' | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |