Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -449,65 +449,65 @@ 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 |
|
| 512 |
def post(endpoint,endpoint_media,username,password,tags,categories,metode):
|
| 513 |
credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
|
|
@@ -549,6 +549,20 @@ def post(endpoint,endpoint_media,username,password,tags,categories,metode):
|
|
| 549 |
response_post = requests.post(endpoint, headers=headers, data=data)
|
| 550 |
return response_post.json()
|
| 551 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
|
| 553 |
def save(title,content):
|
| 554 |
with open("judul.txt", "w") as file:
|
|
@@ -604,11 +618,14 @@ with gr.Blocks(theme = "soft", title="Wordpress Article Generator") as article_g
|
|
| 604 |
link_azure = gr.Textbox(placeholder="Khusus Untuk Skema Request Menggunakan Azure",type="password", label="Azure Endpoint (Opsional)")
|
| 605 |
replicate_token = gr.Textbox(placeholder="Masukkan Token Replicate", type="password",label="Replicate Key")
|
| 606 |
button_scrap = gr.Button("Scrap Article")
|
|
|
|
|
|
|
|
|
|
| 607 |
with gr.Tab("Raw Output"):
|
| 608 |
title = gr.Textbox("", label="Judul", interactive=True)
|
| 609 |
img = gr.Image(height=300, width=500)
|
| 610 |
content = gr.Textbox("", label="Konten", interactive=True)
|
| 611 |
-
|
| 612 |
save_button= gr.Button("Save Change")
|
| 613 |
status = gr.HTML("")
|
| 614 |
save_button.click(fn=save, inputs =[title,content], outputs = status)
|
|
@@ -616,10 +633,9 @@ with gr.Blocks(theme = "soft", title="Wordpress Article Generator") as article_g
|
|
| 616 |
title = gr.HTML("")
|
| 617 |
img = gr.Image()
|
| 618 |
content = gr.HTML("")
|
| 619 |
-
|
| 620 |
view_change = gr.Button("View Change")
|
| 621 |
view_change.click(fn=view, outputs=[title,content])
|
| 622 |
-
# button_scrap.click(fn=scrap, inputs=[link,backlink,keyword,versi,api_key,link_azure,replicate_token], outputs=[title,img,content])
|
| 623 |
with gr.Column():
|
| 624 |
endpoint= gr.Textbox(placeholder="Masukkan Endpoint Wordpress", label="Endpoint Wordpress")
|
| 625 |
endpoint_media= gr.Textbox(placeholder="Masukkan Endpoint Media Wordpress", label="Endpoint Media")
|
|
|
|
| 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 = "<h3>Berhasil Generate Artikel</h3>"
|
| 506 |
+
return status
|
| 507 |
+
except:
|
| 508 |
+
status = "<h3>Gagal Generate Artikel</h3>"
|
| 509 |
+
return status
|
| 510 |
+
|
| 511 |
|
| 512 |
def post(endpoint,endpoint_media,username,password,tags,categories,metode):
|
| 513 |
credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
|
|
|
|
| 549 |
response_post = requests.post(endpoint, headers=headers, data=data)
|
| 550 |
return response_post.json()
|
| 551 |
|
| 552 |
+
def view_output():
|
| 553 |
+
try:
|
| 554 |
+
with open('judul.txt', 'r') as file:
|
| 555 |
+
judul = file.read()
|
| 556 |
+
title = '<h1>'+judul+'</h1>'
|
| 557 |
+
with open('kontent.txt', 'r') as file:
|
| 558 |
+
kontent = file.read()
|
| 559 |
+
image = Image.open('output_image.png')
|
| 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 |
def save(title,content):
|
| 568 |
with open("judul.txt", "w") as file:
|
|
|
|
| 618 |
link_azure = gr.Textbox(placeholder="Khusus Untuk Skema Request Menggunakan Azure",type="password", label="Azure Endpoint (Opsional)")
|
| 619 |
replicate_token = gr.Textbox(placeholder="Masukkan Token Replicate", type="password",label="Replicate Key")
|
| 620 |
button_scrap = gr.Button("Scrap Article")
|
| 621 |
+
status = gr.HTML("")
|
| 622 |
+
button_scrap.click(fn=scrap, inputs=[link,backlink,keyword,versi,api_key,link_azure,replicate_token], outputs= status)
|
| 623 |
+
view_outputs = gr.Button("View Output")
|
| 624 |
with gr.Tab("Raw Output"):
|
| 625 |
title = gr.Textbox("", label="Judul", interactive=True)
|
| 626 |
img = gr.Image(height=300, width=500)
|
| 627 |
content = gr.Textbox("", label="Konten", interactive=True)
|
| 628 |
+
view_outputs.click(fn=view_output, outputs=[title,img,content])
|
| 629 |
save_button= gr.Button("Save Change")
|
| 630 |
status = gr.HTML("")
|
| 631 |
save_button.click(fn=save, inputs =[title,content], outputs = status)
|
|
|
|
| 633 |
title = gr.HTML("")
|
| 634 |
img = gr.Image()
|
| 635 |
content = gr.HTML("")
|
| 636 |
+
view_outputs.click(fn=view_output, outputs=[title,img,content])
|
| 637 |
view_change = gr.Button("View Change")
|
| 638 |
view_change.click(fn=view, outputs=[title,content])
|
|
|
|
| 639 |
with gr.Column():
|
| 640 |
endpoint= gr.Textbox(placeholder="Masukkan Endpoint Wordpress", label="Endpoint Wordpress")
|
| 641 |
endpoint_media= gr.Textbox(placeholder="Masukkan Endpoint Media Wordpress", label="Endpoint Media")
|