mgokg's picture
Update app.py
a8b7167 verified
raw
history blame
1.19 kB
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
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
import time
options = webdriver.ChromeOptions()
options.add_argument('--headless')
wd = webdriver.Chrome(options=options)
def selenium(message):
try:
url = f"https://www.google.com/search?q=zugverbindung+bad+kissingen+{message}"
#url = 'https://www.spiegel.de'
#<ol class="AmbQnf">
wd.get(url)
wd.implicitly_wait(3)
element = wd.find_element(By.TAG_NAME, "body")
#texts = [element.text for element in elements]
time.sleep(1)
return element.text
except WebDriverException as e:
return "fehler"
finally:
if wd:
wd.quit()
iface = gr.Interface(
fn=selenium,
inputs="text",
outputs="text",
title="perplexity.ai",
description="get answer from perplexity"
)
iface.launch()