Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -424,56 +424,56 @@ def artikel_processing(link_scrap,backlink,keyword, models):
|
|
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 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
except:
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
|
478 |
def post(judul, kontent, endpoint,endpoint_media,username,password,tags,categories,metode):
|
479 |
credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
|
|
|
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')
|
445 |
+
|
446 |
+
with open('log_activity.txt', 'r') as file:
|
447 |
+
existing_data = file.read()
|
448 |
+
|
449 |
+
log = 'Generated_Title:' + judul + '\nTimestamp:' + Timestamp + '\n\n'
|
450 |
+
|
451 |
+
combined_data = existing_data + log
|
452 |
+
|
453 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
|
454 |
+
temp_file.write(combined_data)
|
455 |
+
|
456 |
+
repo_name = get_full_repo_name(model_id="Article_Gen2", token="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")
|
457 |
+
file_url = upload_file(
|
458 |
+
path_or_fileobj=temp_file.name, # Use the temporary file name
|
459 |
+
path_in_repo="log_activity.txt",
|
460 |
+
repo_id=repo_name,
|
461 |
+
repo_type="space",
|
462 |
+
token="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",
|
463 |
+
)
|
464 |
+
file_url = upload_file(
|
465 |
+
path_or_fileobj=image_data,
|
466 |
+
path_in_repo="image_data.txt",
|
467 |
+
repo_id=repo_name,
|
468 |
+
repo_type="space",
|
469 |
+
token="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",
|
470 |
+
)
|
471 |
+
return gambar,judul,kontent
|
472 |
+
# except:
|
473 |
+
# gambar = Image.open('error.png')
|
474 |
+
# judul = 'Gagal Generate Judul:Request Time Out'
|
475 |
+
# kontent = 'Gagal Generate Artikel:Request Time Out'
|
476 |
+
# return gambar,judul,kontent
|
477 |
|
478 |
def post(judul, kontent, endpoint,endpoint_media,username,password,tags,categories,metode):
|
479 |
credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
|