Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
)
|
423 |
-
generate_btn = gr.Button("ุฅูุดุงุก ุงูู
ูุงู")
|
424 |
-
output = gr.Textbox(label="ุงูู
ูุงู ุงูู
ููุดุฃ", lines=30)
|
425 |
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
|
|
|
|
|
|
|
|
430 |
|
431 |
generate_btn.click(
|
432 |
-
|
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()
|