KristofGaming39 commited on
Commit
6afcf4a
·
verified ·
1 Parent(s): c204e2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -24
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
- driver.get(url)
31
- time.sleep(3)
32
-
33
- search_box = driver.find_element(By.ID, "avatar-shop-keyword-input")
34
- search_box.clear()
35
- search_box.send_keys(character_name)
36
- search_box.send_keys(Keys.RETURN)
37
- time.sleep(5)
38
-
39
- items = driver.find_elements(By.XPATH, "//div[contains(@class, 'catalog-item-container')]")
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
- img_url = item.find_element(By.XPATH, ".//img").get_attribute("src")
47
- name = item.find_element(By.XPATH, ".//div[contains(@class, 'item-card-name')]").text
48
- link = item.find_element(By.XPATH, ".//a[contains(@class, 'item-card-link')]").get_attribute("href")
 
 
 
 
 
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