thomson99 commited on
Commit
f71ad91
ยท
verified ยท
1 Parent(s): 66b4ae9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +224 -29
app.py CHANGED
@@ -351,12 +351,116 @@ def generate_faq(topic, style):
351
  })
352
  return faq
353
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  def generate_article(topic, article_type):
355
  template = get_article_template(article_type)
356
  structure = template["structure"]
357
  style = template["style"]
358
  transitions = template["transitions"]
359
-
 
360
  article = {
361
  "title": generate_title(topic, style),
362
  "introduction": generate_introduction(topic, style, transitions),
@@ -364,12 +468,17 @@ def generate_article(topic, article_type):
364
  "conclusion": generate_conclusion(topic, style),
365
  "faq": generate_faq(topic, style)
366
  }
367
- return article
 
 
 
 
 
 
 
368
 
369
  def format_article(article):
370
- """
371
- ุชู†ุณูŠู‚ ุงู„ู…ู‚ุงู„ ุจุดูƒู„ ู…ู†ุธู… ูˆู…ุฑุชุจ
372
- """
373
  formatted_text = f"""# {article['title']}
374
 
375
  ## ู…ู‚ุฏู…ุฉ
@@ -384,7 +493,6 @@ def format_article(article):
384
  """
385
 
386
  formatted_text += """## ุงู„ุฃุณุฆู„ุฉ ุงู„ุดุงุฆุนุฉ
387
-
388
  """
389
 
390
  for qa in article['faq']:
@@ -396,42 +504,129 @@ def format_article(article):
396
  formatted_text += f"""## ุงู„ุฎุงุชู…ุฉ
397
  {article['conclusion']}"""
398
 
399
- # ุงู„ุชุญู‚ู‚ ู…ู† ุนุฏุฏ ุงู„ูƒู„ู…ุงุช
400
- word_count = count_words(formatted_text)
401
- if word_count < 1000:
402
- print(f"ุชุญุฐูŠุฑ: ุงู„ู…ู‚ุงู„ ูŠุญุชูˆูŠ ุนู„ู‰ {word_count} ูƒู„ู…ุฉ ูู‚ุทุŒ ูˆู‡ูˆ ุฃู‚ู„ ู…ู† ุงู„ุญุฏ ุงู„ุฃุฏู†ู‰ ุงู„ู…ุทู„ูˆุจ (1000 ูƒู„ู…ุฉ)")
403
-
404
- # ุงุณุชุฎุฑุงุฌ ุงู„ูƒู„ู…ุงุช ุงู„ู…ูุชุงุญูŠุฉ
405
- keywords = get_keywords(formatted_text)
406
- formatted_text += f"""\n\n## ุงู„ูƒู„ู…ุงุช ุงู„ู…ูุชุงุญูŠุฉ
407
- {', '.join(keywords)}"""
408
-
409
  return formatted_text
410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  # ุฅู†ุดุงุก ูˆุงุฌู‡ุฉ ุงู„ู…ุณุชุฎุฏู…
412
  with gr.Blocks(title="ู…ุณุงุนุฏ ูƒุชุงุจุฉ ุงู„ู…ู‚ุงู„ุงุช ุงู„ุนุฑุจูŠุฉ") as demo:
413
  gr.Markdown("# ๐Ÿ“ ู…ุณุงุนุฏ ูƒุชุงุจุฉ ุงู„ู…ู‚ุงู„ุงุช ุงู„ุนุฑุจูŠุฉ")
414
  gr.Markdown("### ู…ู†ุตุฉ ุฐูƒูŠุฉ ู„ุฅู†ุดุงุก ูˆุชุญุณูŠู† ุงู„ู…ู‚ุงู„ุงุช ุงู„ุนุฑุจูŠุฉ")
415
 
416
  with gr.Tab("ุฅู†ุดุงุก ู…ู‚ุงู„ ุงุญุชุฑุงููŠ"):
