File size: 2,153 Bytes
718c4ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# evaluate_live.py
import requests
from io import BytesIO

# Import Twoich scraperów
from web_scraper_allegro import scrape_allegro_offer
from web_scraper_olx import scrape_olx_offer
from web_scraper_ebay import scrape_ebay_offer

API_URL = "http://localhost:7860/predict"

def call_model(auction):
    if not auction.get("image_urls"):
        return {"error": "No images found"}
    
    img_url = auction["image_urls"][0]
    print(f"📸 Pobieram zdjęcie: {img_url}")
    
    img_resp = requests.get(img_url, timeout=20)
    img_resp.raise_for_status()
    
    files = {
        "image": ("image.jpg", BytesIO(img_resp.content), "image/jpeg")
    }
    data = {
        "title": auction.get("title", ""),
        "description": auction.get("description", "")
    }
    
    r = requests.post(API_URL, files=files, data=data, timeout=120)
    r.raise_for_status()
    return r.json()

def scrape_offer(url: str):
    """Automatycznie wybiera scraper na podstawie domeny"""
    if "allegro.pl" in url:
        return scrape_allegro_offer(url)
    elif "olx.pl" in url:
        return scrape_olx_offer(url)
    elif "ebay." in url:
        return scrape_ebay_offer(url)
    else:
        raise ValueError("Nieobsługiwana platforma")

def evaluate_url(url: str):
    """Pełny pipeline: scrape → model → wynik"""
    print(f"🔍 Analizuję: {url}")
    
    auction = scrape_offer(url)
    print(f"📋 Zebrane: {auction['title'][:50]}...")
    
    model_result = call_model(auction)
    
    return {
        "url": url,
        "platform": auction["platform"],
        "title": auction["title"],
        "model_result": model_result,
    }

if __name__ == "__main__":
    while True:
        url = input("\nPodaj link do aukcji (lub 'q' do wyjścia): ")
        if url.lower() == 'q':
            break
        
        try:
            result = evaluate_url(url)
            print("\n" + "="*80)
            print(f"VERDICT: {result['model_result'].get('verdict')}")
            print(f"CONFIDENCE: {result['model_result'].get('confidence')}")
            print("="*80)
        except Exception as e:
            print(f"❌ Błąd: {e}")