Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,21 @@ import openai
|
|
8 |
api_key = "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"
|
9 |
openai.api_key = api_key
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def web_scrape(url):
|
12 |
options = webdriver.ChromeOptions()
|
13 |
options.add_argument('--headless')
|
@@ -21,26 +36,9 @@ def web_scrape(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 |
-
|
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 |
-
|
44 |
except WebDriverException as e:
|
45 |
return "error handle website"
|
46 |
finally:
|
@@ -50,7 +48,7 @@ def web_scrape(url):
|
|
50 |
return Image.open(BytesIO(screenshot))
|
51 |
|
52 |
iface = gr.Interface(
|
53 |
-
fn=
|
54 |
inputs=gr.inputs.Textbox(label="Website URL", default="https://stock.adobe.com/stock-photo/id/621214874"),
|
55 |
outputs=gr.outputs.Textbox(label="Web Content"),
|
56 |
title="Web Scraping with Selenium (Body Tag)",
|
|
|
8 |
api_key = "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"
|
9 |
openai.api_key = api_key
|
10 |
|
11 |
+
def generate_response():
|
12 |
+
try:
|
13 |
+
prompts = [
|
14 |
+
f"Please make 3 best microstock titles with {web_scrape}",
|
15 |
+
]
|
16 |
+
response = openai.Completion.create(
|
17 |
+
engine="davinci", # You can choose different engines
|
18 |
+
prompt=prompts,
|
19 |
+
max_tokens=50, # Adjust max_tokens as needed
|
20 |
+
)
|
21 |
+
generated_text = response.choices[0].text.strip()
|
22 |
+
return generated_text
|
23 |
+
except Exception as e:
|
24 |
+
return f"Error: {str(e)}"
|
25 |
+
|
26 |
def web_scrape(url):
|
27 |
options = webdriver.ChromeOptions()
|
28 |
options.add_argument('--headless')
|
|
|
36 |
wd.implicitly_wait(10)
|
37 |
page_title = wd.title.replace("Stock Photo | Adobe Stock", "").strip()
|
38 |
#content_value = meta_element.get_attribute("name")
|
39 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
return page_title
|
42 |
except WebDriverException as e:
|
43 |
return "error handle website"
|
44 |
finally:
|
|
|
48 |
return Image.open(BytesIO(screenshot))
|
49 |
|
50 |
iface = gr.Interface(
|
51 |
+
fn=generate_response,
|
52 |
inputs=gr.inputs.Textbox(label="Website URL", default="https://stock.adobe.com/stock-photo/id/621214874"),
|
53 |
outputs=gr.outputs.Textbox(label="Web Content"),
|
54 |
title="Web Scraping with Selenium (Body Tag)",
|