Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -70,14 +70,13 @@ base_replacements = {
|
|
| 70 |
'Aplikasi pesan':'Message app'
|
| 71 |
}
|
| 72 |
|
| 73 |
-
def clean_scrap(artikel,link,
|
| 74 |
new_artikel = []
|
| 75 |
-
article = [
|
| 76 |
-
openai.api_key = openai_key
|
| 77 |
if len(artikel) > 1:
|
| 78 |
for art in artikel:
|
| 79 |
response = openai.ChatCompletion.create(
|
| 80 |
-
|
| 81 |
messages=[
|
| 82 |
{"role": "system", "content": "You are a very professional article editor."},
|
| 83 |
{"role": "user", "content": "I have a raw article that contains a lot of unnecessary data such as ads, website information, and article publishers, as well as links to other pages, and so on. Please clean up the article I provided so that only the article's content remains. \nThen, you should also summarize the article so that it does not exceed 5000 characters" + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {the cleaned and summarized article's content}"}
|
|
@@ -91,7 +90,7 @@ def clean_scrap(artikel,link, openai_key):
|
|
| 91 |
else:
|
| 92 |
for art in artikel:
|
| 93 |
response = openai.ChatCompletion.create(
|
| 94 |
-
|
| 95 |
messages=[
|
| 96 |
{"role": "system", "content": "You are a very professional article editor."},
|
| 97 |
{"role": "user", "content": "I have a raw article that contains a lot of unnecessary data such as ads, website information, and article publishers, as well as links to other pages, and so on. Please clean up the article I provided so that only the article's content remains." + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {the cleaned article's content}"}
|
|
@@ -106,7 +105,7 @@ def clean_scrap(artikel,link, openai_key):
|
|
| 106 |
new_art = [' '.join(new_artikel)]
|
| 107 |
for art in new_art:
|
| 108 |
response = openai.ChatCompletion.create(
|
| 109 |
-
|
| 110 |
messages=[
|
| 111 |
{"role": "system", "content": "You are a very professional article editor and capable of generating compelling and professional article titles."},
|
| 112 |
{"role": "user", "content": "Paraphrase the above article to make it a well-written and easily understandable piece for humans, following the conventions of renowned articles. \nThen, You Must Generate a title that is appropriate for the article I provided. The title should be professional, similar to typical article titles and sound more natural for a human to read" + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: title:{title}, article: {new paraphrased article}"}
|
|
@@ -121,7 +120,7 @@ def clean_scrap(artikel,link, openai_key):
|
|
| 121 |
content = article[0].split("\n")
|
| 122 |
title = content[0].replace('title:', '').replace("Title:", '').strip()
|
| 123 |
response = openai.ChatCompletion.create(
|
| 124 |
-
|
| 125 |
messages=[
|
| 126 |
{"role": "system", "content": "You are a professional translator and rewriter"},
|
| 127 |
{"role": "user", "content": "Please translate and rewrite this sentence into Indonesian language with the following requirements: \n1. The sentence should be concise, compact, and clear. \n2. The sentence length should not exceed 50 characters. \n3. The sentences should be professional, similar to typical article titles and sound more natural for a human to read.:" +title+"\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: Judul:{hasil rewrite}"}
|
|
@@ -141,7 +140,7 @@ def clean_scrap(artikel,link, openai_key):
|
|
| 141 |
|
| 142 |
return title, judul, link, contents
|
| 143 |
|
| 144 |
-
def scrap_artikel(link_scrap,
|
| 145 |
options = webdriver.ChromeOptions()
|
| 146 |
options.add_argument('--headless')
|
| 147 |
options.add_argument('--no-sandbox')
|
|
@@ -173,11 +172,11 @@ def scrap_artikel(link_scrap, openai_key):
|
|
| 173 |
artikels = [part1, part2, part3, part4]
|
| 174 |
else :
|
| 175 |
artikels = [paragraf]
|
| 176 |
-
title, judul, url, contents = clean_scrap(artikels,link_scrap,
|
| 177 |
return title, judul, url, contents
|
| 178 |
|
| 179 |
-
def artikel_processing(link_scrap,backlink,keyword,
|
| 180 |
-
title, judul, url, artikel= scrap_artikel(link_scrap,
|
| 181 |
teks_to_tags = artikel[0][:500]
|
| 182 |
translated = []
|
| 183 |
optimized = []
|
|
@@ -185,10 +184,9 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
|
|
| 185 |
article = []
|
| 186 |
post_article = []
|
| 187 |
|
| 188 |
-
openai.api_key = openai_key
|
| 189 |
for i in artikel:
|
| 190 |
response = openai.ChatCompletion.create(
|
| 191 |
-
|
| 192 |
messages=[
|
| 193 |
{"role": "system", "content": "You are a proficient English to Indonesian language translator machine. You are capable of translating professionally according to the rules of the Indonesian language"},
|
| 194 |
{"role": "user", "content": "Translate the following article into Indonesian language. Then, you must resume the article translated. The translated result should be more than 2500 characters and less than 7000 characters.: " + i + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {Professionally rewritten content}"}
|
|
@@ -203,7 +201,7 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
|
|
| 203 |
|
| 204 |
for i in translated:
|
| 205 |
response = openai.ChatCompletion.create(
|
| 206 |
-
|
| 207 |
messages=[
|
| 208 |
{"role": "system", "content": f"""You are a very professional article editor and perform SEO optimization on an article with utmost professionalism. berikut adalah SOP SEO yang harus kamu terapkan
|
| 209 |
1. meta decription max 160 characters
|
|
@@ -225,7 +223,7 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
|
|
| 225 |
|
| 226 |
for i in optimized:
|
| 227 |
response = openai.ChatCompletion.create(
|
| 228 |
-
|
| 229 |
messages=[
|
| 230 |
{"role": "system", "content": f"""
|
| 231 |
You are a professional article writer and editor. I have an article that needs your editing expertise to align its writing style with specific instructions and guidelines:
|
|
@@ -261,7 +259,7 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
|
|
| 261 |
|
| 262 |
for i in article:
|
| 263 |
response = openai.ChatCompletion.create(
|
| 264 |
-
|
| 265 |
messages=[
|
| 266 |
{"role": "system", "content": "You are a professional article editor machine."},
|
| 267 |
{"role": "user", "content": "Please rewrite the given article in the style of a professional writer for Forbes or The New York Times with bahasa indonesia as your native language:\n\n" + i + "\nAdd underline tags <u> and bold tags <b> to all foreign terms (non-Indonesian words) you encounter. You only have less than 7 attempts to do this, no more than that in order to keep the article neat and clean. \nThen, You must divide the article into several paragraphs, no less than 3 paragraphs. kamu juga harus membuat subheading menggunakan <h2> pada setiap sub topik pembahasan \n\nPlease ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries. Provide only the reformatted article using this format:<h2>A brief headline of the article content</h2> <p>reformatted article</p>"}
|
|
@@ -274,7 +272,7 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
|
|
| 274 |
|
| 275 |
for i in edited_format:
|
| 276 |
response = openai.ChatCompletion.create(
|
| 277 |
-
|
| 278 |
messages=[
|
| 279 |
{"role": "system", "content": "You are a professional article editor machine."},
|
| 280 |
{"role": "user", "content": "Please edit the given article:\n" + "\n" + i + f"\nAdd annotations to the words with the keywords {keyword} to format them as links in the HTML structure.the link should be connected to {backlink} \nThe format should be like this: <a title={keyword} href={backlink}>{keyword}</a>. YOU MUST Do this FORMAT ONLY for the first 3 keywords that appear and MUST be on different keywords, IF a keyword appears more than twice then simply ignored it by not adding any links to those keywords. Do not combine two keyword into one or modify any keyword. You only have less than 3 attempts to do this, no more than that in order to keep the article neat and clean. \nExcept for the terms {keyword} you are prohibited from providing backlinks. Additionally, you are not allowed to include backlinks to individuals' names or technology company names such as Google, Microsoft, and others. \nYou only have less than 3 attempts to do this, no more than that in order to keep the article neat and clean.\nPlease ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries."+"Provide only the reformatted article using this format: {new_formatted_article}"}
|
|
@@ -297,7 +295,7 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
|
|
| 297 |
|
| 298 |
def generate_image_prompt(title):
|
| 299 |
response = openai.ChatCompletion.create(
|
| 300 |
-
|
| 301 |
messages=[
|
| 302 |
{"role" : "user", "content" : """ChatGPT will now enter "Midjourney Prompt Generator Mode" and restrict ChatGPT's inputs and outputs to a predefined framework, please follow these instructions carefully.
|
| 303 |
|
|
@@ -425,9 +423,22 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
|
|
| 425 |
image_data = None
|
| 426 |
return judul,content,image, image_data
|
| 427 |
|
| 428 |
-
def scrap(link_scrap,backlink,keyword,
|
| 429 |
try:
|
| 430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
desired_timezone = pytz.timezone('Asia/Jakarta')
|
| 432 |
current_time = datetime.datetime.now(desired_timezone)
|
| 433 |
Timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
@@ -511,13 +522,15 @@ with gr.Blocks(theme = "soft", title="Wordpress Article Generator") as article_g
|
|
| 511 |
link = gr.Textbox(placeholder="Masukkan Link Artikel Yang Akan di Scrap", label="Link")
|
| 512 |
backlink = gr.Textbox(placeholder="Masukkan Backlink Yang Akan Diterapkan", label="Backlink")
|
| 513 |
keyword = gr.Textbox(placeholder="Masukkan Keyword Artikel", label="Keyword")
|
| 514 |
-
|
|
|
|
|
|
|
| 515 |
replicate_token = gr.Textbox(placeholder="Masukkan Token Replicate", label="Replicate Key")
|
| 516 |
button_scrap = gr.Button("Scrap Article")
|
| 517 |
img = gr.Image()
|
| 518 |
outputs = gr.Textbox("", label="Judul")
|
| 519 |
content = gr.Textbox("", label="Content")
|
| 520 |
-
button_scrap.click(fn=scrap, inputs=[link,backlink,keyword,
|
| 521 |
with gr.Column():
|
| 522 |
endpoint= gr.Textbox(placeholder="Masukkan Endpoint Wordpress", label="Endpoint Wordpress")
|
| 523 |
endpoint_media= gr.Textbox(placeholder="Masukkan Endpoint Media Wordpress", label="Endpoint Media")
|
|
|
|
| 70 |
'Aplikasi pesan':'Message app'
|
| 71 |
}
|
| 72 |
|
| 73 |
+
def clean_scrap(artikel,link, models):
|
| 74 |
new_artikel = []
|
| 75 |
+
article = [
|
|
|
|
| 76 |
if len(artikel) > 1:
|
| 77 |
for art in artikel:
|
| 78 |
response = openai.ChatCompletion.create(
|
| 79 |
+
engine=models,
|
| 80 |
messages=[
|
| 81 |
{"role": "system", "content": "You are a very professional article editor."},
|
| 82 |
{"role": "user", "content": "I have a raw article that contains a lot of unnecessary data such as ads, website information, and article publishers, as well as links to other pages, and so on. Please clean up the article I provided so that only the article's content remains. \nThen, you should also summarize the article so that it does not exceed 5000 characters" + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {the cleaned and summarized article's content}"}
|
|
|
|
| 90 |
else:
|
| 91 |
for art in artikel:
|
| 92 |
response = openai.ChatCompletion.create(
|
| 93 |
+
engine=models,
|
| 94 |
messages=[
|
| 95 |
{"role": "system", "content": "You are a very professional article editor."},
|
| 96 |
{"role": "user", "content": "I have a raw article that contains a lot of unnecessary data such as ads, website information, and article publishers, as well as links to other pages, and so on. Please clean up the article I provided so that only the article's content remains." + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {the cleaned article's content}"}
|
|
|
|
| 105 |
new_art = [' '.join(new_artikel)]
|
| 106 |
for art in new_art:
|
| 107 |
response = openai.ChatCompletion.create(
|
| 108 |
+
engine=models,
|
| 109 |
messages=[
|
| 110 |
{"role": "system", "content": "You are a very professional article editor and capable of generating compelling and professional article titles."},
|
| 111 |
{"role": "user", "content": "Paraphrase the above article to make it a well-written and easily understandable piece for humans, following the conventions of renowned articles. \nThen, You Must Generate a title that is appropriate for the article I provided. The title should be professional, similar to typical article titles and sound more natural for a human to read" + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: title:{title}, article: {new paraphrased article}"}
|
|
|
|
| 120 |
content = article[0].split("\n")
|
| 121 |
title = content[0].replace('title:', '').replace("Title:", '').strip()
|
| 122 |
response = openai.ChatCompletion.create(
|
| 123 |
+
engine=models,
|
| 124 |
messages=[
|
| 125 |
{"role": "system", "content": "You are a professional translator and rewriter"},
|
| 126 |
{"role": "user", "content": "Please translate and rewrite this sentence into Indonesian language with the following requirements: \n1. The sentence should be concise, compact, and clear. \n2. The sentence length should not exceed 50 characters. \n3. The sentences should be professional, similar to typical article titles and sound more natural for a human to read.:" +title+"\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: Judul:{hasil rewrite}"}
|
|
|
|
| 140 |
|
| 141 |
return title, judul, link, contents
|
| 142 |
|
| 143 |
+
def scrap_artikel(link_scrap, models):
|
| 144 |
options = webdriver.ChromeOptions()
|
| 145 |
options.add_argument('--headless')
|
| 146 |
options.add_argument('--no-sandbox')
|
|
|
|
| 172 |
artikels = [part1, part2, part3, part4]
|
| 173 |
else :
|
| 174 |
artikels = [paragraf]
|
| 175 |
+
title, judul, url, contents = clean_scrap(artikels,link_scrap, models)
|
| 176 |
return title, judul, url, contents
|
| 177 |
|
| 178 |
+
def artikel_processing(link_scrap,backlink,keyword, models):
|
| 179 |
+
title, judul, url, artikel= scrap_artikel(link_scrap, models)
|
| 180 |
teks_to_tags = artikel[0][:500]
|
| 181 |
translated = []
|
| 182 |
optimized = []
|
|
|
|
| 184 |
article = []
|
| 185 |
post_article = []
|
| 186 |
|
|
|
|
| 187 |
for i in artikel:
|
| 188 |
response = openai.ChatCompletion.create(
|
| 189 |
+
engine=models,
|
| 190 |
messages=[
|
| 191 |
{"role": "system", "content": "You are a proficient English to Indonesian language translator machine. You are capable of translating professionally according to the rules of the Indonesian language"},
|
| 192 |
{"role": "user", "content": "Translate the following article into Indonesian language. Then, you must resume the article translated. The translated result should be more than 2500 characters and less than 7000 characters.: " + i + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {Professionally rewritten content}"}
|
|
|
|
| 201 |
|
| 202 |
for i in translated:
|
| 203 |
response = openai.ChatCompletion.create(
|
| 204 |
+
engine=models,
|
| 205 |
messages=[
|
| 206 |
{"role": "system", "content": f"""You are a very professional article editor and perform SEO optimization on an article with utmost professionalism. berikut adalah SOP SEO yang harus kamu terapkan
|
| 207 |
1. meta decription max 160 characters
|
|
|
|
| 223 |
|
| 224 |
for i in optimized:
|
| 225 |
response = openai.ChatCompletion.create(
|
| 226 |
+
engine=models,
|
| 227 |
messages=[
|
| 228 |
{"role": "system", "content": f"""
|
| 229 |
You are a professional article writer and editor. I have an article that needs your editing expertise to align its writing style with specific instructions and guidelines:
|
|
|
|
| 259 |
|
| 260 |
for i in article:
|
| 261 |
response = openai.ChatCompletion.create(
|
| 262 |
+
engine=models,
|
| 263 |
messages=[
|
| 264 |
{"role": "system", "content": "You are a professional article editor machine."},
|
| 265 |
{"role": "user", "content": "Please rewrite the given article in the style of a professional writer for Forbes or The New York Times with bahasa indonesia as your native language:\n\n" + i + "\nAdd underline tags <u> and bold tags <b> to all foreign terms (non-Indonesian words) you encounter. You only have less than 7 attempts to do this, no more than that in order to keep the article neat and clean. \nThen, You must divide the article into several paragraphs, no less than 3 paragraphs. kamu juga harus membuat subheading menggunakan <h2> pada setiap sub topik pembahasan \n\nPlease ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries. Provide only the reformatted article using this format:<h2>A brief headline of the article content</h2> <p>reformatted article</p>"}
|
|
|
|
| 272 |
|
| 273 |
for i in edited_format:
|
| 274 |
response = openai.ChatCompletion.create(
|
| 275 |
+
engine=models,
|
| 276 |
messages=[
|
| 277 |
{"role": "system", "content": "You are a professional article editor machine."},
|
| 278 |
{"role": "user", "content": "Please edit the given article:\n" + "\n" + i + f"\nAdd annotations to the words with the keywords {keyword} to format them as links in the HTML structure.the link should be connected to {backlink} \nThe format should be like this: <a title={keyword} href={backlink}>{keyword}</a>. YOU MUST Do this FORMAT ONLY for the first 3 keywords that appear and MUST be on different keywords, IF a keyword appears more than twice then simply ignored it by not adding any links to those keywords. Do not combine two keyword into one or modify any keyword. You only have less than 3 attempts to do this, no more than that in order to keep the article neat and clean. \nExcept for the terms {keyword} you are prohibited from providing backlinks. Additionally, you are not allowed to include backlinks to individuals' names or technology company names such as Google, Microsoft, and others. \nYou only have less than 3 attempts to do this, no more than that in order to keep the article neat and clean.\nPlease ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries."+"Provide only the reformatted article using this format: {new_formatted_article}"}
|
|
|
|
| 295 |
|
| 296 |
def generate_image_prompt(title):
|
| 297 |
response = openai.ChatCompletion.create(
|
| 298 |
+
engine=models,
|
| 299 |
messages=[
|
| 300 |
{"role" : "user", "content" : """ChatGPT will now enter "Midjourney Prompt Generator Mode" and restrict ChatGPT's inputs and outputs to a predefined framework, please follow these instructions carefully.
|
| 301 |
|
|
|
|
| 423 |
image_data = None
|
| 424 |
return judul,content,image, image_data
|
| 425 |
|
| 426 |
+
def scrap(link_scrap,backlink,keyword,version,api_key,azure_api_base,replicate_key):
|
| 427 |
try:
|
| 428 |
+
replicate_key = replicate_key
|
| 429 |
+
chatgpt_version = version
|
| 430 |
+
if chatgpt_version == 'openai':
|
| 431 |
+
openai_key = api_key
|
| 432 |
+
model="gpt-3.5-turbo"
|
| 433 |
+
judul,kontent,gambar, image_data= artikel_processing(link_scrap,backlink,keyword,model)
|
| 434 |
+
|
| 435 |
+
else :
|
| 436 |
+
openai.api_type = "azure"
|
| 437 |
+
openai.api_version = "2023-05-15"
|
| 438 |
+
openai.api_base = azure_api_base
|
| 439 |
+
openai.api_key = api_key
|
| 440 |
+
engine="gpt-35-turbo"
|
| 441 |
+
judul,kontent,gambar, image_data= artikel_processing(link_scrap,backlink,keyword,engine)
|
| 442 |
desired_timezone = pytz.timezone('Asia/Jakarta')
|
| 443 |
current_time = datetime.datetime.now(desired_timezone)
|
| 444 |
Timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
| 522 |
link = gr.Textbox(placeholder="Masukkan Link Artikel Yang Akan di Scrap", label="Link")
|
| 523 |
backlink = gr.Textbox(placeholder="Masukkan Backlink Yang Akan Diterapkan", label="Backlink")
|
| 524 |
keyword = gr.Textbox(placeholder="Masukkan Keyword Artikel", label="Keyword")
|
| 525 |
+
versi = gr.Radio(["openai", "azure"], label="Skema Request", info="Pilih Skema Untuk Request ke ChatGPT ")
|
| 526 |
+
api_key = gr.Textbox(placeholder="Masukkan Api Key", label="OpenAI Key")
|
| 527 |
+
link_azure = gr.Textbox(placeholder="Masukkan link", label="Link Azure")
|
| 528 |
replicate_token = gr.Textbox(placeholder="Masukkan Token Replicate", label="Replicate Key")
|
| 529 |
button_scrap = gr.Button("Scrap Article")
|
| 530 |
img = gr.Image()
|
| 531 |
outputs = gr.Textbox("", label="Judul")
|
| 532 |
content = gr.Textbox("", label="Content")
|
| 533 |
+
button_scrap.click(fn=scrap, inputs=[link,backlink,keyword,versi,api_key,link_azure,replicate_token], outputs=[img,outputs,content])
|
| 534 |
with gr.Column():
|
| 535 |
endpoint= gr.Textbox(placeholder="Masukkan Endpoint Wordpress", label="Endpoint Wordpress")
|
| 536 |
endpoint_media= gr.Textbox(placeholder="Masukkan Endpoint Media Wordpress", label="Endpoint Media")
|