417
- topic_input = gr.Textbox(label="ู…ูˆุถูˆุน ุงู„ู…ู‚ุงู„")
418
- article_type = gr.Dropdown(
419
- choices=["ุนู„ู…ูŠ", "ุตุญููŠ", "ุชู‚ู†ูŠ", "ุชุนู„ูŠู…ูŠ", "ุชุณูˆูŠู‚ูŠ", "ุงุฌุชู…ุงุนูŠ", "ุฑุฃูŠ", "ุซู‚ุงููŠ"],
420
- label="ู†ูˆุน ุงู„ู…ู‚ุงู„",
421
- value="ุนู„ู…ูŠ"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
  )
423
- generate_btn = gr.Button("ุฅู†ุดุงุก ุงู„ู…ู‚ุงู„")
424
- output = gr.Textbox(label="ุงู„ู…ู‚ุงู„ ุงู„ู…ูู†ุดุฃ", lines=30)
425
 
426
- def generate_and_format(topic, article_type):
427
- article = generate_article(topic, article_type)
428
- formatted_article = format_article(article)
429
- return formatted_article
 
 
 
 
430
 
431
  generate_btn.click(
432
- generate_and_format,
433
  inputs=[topic_input, article_type],
434
- outputs=output
 
 
 
 
 
 
 
 
 
 
435
  )
436
 
437
  demo.launch()
 
351
  })
352
  return faq
353
 
