File size: 1,961 Bytes
e0b4e38
de01cb6
5c579db
 
 
f60388c
 
9ea10fc
f60388c
4d75a6f
850d477
5c579db
 
 
 
f150bb6
5c579db
 
 
 
 
f60388c
035990c
f60388c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ecabf86
f60388c
5c579db
ecabf86
5c579db
 
 
 
 
 
 
850d477
fb6b3ad
850d477
 
 
de01cb6
f150bb6
850d477
5c579db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import gradio as gr
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from PIL import Image
from io import BytesIO
import openai

api_key = "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"
openai.api_key = api_key

def web_scrape(url):
    options = webdriver.ChromeOptions()
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')

    try:
        wd = webdriver.Chrome(options=options)
        wd.set_window_size(1080, 720)  # Adjust the window size here
        wd.get(url)
        wd.implicitly_wait(10)
        page_title = wd.title.replace("Stock Photo | Adobe Stock", "").strip()
        #content_value = meta_element.get_attribute("name")
        prompts = [
            f"Please make 3 best microstock titles with {page_title}",
        ]

        titles = []
        for prompt in prompts:
            response = openai.Completion.create(
                engine="text-davinci-002",
                prompt=prompt,
                max_tokens=30,  # Adjust max_tokens as needed
                n=3,  # Generate 3 titles
                stop=None,  # You can specify stop words to end the titles if needed
            )

            generated_titles = [choice['text'] for choice in response['choices']]
            titles.extend(generated_titles)

        return "\n".join(titles)

        #return meta_element
    except WebDriverException as e:
        return "error handle website"
    finally:
        if wd:
            wd.quit()

    return Image.open(BytesIO(screenshot))

iface = gr.Interface(
    fn=web_scrape,
    inputs=gr.inputs.Textbox(label="Website URL", default="https://stock.adobe.com/stock-photo/id/621214874"),
    outputs=gr.outputs.Textbox(label="Web Content"),
    title="Web Scraping with Selenium (Body Tag)",
    description="Scrape the content of a website's <body> tag using Selenium.",
)


iface.launch()