Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
from bs4 import BeautifulSoup
|
| 4 |
-
from selenium import webdriver
|
| 5 |
-
from selenium.webdriver.chrome.service import Service
|
| 6 |
-
from webdriver_manager.chrome import ChromeDriverManager
|
| 7 |
-
from selenium.webdriver.common.by import By
|
| 8 |
-
from selenium.webdriver.common.keys import Keys
|
| 9 |
-
import time
|
| 10 |
from PIL import Image
|
| 11 |
from transformers import ViltProcessor, ViltForQuestionAnswering
|
| 12 |
import torch
|
| 13 |
import torch.nn.functional as F
|
| 14 |
|
| 15 |
-
# Selenium WebDriver setup
|
| 16 |
-
options = webdriver.ChromeOptions()
|
| 17 |
-
options.add_argument("--headless") # Futás háttérben
|
| 18 |
-
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
|
| 19 |
-
|
| 20 |
# ViLT Model betöltése
|
| 21 |
model_path = "dandelin/vilt-b32-finetuned-vqa" # Hugging Face modell
|
| 22 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -27,25 +16,30 @@ processor = ViltProcessor.from_pretrained(model_path)
|
|
| 27 |
# Keresés a Roblox katalógusban
|
| 28 |
def search_roblox(character_name):
|
| 29 |
url = f"https://www.roblox.com/catalog?Category=3&salesTypeFilter=1"
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
items =
|
| 40 |
|
| 41 |
best_item = None
|
| 42 |
best_score = 0
|
| 43 |
|
| 44 |
for item in items[:5]: # Csak az első 5 találatot nézzük
|
| 45 |
try:
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
image = Image.open(requests.get(img_url, stream=True).raw).convert("RGB")
|
| 51 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
from transformers import ViltProcessor, ViltForQuestionAnswering
|
| 6 |
import torch
|
| 7 |
import torch.nn.functional as F
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# ViLT Model betöltése
|
| 10 |
model_path = "dandelin/vilt-b32-finetuned-vqa" # Hugging Face modell
|
| 11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 16 |
# Keresés a Roblox katalógusban
|
| 17 |
def search_roblox(character_name):
|
| 18 |
url = f"https://www.roblox.com/catalog?Category=3&salesTypeFilter=1"
|
| 19 |
+
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}
|
| 20 |
+
response = requests.get(url, headers=headers)
|
| 21 |
+
|
| 22 |
+
if response.status_code != 200:
|
| 23 |
+
return None, "Failed to fetch data", 0
|
| 24 |
+
|
| 25 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
| 26 |
+
|
| 27 |
+
# Az elemzéshez szükséges adatokat a megfelelő HTML elemekből szűrjük
|
| 28 |
+
items = soup.find_all('div', {'class': 'catalog-item-container'})
|
| 29 |
|
| 30 |
best_item = None
|
| 31 |
best_score = 0
|
| 32 |
|
| 33 |
for item in items[:5]: # Csak az első 5 találatot nézzük
|
| 34 |
try:
|
| 35 |
+
img_tag = item.find('img')
|
| 36 |
+
img_url = img_tag['src'] if img_tag else None
|
| 37 |
+
name = item.find('div', {'class': 'item-card-name'}).text.strip()
|
| 38 |
+
link_tag = item.find('a', {'class': 'item-card-link'})
|
| 39 |
+
link = link_tag['href'] if link_tag else None
|
| 40 |
+
|
| 41 |
+
if not img_url or not link:
|
| 42 |
+
continue
|
| 43 |
|
| 44 |
image = Image.open(requests.get(img_url, stream=True).raw).convert("RGB")
|
| 45 |
|