354
+ def get_random_variations():
355
+ """ุชูˆู„ูŠุฏ ุชู†ูˆูŠุนุงุช ุนุดูˆุงุฆูŠุฉ ู„ู„ู…ุญุชูˆู‰"""
356
+ variations = {
357
+ "ูู‚ุฑุงุช_ุงูุชุชุงุญูŠุฉ": [
358
+ "ููŠ ุนุตุฑ ูŠุชุณู… ุจุงู„ุชุทูˆุฑ ุงู„ู…ุชุณุงุฑุน",
359
+ "ููŠ ุธู„ ุงู„ุชุญูˆู„ุงุช ุงู„ุนู…ูŠู‚ุฉ ุงู„ุชูŠ ูŠุดู‡ุฏู‡ุง ุนุงู„ู…ู†ุง",
360
+ "ู…ุน ุชุฒุงูŠุฏ ุงู„ุงู‡ุชู…ุงู… ุงู„ุนุงู„ู…ูŠ",
361
+ "ููŠ ุฎุถู… ุงู„ุชุบูŠุฑุงุช ุงู„ู…ุชุณุงุฑุนุฉ",
362
+ "ููŠ ุฅุทุงุฑ ุงู„ุณุนูŠ ุงู„ู…ุชูˆุงุตู„ ู†ุญูˆ ุงู„ุชุทูˆูŠุฑ"
363
+ ],
364
+ "ุนุจุงุฑุงุช_ุฑุจุท": [
365
+ "ูˆููŠ ู‡ุฐุง ุงู„ุณูŠุงู‚",
366
+ "ูˆู…ู† ู‡ุฐุง ุงู„ู…ู†ุทู„ู‚",
367
+ "ูˆุจู†ุงุกู‹ ุนู„ู‰ ู…ุง ุณุจู‚",
368
+ "ูˆููŠ ุถูˆุก ุฐู„ูƒ",
369
+ "ูˆุชุฃุณูŠุณุงู‹ ุนู„ู‰ ู…ุง ุชู‚ุฏู…"
370
+ ],
371
+ "ุฎูˆุงุชูŠู…": [
372
+ "ูˆููŠ ุงู„ุฎุชุงู…ุŒ ูŠู…ูƒู† ุงู„ู‚ูˆู„",
373
+ "ูˆุฎุชุงู…ุงู‹ุŒ ู†ุฎู„ุต ุฅู„ู‰",
374
+ "ูˆููŠ ู†ู‡ุงูŠุฉ ุงู„ู…ุทุงู",
375
+ "ูˆุจู†ุงุกู‹ ุนู„ู‰ ู…ุง ุณุจู‚",
376
+ "ูˆููŠ ุถูˆุก ู…ุง ุชู‚ุฏู…"
377
+ ]
378
+ }
379
+ return variations
380
+
381
+ def get_synonyms(word):
382
+ """ู‚ุงู…ูˆุณ ุงู„ู…ุฑุงุฏูุงุช ู„ู„ูƒู„ู…ุงุช ุงู„ุดุงุฆุนุฉ"""
383
+ synonyms = {
384
+ "ู…ู‡ู…": ["ุญูŠูˆูŠ", "ุฃุณุงุณูŠ", "ุฌูˆู‡ุฑูŠ", "ู…ุญูˆุฑูŠ", "ุฑุฆูŠุณูŠ"],
385
+ "ุชุทูˆุฑ": ["ุชู‚ุฏู…", "ู†ู…ูˆ", "ุงุฑุชู‚ุงุก", "ุชุญุณู†", "ุงุฒุฏู‡ุงุฑ"],
386
+ "ุชุฃุซูŠุฑ": ["ุฃุซุฑ", "ู…ูุนูˆู„", "ู†ุชูŠุฌุฉ", "ุงู†ุนูƒุงุณ", "ุชุฏุงุนูŠุงุช"],
387
+ "ุฏุฑุงุณุฉ": ["ุจุญุซ", "ุชุญู„ูŠู„", "ุงุณุชู‚ุตุงุก", "ูุญุต", "ุชู…ุญูŠุต"],
388
+ "ุชุญู„ูŠู„": ["ุฏุฑุงุณุฉ", "ุชููƒูŠูƒ", "ุชุดุฑูŠุญ", "ุงุณุชู‚ุฑุงุก", "ุชูุณูŠุฑ"]
389
+ }
390
+ return synonyms.get(word, [word])
391
+
392
+ def enhance_text_variation(text):
393
+ """ุชุญุณูŠู† ุชู†ูˆุน ุงู„ู†ุต ุจุงุณุชุฎุฏุงู… ุงู„ู…ุฑุงุฏูุงุช"""
394
+ words = text.split()
395
+ enhanced_words = []
396
+ for word in words:
397
+ if word in get_synonyms(word) and random.random() > 0.7: # 30% ูุฑุตุฉ ู„ู„ุชุบูŠูŠุฑ
398
+ enhanced_words.append(random.choice(get_synonyms(word)))
399
+ else:
400
+ enhanced_words.append(word)
401
+ return " ".join(enhanced_words)
402
+
403
+ def add_human_touch(text):
404
+ """ุฅุถุงูุฉ ู„ู…ุณุฉ ุจุดุฑูŠุฉ ู„ู„ู†ุต"""
405
+ # ุฅุถุงูุฉ ุชุนุจูŠุฑุงุช ุดุฎุตูŠุฉ
406
+ personal_expressions = [
407
+ "ูˆู…ู† ูˆุฌู‡ุฉ ู†ุธุฑูŠ",
408
+ "ูˆูƒู…ุง ู†ู„ุงุญุธ ููŠ ูˆุงู‚ุนู†ุง",
409
+ "ูˆู…ู† ุฎู„ุงู„ ุชุฌุฑุจุชูŠ",
410
+ "ูˆูƒู…ุง ูŠุชุถุญ ู„ู†ุง",
411
+ "ูˆู…ู† ุงู„ู…ู„ูุช ู„ู„ู†ุธุฑ"
412
+ ]
413
+
414
+ # ุฅุถุงูุฉ ุฃู…ุซู„ุฉ ูˆุงู‚ุนูŠุฉ
415
+ real_examples = [
416
+ "ูุนู„ู‰ ุณุจูŠู„ ุงู„ู…ุซุงู„",
417
+ "ูˆู„ู†ุฃุฎุฐ ู…ุซุงู„ุงู‹ ุนู„ู‰ ุฐู„ูƒ",
418
+ "ูˆุฎูŠุฑ ู…ุซุงู„ ุนู„ู‰ ุฐู„ูƒ",
419
+ "ูˆู…ู† ุงู„ุฃู…ุซู„ุฉ ุงู„ูˆุงู‚ุนูŠุฉ",
420
+ "ูˆูƒู…ุง ู†ุฑู‰ ููŠ ุญูŠุงุชู†ุง ุงู„ูŠูˆู…ูŠุฉ"
421
+ ]
422
+
423
+ paragraphs = text.split("\n\n")
424
+ enhanced_paragraphs = []
425
+
426
+ for i, paragraph in enumerate(paragraphs):
427
+ if random.random() > 0.7: # 30% ูุฑุตุฉ ู„ุฅุถุงูุฉ ุชุนุจูŠุฑ ุดุฎุตูŠ
428
+ paragraph = random.choice(personal_expressions) + "ุŒ " + paragraph
429
+ if random.random() > 0.7: # 30% ูุฑุตุฉ ู„ุฅุถุงูุฉ ู…ุซุงู„
430
+ paragraph += " " + random.choice(real_examples) + "."
431
+ enhanced_paragraphs.append(paragraph)
432
+
433
+ return "\n\n".join(enhanced_paragraphs)
434
+
435
+ def check_grammar_and_style(text):
436
+ """ุชุญุณูŠู† ุงู„ู‚ูˆุงุนุฏ ูˆุงู„ุฃุณู„ูˆุจ"""
437
+ # ุชุตุญูŠุญ ุงู„ุฃุฎุทุงุก ุงู„ุดุงุฆุนุฉ
438
+ common_mistakes = {
439
+ "ุงู„ุฐูŠ": "ุงู„ุฐูŠ",
440
+ "ุงู„ุฐูŠู†": "ุงู„ุฐูŠู†",
441
+ "ุงู„ุชูŠ": "ุงู„ุชูŠ",
442
+ "ุงู„ู„ุฐูŠู†": "ุงู„ู„ุฐูŠู†",
443
+ "ุงู„ู„ุชูŠู†": "ุงู„ู„ุชูŠู†"
444
+ }
445
+
446
+ for mistake, correction in common_mistakes.items():
447
+ text = text.replace(mistake, correction)
448
+
449
+ # ุชุญุณูŠู† ุนู„ุงู…ุงุช ุงู„ุชุฑู‚ูŠู…
450
+ text = text.replace(" ุŒ", "ุŒ")
451
+ text = text.replace(" .", ".")
452
+ text = text.replace(" ุ›", "ุ›")
453
+ text = text.replace(" :", ":")
454
+
455
+ return text
456
+
457
  def generate_article(topic, article_type):
