import gradio as gr import random import pandas as pd import json import os import shutil from datetime import datetime # Verzeichnisse DATA_DIR = "data" PRESET_FILE = os.path.join(DATA_DIR, "presets.json") BACKUP_DIR = os.path.join(DATA_DIR, "backups") SESSION_DIR = os.path.join(DATA_DIR, "sessions") EXPORT_DIR = "exports" # Sicherstellen, dass alle benötigten Verzeichnisse existieren os.makedirs(DATA_DIR, exist_ok=True) os.makedirs(BACKUP_DIR, exist_ok=True) os.makedirs(SESSION_DIR, exist_ok=True) os.makedirs(EXPORT_DIR, exist_ok=True) # Hilfsfunktionen Presets def load_presets(): with open(PRESET_FILE, "r") as f: return json.load(f) def save_presets(presets): timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") backup_file = os.path.join(BACKUP_DIR, f"presets_backup_{timestamp}.json") shutil.copy(PRESET_FILE, backup_file) with open(PRESET_FILE, "w") as f: json.dump(presets, f, indent=4) # Kamera-/Objektiv-/Film-Datenbank (gekürzt) camera_lens_film_combinations_master = [ ("Canon EOS R5", "Canon RF 50mm f/1.2L USM", "Kodak Portra 400"), ("Nikon Z8", "Nikon Z 50mm f/1.2 S", "Kodak Ektar 100"), ("Sony Alpha 7R V", "Sony FE 85mm f/1.4 GM", "Cinestill 800T"), ("Fujifilm GFX 100 II", "Fujifilm GF 80mm f/1.7 R WR", "Fujifilm Provia 100F"), ("Leica M11", "Leica Summilux-M 50mm f/1.4 ASPH", "Kodak Gold 200") ] light_conditions_master = [ "Golden Hour", "Blue Hour", "Overcast Light", "Diffused Light", "Backlighting", "Soft Ambient Light", "Low-Key Lighting", "High-Key Lighting", "Window Light", "Dappled Light" ] # Prompt Generator def master_prompt_engine(scene_description, num_prompts, aspect_ratio, quality, stylize, seed): prompts = [] for _ in range(num_prompts): camera, lens, film = random.choice(camera_lens_film_combinations_master) light = random.choice(light_conditions_master) mj_parameters = f"--ar {aspect_ratio} --q {quality} --s {stylize}" if seed != "": mj_parameters += f" --seed {seed}" prompt = f"{scene_description}, shot with {camera} and {lens}, using {film} film, under {light} {mj_parameters}" prompts.append(prompt) return prompts # Export Funktion inkl. Session Logging + stabiler Rückgabe def generate_and_export(selected_preset, custom_scene, num_prompts, aspect_ratio, quality, stylize, seed, export_format): presets = load_presets() scene_description = custom_scene if selected_preset == "Custom Input" else presets[selected_preset] prompts = master_prompt_engine(scene_description, num_prompts, aspect_ratio, quality, stylize, seed) df = pd.DataFrame(prompts, columns=["Prompt"]) timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") export_file = os.path.join(EXPORT_DIR, f"prompts_export_{timestamp}.{export_format}") if export_format == "csv": df.to_csv(export_file, index=False) elif export_format == "txt": with open(export_file, "w") as f: for line in prompts: f.write(line + "\n") elif export_format == "json": df.to_json(export_file, orient="records", indent=4) # Session Logging session_file = os.path.join(SESSION_DIR, f"session_{timestamp}.txt") with open(session_file, "w") as f: for line in prompts: f.write(line + "\n") prompt_text = "\n".join(prompts) file_info = f"File successfully saved to: {export_file}" return file_info, prompt_text # Preset hinzufügen def add_preset(new_name, new_description): presets = load_presets() if new_name in presets: return f"Preset '{new_name}' already exists." presets[new_name] = new_description save_presets(presets) return f"Preset '{new_name}' added successfully." # Preset Liste aktualisieren def update_preset_list(): presets = load_presets() return list(presets.keys()) + ["Custom Input"] # Gradio Interface with gr.Blocks() as demo: gr.Markdown("# TischEins.org | Midjourney Prompt Engine") with gr.Tab("Prompt Generator"): preset_choice = gr.Dropdown(choices=update_preset_list(), label="Select Preset") custom_scene = gr.Textbox(label="Or enter your custom scene", placeholder="Describe your scene here...") num = gr.Slider(1, 500, value=20, step=1, label="Number of Prompts") aspect_ratio = gr.Textbox(label="Aspect Ratio", value="5:4") quality = gr.Textbox(label="Quality", value="2") stylize = gr.Textbox(label="Stylize", value="750") seed = gr.Textbox(label="Seed (optional)", placeholder="Leave empty for random") export_format = gr.Dropdown(choices=["csv", "txt", "json"], label="Export Format", value="txt") btn = gr.Button("Generate Prompts") export_info = gr.Textbox(label="Export Status") output_preview = gr.Textbox(label="Generated Prompts", lines=20) btn.click(fn=generate_and_export, inputs=[preset_choice, custom_scene, num, aspect_ratio, quality, stylize, seed, export_format], outputs=[export_info, output_preview]) with gr.Tab("Preset Manager"): new_name = gr.Textbox(label="New Preset Name") new_description = gr.Textbox(label="New Preset Description", lines=3) add_btn = gr.Button("Add Preset") add_output = gr.Textbox(label="Preset Manager Status") add_btn.click(fn=add_preset, inputs=[new_name, new_description], outputs=add_output) gr.Markdown('Pro Studio Production Suite by TischEins.org') demo.launch()