| | import gradio as gr |
| | import google.generativeai as genai |
| | import json |
| | import random |
| |
|
| | |
| | genai.configure(api_key="AIzaSyBzxuqigEr7TXXADHFxZ3hDKPGs1ENi92E") |
| |
|
| | model = genai.GenerativeModel("gemini-2.0-flash") |
| |
|
| | |
| | SYSTEM_PROMPT = """ |
| | [Task Background] |
| | You are the AI challenge generator for the relationship app “Spicer.” |
| | Your mission is to create unique, thrilling, and emotionally engaging challenges that help couples add fun, intimacy, and spontaneity to their relationships. |
| | |
| | [Task Context] |
| | You will receive a JSON request containing: |
| | { |
| | "spiceLevel": 1 | 2 | 3, |
| | "timesPerDay": 1 | 2 | 3, |
| | "keywords": [string], |
| | "longDistanceMode": boolean, |
| | "priorChallenges": [ |
| | {"title": string, "description": string} |
| | ] |
| | } |
| | Use this information to understand the users’ preferences, avoid repetition, and generate one new, original challenge idea. Each challenge must feel creative, context-aware, and match the couple’s kinkiness level and relationship mode (physical or long-distance). |
| | |
| | [Output Format] |
| | Return JSON like: |
| | { |
| | "title": "short creative name", |
| | "description": "one-sentence challenge instruction" |
| | } |
| | """ |
| |
|
| | |
| | def generate_challenge(spice_level, times_per_day, keywords, long_distance, prior_challenges): |
| | try: |
| | |
| | prior_list = [] |
| | for row in prior_challenges: |
| | if isinstance(row, list) and len(row) >= 2 and (row[0] or row[1]): |
| | prior_list.append({"title": row[0], "description": row[1]}) |
| |
|
| | |
| | user_json = { |
| | "spiceLevel": int(spice_level), |
| | "timesPerDay": int(times_per_day), |
| | "keywords": [k.strip() for k in keywords.split(",") if k.strip()], |
| | "longDistanceMode": bool(long_distance), |
| | "priorChallenges": prior_list |
| | } |
| |
|
| | |
| | response = model.generate_content( |
| | f"{SYSTEM_PROMPT}\n\nInput:\n{json.dumps(user_json, indent=2)}" |
| | ) |
| | text = response.text.strip() |
| |
|
| | |
| | try: |
| | data = json.loads(text[text.find("{"):text.rfind("}") + 1]) |
| | title = data.get("title", "Untitled Challenge") |
| | desc = data.get("description", "") |
| | return f"### 💋 {title}\n\n{desc}" |
| | except Exception: |
| | return text |
| |
|
| | except Exception as e: |
| | return f"❌ Error: {str(e)}" |
| |
|
| |
|
| | |
| | theme = gr.themes.Soft(primary_hue="pink", secondary_hue="rose", neutral_hue="gray") |
| |
|
| | |
| | def random_inputs(): |
| | return ( |
| | random.choice([1, 2, 3]), |
| | random.choice([1, 2, 3]), |
| | random.choice(["art, dance", "food, cooking", "outdoors, sunset", "gaming, minecraft"]), |
| | random.choice([True, False]), |
| | [["", ""]] |
| | ) |
| |
|
| | |
| | with gr.Blocks(theme=theme) as demo: |
| | gr.Markdown( |
| | """ |
| | <h1 style='text-align:center; color:#E75480;'>💞 Spicer Challenge Generator</h1> |
| | <p style='text-align:center; color:#777;'>AI-powered dares & games that add heat, laughter, and intimacy.</p> |
| | <hr> |
| | """ |
| | ) |
| |
|
| | with gr.Row(): |
| | spice_level = gr.Radio([1, 2, 3], label="🔥 Spice Level", value=1) |
| | times_per_day = gr.Radio([1, 2, 3], label="⏰ Times per Day", value=1) |
| |
|
| | with gr.Row(): |
| | keywords = gr.Textbox(placeholder="art, food, outdoors...", label="🎯 Keywords") |
| | long_distance = gr.Checkbox(label="💌 Long Distance Mode") |
| |
|
| | prior_challenges = gr.Dataframe( |
| | headers=["title", "description"], |
| | label="🕓 Previous Challenges (optional)", |
| | row_count=2, |
| | col_count=2 |
| | ) |
| |
|
| | with gr.Row(): |
| | generate_btn = gr.Button("💫 Generate Challenge", variant="primary") |
| | surprise_btn = gr.Button("🎲 Surprise Me!", variant="secondary") |
| |
|
| | output = gr.Markdown("") |
| |
|
| | generate_btn.click( |
| | fn=generate_challenge, |
| | inputs=[spice_level, times_per_day, keywords, long_distance, prior_challenges], |
| | outputs=output |
| | ) |
| |
|
| | surprise_btn.click( |
| | fn=lambda: generate_challenge(*random_inputs()), |
| | inputs=[], |
| | outputs=output |
| | ) |
| |
|
| | gr.Markdown("<hr><p style='text-align:center; color:#aaa;'>Made with ❤️ by Spicer</p>") |
| |
|
| | if __name__ == "__main__": |
| | demo.launch() |
| |
|