Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,10 @@ from selenium import webdriver
|
|
3 |
from selenium.common.exceptions import WebDriverException
|
4 |
from PIL import Image
|
5 |
from io import BytesIO
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def web_scrape(url):
|
8 |
options = webdriver.ChromeOptions()
|
@@ -15,10 +19,28 @@ def web_scrape(url):
|
|
15 |
wd.set_window_size(1080, 720) # Adjust the window size here
|
16 |
wd.get(url)
|
17 |
wd.implicitly_wait(10)
|
18 |
-
|
19 |
#content_value = meta_element.get_attribute("name")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
return meta_element
|
22 |
except WebDriverException as e:
|
23 |
return "error handle website"
|
24 |
finally:
|
|
|
3 |
from selenium.common.exceptions import WebDriverException
|
4 |
from PIL import Image
|
5 |
from io import BytesIO
|
6 |
+
import openai
|
7 |
+
|
8 |
+
api_key = "YOUR_API_KEY"
|
9 |
+
openai.api_key = api_key
|
10 |
|
11 |
def web_scrape(url):
|
12 |
options = webdriver.ChromeOptions()
|
|
|
19 |
wd.set_window_size(1080, 720) # Adjust the window size here
|
20 |
wd.get(url)
|
21 |
wd.implicitly_wait(10)
|
22 |
+
page_title = wd.title.replace("Stock Photo | Adobe Stock", "").strip()
|
23 |
#content_value = meta_element.get_attribute("name")
|
24 |
+
prompts = [
|
25 |
+
f"Please make 3 best microstock titles with {page_title}",
|
26 |
+
]
|
27 |
+
|
28 |
+
titles = []
|
29 |
+
for prompt in prompts:
|
30 |
+
response = openai.Completion.create(
|
31 |
+
engine="text-davinci-002",
|
32 |
+
prompt=prompt,
|
33 |
+
max_tokens=30, # Adjust max_tokens as needed
|
34 |
+
n=3, # Generate 3 titles
|
35 |
+
stop=None, # You can specify stop words to end the titles if needed
|
36 |
+
)
|
37 |
+
|
38 |
+
generated_titles = [choice['text'] for choice in response['choices']]
|
39 |
+
titles.extend(generated_titles)
|
40 |
+
|
41 |
+
return "\n".join(titles)
|
42 |
|
43 |
+
#return meta_element
|
44 |
except WebDriverException as e:
|
45 |
return "error handle website"
|
46 |
finally:
|