Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -449,64 +449,64 @@ def artikel_processing(link_scrap,backlink,keyword,models,api_key,azure_api_base
|
|
449 |
return judul,content,image,image_data
|
450 |
|
451 |
def scrap(link_scrap,backlink,keyword,version,api_key,azure_api_base,replicate_key):
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
|
511 |
def post(endpoint,endpoint_media,username,password,tags,categories,metode):
|
512 |
credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
|
@@ -549,14 +549,20 @@ def post(endpoint,endpoint_media,username,password,tags,categories,metode):
|
|
549 |
return response_post.json()
|
550 |
|
551 |
def view_outputs():
|
552 |
-
|
553 |
-
judul
|
554 |
-
|
555 |
-
|
556 |
-
kontent
|
557 |
-
|
558 |
-
|
559 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
560 |
|
561 |
|
562 |
with gr.Blocks(theme = "soft", title="Wordpress Article Generator") as article_generator:
|
@@ -574,9 +580,9 @@ with gr.Blocks(theme = "soft", title="Wordpress Article Generator") as article_g
|
|
574 |
backlink = gr.Textbox(placeholder="Masukkan Backlink Yang Akan Diterapkan", label="Backlink")
|
575 |
keyword = gr.Textbox(placeholder="Masukkan Keyword Artikel", label="Keyword")
|
576 |
versi = gr.Radio(["openai", "azure"], label="Skema Request", info="Pilih Skema Untuk Request ke ChatGPT ")
|
577 |
-
api_key = gr.Textbox(placeholder="Masukkan Api Key", label="API Key")
|
578 |
-
link_azure = gr.Textbox(placeholder="Khusus Untuk Skema Request Menggunakan Azure", label="Azure Endpoint (Opsional)")
|
579 |
-
replicate_token = gr.Textbox(placeholder="Masukkan Token Replicate", label="Replicate Key")
|
580 |
button_scrap = gr.Button("Scrap Article")
|
581 |
status = gr.Textbox("", label="Generate Status")
|
582 |
button_scrap.click(fn=scrap, inputs=[link,backlink,keyword,versi,api_key,link_azure,replicate_token], outputs=status)
|
@@ -594,8 +600,8 @@ with gr.Blocks(theme = "soft", title="Wordpress Article Generator") as article_g
|
|
594 |
with gr.Column():
|
595 |
endpoint= gr.Textbox(placeholder="Masukkan Endpoint Wordpress", label="Endpoint Wordpress")
|
596 |
endpoint_media= gr.Textbox(placeholder="Masukkan Endpoint Media Wordpress", label="Endpoint Media")
|
597 |
-
username= gr.Textbox(placeholder="Masukkan Username Wordpress",
|
598 |
-
password= gr.Textbox(placeholder="Masukkan Password Wordpress", label="Password")
|
599 |
tags= gr.Textbox(placeholder="Masukkan ID Tags Yang Akan Diterapkan", label="Tags")
|
600 |
categories= gr.Textbox(placeholder="Masukkan ID Kategori Artikel", label="Kategori")
|
601 |
metode= gr.Radio(["publish", "draft"], label="Status Post", info="Pilih Metode Publish atau Draft Untuk Memposting")
|
|
|
449 |
return judul,content,image,image_data
|
450 |
|
451 |
def scrap(link_scrap,backlink,keyword,version,api_key,azure_api_base,replicate_key):
|
452 |
+
try:
|
453 |
+
judul,kontent,gambar, image_data= artikel_processing(link_scrap,backlink,keyword,version,api_key,azure_api_base,replicate_key)
|
454 |
+
title = '<h1>'+judul+'</h1>'
|
455 |
+
desired_timezone = pytz.timezone('Asia/Jakarta')
|
456 |
+
current_time = datetime.datetime.now(desired_timezone)
|
457 |
+
Timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S')
|
458 |
+
|
459 |
+
with open('log_activity.txt', 'r') as file:
|
460 |
+
existing_data = file.read()
|
461 |
+
|
462 |
+
log = 'Generated_Title:' + judul + '\nTimestamp:' + Timestamp + '\nLink:' + link_scrap + "\n\n"
|
463 |
+
|
464 |
+
combined_data = existing_data + log
|
465 |
+
|
466 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
|
467 |
+
temp_file.write(combined_data)
|
468 |
+
|
469 |
+
with open("judul.txt", "w") as file:
|
470 |
+
file.write(judul)
|
471 |
+
|
472 |
+
with open("kontent.txt", "w") as file:
|
473 |
+
file.write(kontent)
|
474 |
+
|
475 |
+
repo_name = get_full_repo_name(model_id="Article_Gen3", token="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")
|
476 |
+
file_url = upload_file(
|
477 |
+
path_or_fileobj=temp_file.name, # Use the temporary file name
|
478 |
+
path_in_repo="log_activity.txt",
|
479 |
+
repo_id=repo_name,
|
480 |
+
repo_type="space",
|
481 |
+
token="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",
|
482 |
+
)
|
483 |
+
file_url = upload_file(
|
484 |
+
path_or_fileobj=image_data,
|
485 |
+
path_in_repo="image_data.txt",
|
486 |
+
repo_id=repo_name,
|
487 |
+
repo_type="space",
|
488 |
+
token="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",
|
489 |
+
)
|
490 |
+
file_url = upload_file(
|
491 |
+
path_or_fileobj='judul.txt',
|
492 |
+
path_in_repo="judul.txt",
|
493 |
+
repo_id=repo_name,
|
494 |
+
repo_type="space",
|
495 |
+
token="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",
|
496 |
+
)
|
497 |
+
file_url = upload_file(
|
498 |
+
path_or_fileobj='kontent.txt',
|
499 |
+
path_in_repo="kontent.txt",
|
500 |
+
repo_id=repo_name,
|
501 |
+
repo_type="space",
|
502 |
+
token="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",
|
503 |
+
)
|
504 |
+
if kontent:
|
505 |
+
status = "Berhasil Generate Artikel"
|
506 |
+
return status
|
507 |
+
except:
|
508 |
+
status = "Gagal Generate Artikel"
|
509 |
+
return status
|
510 |
|
511 |
def post(endpoint,endpoint_media,username,password,tags,categories,metode):
|
512 |
credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
|
|
|
549 |
return response_post.json()
|
550 |
|
551 |
def view_outputs():
|
552 |
+
try:
|
553 |
+
with open('judul.txt', 'r') as file:
|
554 |
+
judul = file.read()
|
555 |
+
title = '<h1>'+judul+'</h1>'
|
556 |
+
with open('kontent.txt', 'r') as file:
|
557 |
+
kontent = file.read()
|
558 |
+
image = Image.open('output_image.png')
|
559 |
+
|
560 |
+
return title,image,kontent
|
561 |
+
except:
|
562 |
+
title = 'Gagal Generate Judul'
|
563 |
+
kontent = 'Gagal Generate Konten'
|
564 |
+
image = Image.open('error.png')
|
565 |
+
return title,image,kontent
|
566 |
|
567 |
|
568 |
with gr.Blocks(theme = "soft", title="Wordpress Article Generator") as article_generator:
|
|
|
580 |
backlink = gr.Textbox(placeholder="Masukkan Backlink Yang Akan Diterapkan", label="Backlink")
|
581 |
keyword = gr.Textbox(placeholder="Masukkan Keyword Artikel", label="Keyword")
|
582 |
versi = gr.Radio(["openai", "azure"], label="Skema Request", info="Pilih Skema Untuk Request ke ChatGPT ")
|
583 |
+
api_key = gr.Textbox(placeholder="Masukkan Api Key", type="password",label="API Key")
|
584 |
+
link_azure = gr.Textbox(placeholder="Khusus Untuk Skema Request Menggunakan Azure",type="password", label="Azure Endpoint (Opsional)")
|
585 |
+
replicate_token = gr.Textbox(placeholder="Masukkan Token Replicate", type="password",label="Replicate Key")
|
586 |
button_scrap = gr.Button("Scrap Article")
|
587 |
status = gr.Textbox("", label="Generate Status")
|
588 |
button_scrap.click(fn=scrap, inputs=[link,backlink,keyword,versi,api_key,link_azure,replicate_token], outputs=status)
|
|
|
600 |
with gr.Column():
|
601 |
endpoint= gr.Textbox(placeholder="Masukkan Endpoint Wordpress", label="Endpoint Wordpress")
|
602 |
endpoint_media= gr.Textbox(placeholder="Masukkan Endpoint Media Wordpress", label="Endpoint Media")
|
603 |
+
username= gr.Textbox(placeholder="Masukkan Username Wordpress",label="Username")
|
604 |
+
password= gr.Textbox(placeholder="Masukkan Password Wordpress",type="password" ,label="Password")
|
605 |
tags= gr.Textbox(placeholder="Masukkan ID Tags Yang Akan Diterapkan", label="Tags")
|
606 |
categories= gr.Textbox(placeholder="Masukkan ID Kategori Artikel", label="Kategori")
|
607 |
metode= gr.Radio(["publish", "draft"], label="Status Post", info="Pilih Metode Publish atau Draft Untuk Memposting")
|