458
  template = get_article_template(article_type)
459
  structure = template["structure"]
460
  style = template["style"]
461
  transitions = template["transitions"]
462
+
463
+ # ุฅู†ุดุงุก ุงู„ู…ู‚ุงู„ ุงู„ุฃุณุงุณูŠ
464
  article = {
465
  "title": generate_title(topic, style),
466
  "introduction": generate_introduction(topic, style, transitions),
 
468
  "conclusion": generate_conclusion(topic, style),
469
  "faq": generate_faq(topic, style)
470
  }
471
+
472
+ # ุชุญุณูŠู† ุงู„ู…ุญุชูˆู‰
473
+ formatted_text = format_article(article)
474
+ enhanced_text = enhance_text_variation(formatted_text)
475
+ humanized_text = add_human_touch(enhanced_text)
476
+ final_text = check_grammar_and_style(humanized_text)
477
+
478
+ return final_text
479
 
480
  def format_article(article):
481
+ """ุชู†ุณูŠู‚ ุงู„ู…ู‚ุงู„ ุจุดูƒู„ ุฌู…ูŠู„"""
 
 
482
  formatted_text = f"""# {article['title']}
483
 
484
  ## ู…ู‚ุฏู…ุฉ
 
493
  """
494
 
495
  formatted_text += """## ุงู„ุฃุณุฆู„ุฉ ุงู„ุดุงุฆุนุฉ
 
496
  """
497
 
498
  for qa in article['faq']:
 
504
  formatted_text += f"""## ุงู„ุฎุงุชู…ุฉ
505
  {article['conclusion']}"""
506
 
 
 
 
 
 
 
 
 
 
 
507
  return formatted_text
508
 
