Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
inputs = tokenizer.encode(prompt, return_tensors="pt")
|
| 13 |
-
response = model.generate(inputs, max_length=100, num_return_sequences=1)
|
| 14 |
-
return tokenizer.decode(response[0], skip_special_tokens=True)
|
| 15 |
-
|
| 16 |
-
# Gradio interface
|
| 17 |
-
def chatbot_interface(prompt):
|
| 18 |
-
response = generate_response(prompt)
|
| 19 |
-
return response
|
| 20 |
-
|
| 21 |
-
# Create a Gradio interface
|
| 22 |
-
iface = gr.Interface(fn=chatbot_interface, inputs="text", outputs="text")
|
| 23 |
-
|
| 24 |
-
# Launch the interface
|
| 25 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from selenium import webdriver
|
| 3 |
+
from selenium.webdriver.support.ui import WebDriverWait
|
| 4 |
+
from selenium.webdriver.support import expected_conditions as EC
|
| 5 |
+
from selenium.webdriver.common.by import By
|
| 6 |
|
| 7 |
+
def scrape_website(url):
|
| 8 |
+
# Create a new instance of the Chrome driver
|
| 9 |
+
driver = webdriver.Chrome()
|
| 10 |
+
|
| 11 |
+
# Navigate to the provided URL
|
| 12 |
+
driver.get(url)
|
| 13 |
+
|
| 14 |
+
# Wait until all processes are complete
|
| 15 |
+
wait = WebDriverWait(driver, 10) # Maximum wait time in seconds
|
| 16 |
+
wait.until(EC.presence_of_element_located((By.TAG_NAME, 'body')))
|
| 17 |
+
|
| 18 |
+
# Extract the page title
|
| 19 |
+
title = driver.title
|
| 20 |
+
|
| 21 |
+
# Close the browser
|
| 22 |
+
driver.quit()
|
| 23 |
+
|
| 24 |
+
return title
|
| 25 |
|
| 26 |
+
# Define the Gradio interface
|
| 27 |
+
interface = gr.Interface(
|
| 28 |
+
fn=scrape_website,
|
| 29 |
+
inputs="text",
|
| 30 |
+
outputs="text",
|
| 31 |
+
title="Web Scraping Application",
|
| 32 |
+
description="Enter a URL to extract the page title."
|
| 33 |
+
)
|
| 34 |
|
| 35 |
+
# Run the Gradio app
|
| 36 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|