import gradio as gr import os from openai import OpenAI css = """ .gradio-container { max-width: min(90vw, 800px) !important; margin: 0 auto !important; display: flex !important; } @keyframes rainbow { 0% { background: hsl(0, 60%, 70%); } 16% { background: hsl(60, 60%, 70%); } 33% { background: hsl(120, 60%, 70%); } 50% { background: hsl(180, 60%, 70%); } 66% { background: hsl(240, 60%, 70%); } 83% { background: hsl(300, 60%, 70%); } 100% { background: hsl(360, 60%, 70%); } } #rainbow-btn { text-shadow: 1px 1px 2px black !important; } #rainbow-btn:hover { animation: rainbow 3s linear infinite !important; } h1 { background: linear-gradient(45deg, #4169e1, #87ceeb, #4169e1) !important; -webkit-background-clip: text !important; -webkit-text-fill-color: transparent !important; background-clip: text !important; text-shadow: 2px 2px 4px rgba(0,0,0,0.3) !important; font-size: 4.5em !important; font-weight: 700 !important; font-family: "Impact", "Arial Black", sans-serif !important; text-align: center !important; letter-spacing: 2px !important; } """ def generate_prompt(): try: # Read the system prompt from file with open("system_prompt.md", "r") as f: system_prompt = f.read() # Initialize OpenAI client client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY")) # Make API call response = client.chat.completions.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": system_prompt}, {"role": "user", "content": "Generate a new system prompt."} ], max_tokens=500, temperature=0.9 ) return response.choices[0].message.content except Exception: return f"Could not generate a prompt. No fish today." with gr.Blocks( title="Prompt Roulette", css=css ) as demo: gr.Markdown("# PROMPT ROULETTE") gr.Markdown( "**Tired of talking to the same boring AI every day?**\n\n" "Tired of friendly exclamation points (!), 👋 emojis, and bullet point lists?\n\n" ) gr.Markdown( "You need a new system prompt! Click the button below to discover a new side of your favorite AI assistant." ) generate_btn = gr.Button("SPIN", variant="primary", elem_id="rainbow-btn") output_text = gr.Textbox( label="Your New Prompt", lines=5, max_lines=10, interactive=False, show_copy_button=True ) generate_btn.click( fn=generate_prompt, outputs=[output_text] ) demo.launch()