Certainly! Below are four distinctive Python-based system variations for your text-based AI prompt generator. Each system:
- Generates a user-specified number of prompts (
random_generate = (n))
- Each prompt consists of two medium English sentences about a random Wikipedia article
- Followed by two medium sentences in a random language (different languages per prompt)
- Includes intricate details in the prompt content
- Uses random Wikipedia articles fetched dynamically
- Uses translations for the non-English segment
- Has a different style/mechanism in each variation for diversity
Prerequisites (for all variations):
pip install wikipedia googletrans==4.0.0-rc1
Variation 1: Simple random article fetch + direct translation for second half
import wikipedia
from googletrans import Translator
import random
def get_random_wikipedia_article():
# Get a random article title
random_title = wikipedia.random(pages=1)
try:
# Get summary limited to around two medium sentences (~60 words)
summary = wikipedia.summary(random_title, sentences=2)
return random_title, summary
except Exception as e:
# fallback if some article fails
return None, None
def generate_prompt():
translator = Translator()
languages = ['es', 'fr', 'de', 'it', 'ru', 'ja', 'zh-cn', 'ar', 'pt', 'nl']
title, eng_text = get_random_wikipedia_article()
if not eng_text:
return None
# Translate the English sentences into a random language
lang = random.choice(languages)
translated = translator.translate(eng_text, dest=lang).text
# Make sure translated text is roughly two sentences (split by periods)
# Or truncate if needed
translated_sentences = translated.split('.')
translated_snippet = '.'.join(translated_sentences[:2]).strip() + '.'
prompt = f"Article: {title}\n\n{eng_text}\n\n{translated_snippet} ({lang})"
return prompt
def random_generate(n):
for i in range(n):
prompt = generate_prompt()
if prompt:
print(f"PROMPT {i+1}:\n{prompt}\n{'-'*60}\n")
if __name__ == "__main__":
n = int(input("Enter the number of prompts to generate: "))
random_generate(n)
Variation 2: Uses sectioned data from Wikipedia, rephrases English, then translates into complex languages
import wikipedia
from googletrans import Translator
import random
import textwrap
def get_random_article_with_sections():
title = wikipedia.random(pages=1)
try:
page = wikipedia.page(title)
# Pick a random section with some text
if not page.sections:
return None, None
section = random.choice(page.sections)
content = wikipedia.page(title).section(section)
if content:
# Try to get first two medium sentences from section
sentences = content.split('. ')
snippet = '. '.join(sentences[:2]) + '.'
return title, snippet
else:
return None, None
except Exception:
return None, None
def rephrase_english(text):
# Simple rephrasing by splitting and joining,
# For demo, add detail about complexity/intricacy explicitly:
more_detail = ("This text delves into the complex aspects and intricate details related to the subject. "
+ text)
return more_detail
def generate_prompt():
translator = Translator()
# Select language with complex scripts or grammar
compl_langs = ['ar', 'hi', 'he', 'th', 'ko', 'fa']
title, eng_text = get_random_article_with_sections()
if not eng_text:
return None
eng_text = rephrase_english(eng_text)
lang = random.choice(compl_langs)
translated = translator.translate(eng_text, dest=lang).text
# Limit to roughly two sentences
translated_sentences = translated.split('.')
translated_snippet = '.'.join(translated_sentences[:2]).strip() + '.'
return f"Article: {title}\n\n{eng_text}\n\n{translated_snippet} ({lang})"
def random_generate(n):
count = 0
while count < n:
prompt = generate_prompt()
if prompt:
print(f"PROMPT {count+1}:\n{prompt}\n{'='*70}\n")
count += 1
if __name__ == "__main__":
n = int(input("Number of prompts to generate: "))
random_generate(n)
Variation 3: Pre-gathered random articles list + manual intricate valid info parsing + multiple languages in second half
import wikipedia
from googletrans import Translator
import random
def prefetch_random_articles(count=50):
titles = []
while len(titles) < count:
try:
title = wikipedia.random(pages=1)
# Ignore disambiguation pages etc.
page = wikipedia.page(title)
if 'disambiguation' not in page.title.lower():
titles.append(page.title)
except Exception:
continue
return titles
def extract_intricate_details(text):
# Approximate intricate detail by focusing on clause after comma or parentheses
parts = text.split(',')
if len(parts) > 1:
intricate_part = ','.join(parts[1:]).strip()
return parts[0] + ',' + intricate_part
else:
return text
def generate_prompt(prefetch_list):
translator = Translator()
lang_list = ['es', 'fr', 'it', 'de', 'ru', 'zh-cn']
title = random.choice(prefetch_list)
try:
summary = wikipedia.summary(title, sentences=2)
except Exception:
return None
# Extract intricate details
eng_text = extract_intricate_details(summary)
# Two English sentences
eng_sentences = eng_text.split('.')
eng_part = '.'.join(eng_sentences[:2]).strip() + "."
# Translate half sentences in second language
lang = random.choice(lang_list)
translated = translator.translate(eng_part, dest=lang).text
# Force exactly two sentences in target lang by splitting and trimming
t_sents = translated.split('.')
if len(t_sents) >= 2:
translated_part = '.'.join(t_sents[:2]).strip() + '.'
else:
translated_part = translated
prompt = f"Article: {title}\n\n{eng_part}\n\n{translated_part} ({lang})"
return prompt
def random_generate(n):
print("Prefetching random article titles for efficient generation...")
prefetch_list = prefetch_random_articles(100)
count = 0
while count < n:
prompt = generate_prompt(prefetch_list)
if prompt:
print(f"PROMPT {count+1}:\n{prompt}\n{'#'*60}\n")
count += 1
if __name__ == "__main__":
n = int(input("Enter number of prompts to generate: "))
random_generate(n)
Variation 4: Uses a user interaction to choose language sets + intricate facts added manually from disambiguation handling
import wikipedia
from googletrans import Translator
import random
def get_random_article_title():
try:
return wikipedia.random(pages=1)
except:
return None
def get_summary_safe(title):
try:
return wikipedia.summary(title, sentences=2)
except:
return None
def add_intricate_fact(title, summary):
# Adding an artificial intricate detail by appending wikipedia original url and length info
url = f"https://en.wikipedia.org/wiki/{title.replace(' ', '_')}"
length_info = f"The article length is approximately {len(summary.split())} words."
intricate_detail = f"{summary} Notably, {length_info} More info: {url}."
return intricate_detail
def translate_text(text, lang):
translator = Translator()
try:
return translator.translate(text, dest=lang).text
except:
return text
def random_generate(n):
# Let user pick language family sets
lang_families = {
'Romance': ['es', 'fr', 'it', 'pt', 'ro'],
'Germanic': ['de', 'nl', 'sv', 'da'],
'Slavic': ['ru', 'pl', 'cs', 'sk', 'uk'],
'Asian': ['ja', 'zh-cn', 'ko', 'hi', 'th']
}
print("Select language family for prompts (or 'random'):")
for k in lang_families:
print(f"- {k}")
choice = input("Your choice: ").strip()
if choice.lower() == 'random' or choice not in lang_families:
selected_langs = sum(lang_families.values(), [])
else:
selected_langs = lang_families[choice]
count = 0
while count < n:
title = get_random_article_title()
if not title:
continue
summary = get_summary_safe(title)
if not summary:
continue
# Remove disambiguation and append intricate facts
if 'disambiguation' in title.lower():
title = title.replace('(disambiguation)', '').strip()
summary = f"This disambiguation page refers to multiple topics under '{title}'."
intricate_text = add_intricate_fact(title, summary)
# split to two medium sentences
sentences = intricate_text.split('.')
eng_part = '.'.join(sentences[:2]).strip() + '.'
# Translate second half
lang = random.choice(selected_langs)
translated_part = translate_text(eng_part, lang)
# trim to two sentences in target lang
tsents = translated_part.split('.')
translated_part = '.'.join(tsents[:2]).strip() + '.'
print(f"PROMPT {count+1}:\nArticle: {title}\n\n{eng_part}\n\n{translated_part} ({lang})\n\n{'='*60}\n")
count += 1
if __name__ == "__main__":
n = int(input("Number of prompts to generate: "))
random_generate(n)
Summary
- All systems accept user input for number of prompts via
random_generate(n)
- Each prompt contains a random Wikipedia article title, two English sentences with intricacy, plus two sentences in a random language
- Different mechanisms to fetch or process the content (random single, sections, prefetch, disambiguation handling, user language choice)
- Each system handles translation and selection of language differently, providing good variety
If you want, I can help you adapt or integrate any of these!