paras9909's picture
Upload folder using huggingface_hub
e51b3eb verified
Raw History Blame Contribute Delete
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.
[![Website](https://img.shields.io/badge/Live_Platform-opticparse.com-blue)](https://opticparse.com)
[![RapidAPI](https://img.shields.io/badge/RapidAPI-5_Live_Gateways-informational)](https://rapidapi.com/studio/)
[![Autonomous Agent](https://img.shields.io/badge/Autonomous_Paywall-$0.05_USDC-purple)](https://opticparse-edge.parastejpal987.workers.dev)
[![Install](https://img.shields.io/badge/pip-install_opticparse--py-brightgreen)](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()