Quantum Weaver Python GUI
👤 Sharing: AI
import tkinter as tk
from tkinter import ttk
import random
class QuantumWeaver(tk.Tk):
def __init__(self):
super().__init__()
self.title("Quantum Weaver: Creative Text Generator")
self.geometry("600x400")
self.text_label = ttk.Label(self, text="Input Text:")
self.text_label.pack(pady=5)
self.text_entry = tk.Text(self, height=5, width=60)
self.text_entry.pack(pady=5)
self.variation_label = ttk.Label(self, text="Variation Level (1-10):")
self.variation_label.pack(pady=5)
self.variation_scale = tk.Scale(self, from_=1, to=10, orient=tk.HORIZONTAL)
self.variation_scale.pack(pady=5)
self.generate_button = ttk.Button(self, text="Generate Variations", command=self.generate_variations)
self.generate_button.pack(pady=10)
self.output_label = ttk.Label(self, text="Generated Text:")
self.output_label.pack(pady=5)
self.output_text = tk.Text(self, height=5, width=60, state=tk.DISABLED)
self.output_text.pack(pady=5)
self.details_button = ttk.Button(self, text="Details", command=self.show_details)
self.details_button.pack(pady=10)
def generate_variations(self):
input_text = self.text_entry.get("1.0", tk.END).strip()
variation_level = int(self.variation_scale.get())
if not input_text:
self.update_output("Please enter some text.")
return
varied_text = self.create_variations(input_text, variation_level)
self.update_output(varied_text)
def create_variations(self, text, level):
words = text.split()
varied_words = []
for word in words:
if random.random() < level / 10:
# Introduce variations (e.g., synonym replacement, slight rephrasing)
synonyms = self.get_synonyms(word)
if synonyms:
varied_words.append(random.choice(synonyms))
else:
varied_words.append(self.add_noise(word, level))
else:
varied_words.append(word)
return " ".join(varied_words)
def get_synonyms(self, word):
# Placeholder for a real synonym retrieval mechanism (e.g., using a thesaurus API)
synonym_dict = {
"happy": ["joyful", "cheerful", "content"],
"sad": ["unhappy", "depressed", "melancholy"],
"big": ["large", "huge", "gigantic"]
}
return synonym_dict.get(word.lower(), [])
def add_noise(self, word, level):
# Introduce slight random changes to the word
noise_level = int(level * 0.2) # Adjust noise level based on variation
noisy_word = list(word)
for _ in range(noise_level):
index = random.randint(0, len(noisy_word) - 1)
if random.random() < 0.5:
# Swap with adjacent character
if index + 1 < len(noisy_word):
noisy_word[index], noisy_word[index + 1] = noisy_word[index + 1], noisy_word[index]
else:
# Insert a random character
noisy_word.insert(index, chr(random.randint(97, 122))) # a-z
return "".join(noisy_word)
def update_output(self, text):
self.output_text.config(state=tk.NORMAL)
self.output_text.delete("1.0", tk.END)
self.output_text.insert(tk.END, text)
self.output_text.config(state=tk.DISABLED)
def show_details(self):
details_window = tk.Toplevel(self)
details_window.title("Program Details")
details_text = tk.Text(details_window, height=15, width=70)
details_text.pack(padx=10, pady=10)
details_text.insert(tk.END, """
Quantum Weaver is a creative text generation tool. It takes input text and generates variations based on a specified 'Variation Level'. The program uses a combination of synonym replacement (using a basic internal dictionary that can be expanded) and the introduction of 'noise' to the words (slight random alterations).
Key Features:
* Adjustable Variation Level: Control the intensity of the text transformation.
* Synonym Replacement: Enhance the text with alternative word choices (requires a more comprehensive synonym database for richer results).
* Noise Introduction: Subtly alter words to create novel text forms.
Potential Uses:
* Generating creative writing prompts.
* Paraphrasing text (with limitations).
* Exploring linguistic variations.
Future Enhancements:
* Integration with a robust thesaurus API.
* More sophisticated noise generation algorithms (e.g., grammatical errors, stylistic variations).
* Option to preserve specific keywords or phrases.
* GUI improvements for better usability.
""")
details_text.config(state=tk.DISABLED)
if __name__ == "__main__":
app = QuantumWeaver()
app.mainloop()
👁️ Viewed: 6
Comments