509
+ def generate_faq(topic, style):
510
+ if style == "ุฃูƒุงุฏูŠู…ูŠ ุฑุณู…ูŠ":
511
+ questions = [
512
+ f"ู…ุง ู‡ูŠ ุงู„ุฃุณุณ ุงู„ู†ุธุฑูŠุฉ ุงู„ุชูŠ ูŠู‚ูˆู… ุนู„ูŠู‡ุง {topic}ุŸ",
513
+ f"ูƒูŠู ูŠู…ูƒู† ุชุทูˆูŠุฑ ู…ู†ู‡ุฌูŠุฉ ุงู„ุจุญุซ ููŠ ู…ุฌุงู„ {topic}ุŸ",
514
+ f"ู…ุง ู‡ูŠ ุฃุจุฑุฒ ุงู„ุชุญุฏูŠุงุช ุงู„ุจุญุซูŠุฉ ููŠ ู…ุฌุงู„ {topic}ุŸ"
515
+ ]
516
+ elif style == "ุฅุฎุจุงุฑูŠ ู…ูˆุถูˆุนูŠ":
517
+ questions = [
518
+ f"ู…ุง ู‡ูŠ ุฃุญุฏุซ ุงู„ุชุทูˆุฑุงุช ููŠ ู…ุฌุงู„ {topic}ุŸ",
519
+ f"ูƒูŠู ูŠุคุซุฑ {topic} ุนู„ู‰ ุงู„ู‚ุทุงุนุงุช ุงู„ู…ุฎุชู„ูุฉุŸ",
520
+ f"ู…ุง ู‡ูŠ ุชูˆู‚ุนุงุช ุงู„ุฎุจุฑุงุก ู„ู…ุณุชู‚ุจู„ {topic}ุŸ"
521
+ ]
522
+ elif style == "ุชู‚ู†ูŠ ุชูุตูŠู„ูŠ":
523
+ questions = [
524
+ f"ู…ุง ู‡ูŠ ุงู„ู…ู…ูŠุฒุงุช ุงู„ุชู‚ู†ูŠุฉ ุงู„ุฑุฆูŠุณูŠุฉ ู„ู€{topic}ุŸ",
525
+ f"ูƒูŠู ูŠู…ูƒู† ุชุทุจูŠู‚ {topic} ููŠ ุงู„ู…ุดุงุฑูŠุน ุงู„ุนู…ู„ูŠุฉุŸ",
526
+ f"ู…ุง ู‡ูŠ ู…ุชุทู„ุจุงุช ุชู†ููŠุฐ ุญู„ูˆู„ {topic}ุŸ"
527
+ ]
528
+ elif style == "ุชุนู„ูŠู…ูŠ ุชูุงุนู„ูŠ":
529
+ questions = [
530
+ f"ู…ุง ู‡ูŠ ุงู„ู…ูุงู‡ูŠู… ุงู„ุฃุณุงุณูŠุฉ ุงู„ุชูŠ ูŠุฌุจ ูู‡ู…ู‡ุง ููŠ ู…ุฌุงู„ {topic}ุŸ",
531
+ f"ูƒูŠู ูŠู…ูƒู† ุชุนุฒูŠุฒ ูู‡ู…ูƒ ู„ู…ุฌุงู„ {topic}ุŸ",
532
+ f"ู…ุง ู‡ูŠ ุงู„ุฃู‡ุฏุงู ุงู„ุชุนู„ูŠู…ูŠุฉ ุงู„ุชูŠ ูŠุฌุจ ุชุญู‚ูŠู‚ู‡ุง ููŠ ู…ุฌุงู„ {topic}ุŸ"
533
+ ]
534
+ elif style == "ุชุณูˆูŠู‚ูŠ ู…ู‚ู†ุน":
535
+ questions = [
536
+ f"ู…ุง ู‡ูŠ ุงู„ุญู„ูˆู„ ุงู„ูุนุงู„ุฉ ุงู„ุชูŠ ู†ู‚ุฏู…ู‡ุง ู„ู…ุฌุงู„ {topic}ุŸ",
537
+ f"ูƒูŠู ูŠู…ูƒู† ุชุญุณูŠู† ุฃุฏุงุฆูƒ ููŠ ู…ุฌุงู„ {topic}ุŸ",
538
+ f"ู…ุง ู‡ูŠ ุงู„ู…ู…ูŠุฒุงุช ุงู„ุชูŠ ุชุชู…ูŠุฒ ุจู‡ุง ู…ู†ุชุฌุงุชู†ุง ุฃูˆ ุฎุฏู…ุงุชู†ุง ููŠ ู…ุฌุงู„ {topic}ุŸ"
539
+ ]
540
+ elif style == "ุงุฌุชู…ุงุนูŠ ุชุญู„ูŠู„ูŠ":
541
+ questions = [
542
+ f"ู…ุง ู‡ูŠ ุงู„ุธูˆุงู‡ุฑ ุงู„ุงุฌุชู…ุงุนูŠุฉ ุงู„ุชูŠ ุชุคุซุฑ ุนู„ู‰ ู…ุฌุงู„ {topic}ุŸ",
543
+ f"ูƒูŠู ูŠู…ูƒู† ุชุญู„ูŠู„ ุงู„ุชุฃุซูŠุฑุงุช ุงู„ุงุฌุชู…ุงุนูŠุฉ ููŠ ู…ุฌุงู„ {topic}ุŸ",
544
+ f"ู…ุง ู‡ูŠ ุงู„ุญู„ูˆู„ ุงู„ู…ู…ูƒู†ุฉ ู„ู„ุชุญุฏูŠุงุช ุงู„ุงุฌุชู…ุงุนูŠุฉ ููŠ ู…ุฌุงู„ {topic}ุŸ"
545
+ ]
546
+ elif style == "ุชุญู„ูŠู„ูŠ ู†ู‚ุฏูŠ":
547
+ questions = [
548
+ f"ู…ุง ู‡ูŠ ุงู„ู†ู‚ุงุท ุงู„ู‚ูˆูŠุฉ ูˆุงู„ุถุนู ููŠ ู…ุฌุงู„ {topic}ุŸ",
549
+ f"ูƒูŠู ูŠู…ูƒู† ุชู‚ูŠูŠู… ุงู„ุฃุฏุงุก ููŠ ู…ุฌุงู„ {topic}ุŸ",
550
+ f"ู…ุง ู‡ูŠ ุงู„ุชูˆุตูŠุงุช ุงู„ุชูŠ ูŠู…ูƒู† ุชู‚ุฏูŠู…ู‡ุง ู„ุชุญุณูŠู† ุฃุฏุงุก ู…ุฌุงู„ {topic}ุŸ"
551
+ ]
552
+ else:
553
+ questions = [
554
+ f"ู…ุง ู‡ูŠ ุงู„ุชุฃุซูŠุฑุงุช ุงู„ุซู‚ุงููŠุฉ ุงู„ุชูŠ ุชุคุซุฑ ุนู„ู‰ ู…ุฌุงู„ {topic}ุŸ",
555
+ f"ูƒูŠู ูŠู…ูƒู† ุชุญู„ูŠู„ ุงู„ุชูุงุนู„ุงุช ุงู„ุซู‚ุงููŠุฉ ููŠ ู…ุฌุงู„ {topic}ุŸ",
556
+ f"ู…ุง ู‡ูŠ ุงู„ุญู„ูˆู„ ุงู„ู…ู…ูƒู†ุฉ ู„ู„ุชุญุฏูŠุงุช ุงู„ุซู‚ุงููŠุฉ ููŠ ู…ุฌุงู„ {topic}ุŸ"
557
+ ]
558
+
559
+ faq = []
560
+ for q in questions:
561
+ faq.append({
562
+ "question": q,
563
+ "answer": f"""ูŠู…ูƒู† ุงู„ุฅุฌุงุจุฉ ุนู„ู‰ ู‡ุฐุง ุงู„ุณุคุงู„ ู…ู† ุฎู„ุงู„ ุชุญู„ูŠู„ ู…ุนู…ู‚ ู„ู„ุฌูˆุงู†ุจ ุงู„ู…ุฎุชู„ูุฉ
564
+ ุงู„ู…ุชุนู„ู‚ุฉ ุจู€{topic}. ูˆุชุดูŠุฑ ุงู„ุฏุฑุงุณุงุช ูˆุงู„ุชุฌุงุฑุจ ุงู„ุนู…ู„ูŠุฉ ุฅู„ู‰ ู…ุฌู…ูˆุนุฉ ู…ู† ุงู„ู†ู‚ุงุท ุงู„ู‡ุงู…ุฉ ุงู„ุชูŠ
565
+ ุชุณุงุนุฏ ููŠ ูู‡ู… ูˆุชุทูˆูŠุฑ ู‡ุฐุง ุงู„ู…ุฌุงู„."""
566
+ })
567
+ return faq
568
+
569
  # ุฅู†ุดุงุก ูˆุงุฌู‡ุฉ ุงู„ู…ุณุชุฎุฏู…
