Dede16 commited on
Commit
de6210b
·
1 Parent(s): 4290162

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -46
app.py CHANGED
@@ -202,7 +202,28 @@ def clean_scrap(artikel,link,models,api_key,azure_api_base,keyword):
202
  contents = content[1:]
203
  contents = [' '.join(contents).replace("article:", '').replace("Article:", '').strip()]
204
 
205
- return title, judul, link, contents
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
 
207
  def scrap_artikel(source_type,source,models,api_key,azure_api_base,keyword):
208
  options = webdriver.ChromeOptions()
@@ -517,17 +538,7 @@ def scrap(source_type,source,backlink,keyword,version,api_key,azure_api_base,rep
517
  desired_timezone = pytz.timezone('Asia/Jakarta')
518
  current_time = datetime.datetime.now(desired_timezone)
519
  Timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S')
520
-
521
- with open('log_activity.txt', 'r') as file:
522
- existing_data = file.read()
523
-
524
- log = url + "\n"
525
-
526
- combined_data = existing_data + log
527
-
528
- with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
529
- temp_file.write(combined_data)
530
-
531
  with open("judul.txt", "w") as file:
532
  file.write(judul)
533
 
@@ -535,14 +546,6 @@ def scrap(source_type,source,backlink,keyword,version,api_key,azure_api_base,rep
535
  file.write(kontent)
536
 
537
  repo_name = get_full_repo_name(model_id="Article_Gen4", token="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")
538
- file_url = upload_file(
539
- path_or_fileobj=temp_file.name,
540
- path_in_repo="log_activity.txt",
541
- repo_id=repo_name,
542
- repo_type="space",
543
- token="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",
544
- )
545
-
546
  file_url = upload_file(
547
  path_or_fileobj=image_data,
548
  path_in_repo="image_data.txt",
@@ -565,19 +568,17 @@ def scrap(source_type,source,backlink,keyword,version,api_key,azure_api_base,rep
565
  token="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",
566
  )
567
  if kontent:
568
- status = "<h3>Berhasil Generate Artikel</h3>"
569
- time.sleep(60)
570
- return status,gambar
571
- else:
572
  with open('log_activity.txt', 'r') as file:
573
  existing_data = file.read()
574
-
575
- log = source + "\n"
 
576
  combined_data = existing_data + log
577
-
578
  with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
579
  temp_file.write(combined_data)
580
-
 
581
  repo_name = get_full_repo_name(model_id="Article_Gen4", token="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")
582
  file_url = upload_file(
583
  path_or_fileobj=temp_file.name,
@@ -586,28 +587,14 @@ def scrap(source_type,source,backlink,keyword,version,api_key,azure_api_base,rep
586
  repo_type="space",
587
  token="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",
588
  )
 
 
 
 
589
  status = "<h3>Gagal Generate Artikel, Coba Generate Ulang atau Ganti Input Source</h3>"
590
  gambar = Image.open("error.png")
591
  return status,gambar
592
  except:
593
- with open('log_activity.txt', 'r') as file:
594
- existing_data = file.read()
595
-
596
- log = source + "\n"
597
- combined_data = existing_data + log
598
-
599
- with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
600
- temp_file.write(combined_data)
601
-
602
- repo_name = get_full_repo_name(model_id="Article_Gen4", token="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")
603
- file_url = upload_file(
604
- path_or_fileobj=temp_file.name,
605
- path_in_repo="log_activity.txt",
606
- repo_id=repo_name,
607
- repo_type="space",
608
- token="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",
609
- )
610
-
611
  status = "<h3>Gagal Generate Artikel</h3>"
612
  gambar = Image.open('error.png')
613
  return status,gambar
 
202
  contents = content[1:]
203
  contents = [' '.join(contents).replace("article:", '').replace("Article:", '').strip()]
204
 
205
+ if len(contents)>=2500:
206
+ return title, judul, link, contents
207
+ else:
208
+ with open('log_activity.txt', 'r') as file:
209
+ existing_data = file.read()
210
+
211
+ log = link + "\n"
212
+
213
+ combined_data = existing_data + log
214
+
215
+ with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
216
+ temp_file.write(combined_data)
217
+
218
+ repo_name = get_full_repo_name(model_id="Article_Gen4", token="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")
219
+ file_url = upload_file(
220
+ path_or_fileobj=temp_file.name,
221
+ path_in_repo="log_activity.txt",
222
+ repo_id=repo_name,
223
+ repo_type="space",
224
+ token="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",
225
+ )
226
+ return None,None,None,None
227
 
228
  def scrap_artikel(source_type,source,models,api_key,azure_api_base,keyword):
229
  options = webdriver.ChromeOptions()
 
538
  desired_timezone = pytz.timezone('Asia/Jakarta')
539
  current_time = datetime.datetime.now(desired_timezone)
540
  Timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S')
541
+
 
 
 
 
 
 
 
 
 
 
542
  with open("judul.txt", "w") as file:
543
  file.write(judul)
544
 
 
546
  file.write(kontent)
547
 
548
  repo_name = get_full_repo_name(model_id="Article_Gen4", token="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")
 
 
 
 
 
 
 
 
549
  file_url = upload_file(
550
  path_or_fileobj=image_data,
551
  path_in_repo="image_data.txt",
 
568
  token="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",
569
  )
570
  if kontent:
 
 
 
 
571
  with open('log_activity.txt', 'r') as file:
572
  existing_data = file.read()
573
+
574
+ log = url + "\n"
575
+
576
  combined_data = existing_data + log
577
+
578
  with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
579
  temp_file.write(combined_data)
580
+
581
+
582
  repo_name = get_full_repo_name(model_id="Article_Gen4", token="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")
583
  file_url = upload_file(
584
  path_or_fileobj=temp_file.name,
 
587
  repo_type="space",
588
  token="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",
589
  )
590
+ status = "<h3>Berhasil Generate Artikel</h3>"
591
+ time.sleep(60)
592
+ return status,gambar
593
+ else:
594
  status = "<h3>Gagal Generate Artikel, Coba Generate Ulang atau Ganti Input Source</h3>"
595
  gambar = Image.open("error.png")
596
  return status,gambar
597
  except:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  status = "<h3>Gagal Generate Artikel</h3>"
599
  gambar = Image.open('error.png')
600
  return status,gambar