|
import gradio as gr |
|
from selenium import webdriver |
|
from selenium.common.exceptions import WebDriverException |
|
from selenium.webdriver.common.by import By |
|
from gradio_client import Client |
|
|
|
client = Client("Qwen/Qwen2.5-72B-Instruct") |
|
def take_screenshots(ort, start, end, step): |
|
options = webdriver.ChromeOptions() |
|
options.add_argument('--headless') |
|
wd = webdriver.Chrome(options=options) |
|
|
|
results = [] |
|
|
|
for i in range(start, end + 1, step): |
|
url = f"https://www.google.com/search?q=vereine+{ort}&start={i}" |
|
wd.get(url) |
|
wd.implicitly_wait(3) |
|
|
|
try: |
|
element = wd.find_element(By.TAG_NAME, "body") |
|
body_text = element.text |
|
results.append(body_text) |
|
except Exception as e: |
|
print(f"Error fetching data from {url}: {e}") |
|
|
|
wd.quit() |
|
erg ="\n".join(results) |
|
|
|
|
|
|
|
|
|
result = client.predict( |
|
query=f"erstelle ein json objekt für die vereine: \n{erg}", |
|
|
|
history=[], |
|
system="You are Qwen, created by Alibaba Cloud. You are a helpful assistant.", |
|
api_name="/model_chat" |
|
) |
|
result = result[1] |
|
result = result[0][1] |
|
result=gr.Markdown(result) |
|
return result |
|
|
|
iface = gr.Interface( |
|
fn=take_screenshots, |
|
inputs=[ |
|
gr.Textbox(label="Ort", value=""), |
|
gr.Number(label="Start Index", value=10), |
|
gr.Number(label="Anzahl Vereine", value=100), |
|
gr.Number(label="Step", value=10), |
|
], |
|
outputs=gr.Textbox(), |
|
title="Website Screenshot", |
|
description="Take screenshots of websites in specified range and step size for a given location." |
|
) |
|
|
|
iface.launch() |