570
  with gr.Blocks(title="ู…ุณุงุนุฏ ูƒุชุงุจุฉ ุงู„ู…ู‚ุงู„ุงุช ุงู„ุนุฑุจูŠุฉ") as demo:
571
  gr.Markdown("# ๐Ÿ“ ู…ุณุงุนุฏ ูƒุชุงุจุฉ ุงู„ู…ู‚ุงู„ุงุช ุงู„ุนุฑุจูŠุฉ")
572
  gr.Markdown("### ู…ู†ุตุฉ ุฐูƒูŠุฉ ู„ุฅู†ุดุงุก ูˆุชุญุณูŠู† ุงู„ู…ู‚ุงู„ุงุช ุงู„ุนุฑุจูŠุฉ")
573
 
574
  with gr.Tab("ุฅู†ุดุงุก ู…ู‚ุงู„ ุงุญุชุฑุงููŠ"):
575
+ with gr.Row():
576
+ topic_input = gr.Textbox(label="ู…ูˆุถูˆุน ุงู„ู…ู‚ุงู„", placeholder="ุฃุฏุฎู„ ู…ูˆุถูˆุน ุงู„ู…ู‚ุงู„ ู‡ู†ุง...")
577
+ article_type = gr.Dropdown(
578
+ choices=["ุนู„ู…ูŠ", "ุตุญููŠ", "ุชู‚ู†ูŠ", "ุชุนู„ูŠู…ูŠ", "ุชุณูˆูŠู‚ูŠ", "ุงุฌุชู…ุงุนูŠ", "ุฑุฃูŠ", "ุซู‚ุงููŠ"],
579
+ label="ู†ูˆุน ุงู„ู…ู‚ุงู„",
580
+ value="ุนู„ู…ูŠ"
581
+ )
582
+
583
+ with gr.Row():
584
+ word_count_slider = gr.Slider(
585
+ minimum=1000,
586
+ maximum=3000,
587
+ value=1500,
588
+ step=100,
589
+ label="ุนุฏุฏ ุงู„ูƒู„ู…ุงุช ุงู„ู…ุทู„ูˆุจ"
590
+ )
591
+ formality_level = gr.Dropdown(
592
+ choices=["ุฑุณู…ูŠ", "ุดุจู‡ ุฑุณู…ูŠ", "ุนุงุฏูŠ"],
593
+ label="ู…ุณุชูˆู‰ ุงู„ุฑุณู…ูŠุฉ",
594
+ value="ุฑุณู…ูŠ"
595
+ )
596
+
597
+ with gr.Row():
598
+ generate_btn = gr.Button("ุฅู†ุดุงุก ุงู„ู…ู‚ุงู„", variant="primary")
599
+ copy_btn = gr.Button("ู†ุณุฎ ุงู„ู…ู‚ุงู„")
600
+
601
+ output = gr.Textbox(
602
+ label="ุงู„ู…ู‚ุงู„ ุงู„ู…ูู†ุดุฃ",
603
+ lines=30,
604
+ show_copy_button=True
605
  )
 
 
606
 
607
+ word_count_output = gr.Textbox(label="ุนุฏุฏ ุงู„ูƒู„ู…ุงุช ุงู„ูุนู„ูŠ")
608
+
609
+ def count_words(text):
610
+ words = text.split()
611
+ return f"ุนุฏุฏ ุงู„ูƒู„ู…ุงุช: {len(words)}"
612
+
613
+ def copy_article(text):
614
+ return text
615
 
616
  generate_btn.click(
617
+ fn=generate_article,
618
  inputs=[topic_input, article_type],
619
+ outputs=[output]
620
+ ).then(
621
+ fn=count_words,
622
+ inputs=[output],
623
+ outputs=[word_count_output]
624
+ )
625
+
626
+ copy_btn.click(
627
+ fn=copy_article,
628
+ inputs=[output],
629
+ outputs=[output]
630
  )
631
 
632
  demo.launch()