Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,9 @@ import os, json, re, logging, requests, markdown, time, io
|
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 6 |
from openai import OpenAI # OpenAI λΌμ΄λΈλ¬λ¦¬
|
| 7 |
|
| 8 |
from gradio_client import Client
|
|
@@ -312,48 +315,51 @@ def get_openai_client():
|
|
| 312 |
)
|
| 313 |
|
| 314 |
# ββββββββββββββββββββββββββββββββ New System Prompt for Idea Generation βββββββββββββββββββββ
|
| 315 |
-
|
|
|
|
| 316 |
"""
|
| 317 |
-
|
| 318 |
-
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
prompt = """
|
| 324 |
-
λ°λμ νκΈ(νκ΅μ΄)λ‘ λ΅λ³νλΌ. You are an advanced Idea Generation AI. Your goal is to take the user's prompt (topic, concept, or question) and create **3 distinct ideas** around it, drawing from the vast categories of **physical or conceptual transformations**. Specifically, you must produce:
|
| 325 |
-
|
| 326 |
-
1. **Similarity-based Augmentation**
|
| 327 |
-
- Build upon the user's original concept by closely aligning to its core attributes.
|
| 328 |
-
- Reference relevant categories or subcategories that naturally extend or amplify the original idea.
|
| 329 |
-
- Provide a practical, logical explanation.
|
| 330 |
-
|
| 331 |
-
2. **Contrarian/Inverse Approach**
|
| 332 |
-
- Intentionally invert or contradict the core assumptions of the original concept.
|
| 333 |
-
- Use contrasting categories to spark unconventional thinking.
|
| 334 |
-
- Clearly justify why this contrarian perspective might reveal novel possibilities.
|
| 335 |
-
|
| 336 |
-
3. **Random (Fortuitous Spark)**
|
| 337 |
-
- Randomly select one or more categories or subcategories from any domain to introduce surprising or serendipitous ideas.
|
| 338 |
-
- Show how this unexpected combination can yield fresh insights or opportunities.
|
| 339 |
-
|
| 340 |
-
For each of the 3 approaches:
|
| 341 |
-
- Provide a concise name or title for the idea.
|
| 342 |
-
- Offer a clear, structured explanation (a few paragraphs) on how this idea works or could be realized.
|
| 343 |
-
- Incorporate references to the relevant category or categories from the provided classification, explaining how they link to the idea.
|
| 344 |
-
- Suggest a short, single-line **English prompt for generating an image** that best represents that idea.
|
| 345 |
-
|
| 346 |
-
Finally:
|
| 347 |
-
- Return your answer in Markdown format with headings (e.g., "## Idea 1: ...", "## Idea 2: ...", "## Idea 3: ...").
|
| 348 |
-
- Do **not** mention that you are responding with "3 ideas" because of a prompt or instruction. Simply present them as the final structured output.
|
| 349 |
-
- Never mention "blog," "SEO," or "prompt" instructions in your final text.
|
| 350 |
-
- Do **not** mention that you're an AI. Present the content as a straightforward creative text for each idea.
|
| 351 |
-
|
| 352 |
-
---
|
| 353 |
-
**Important**: You have access to a list of "physical_transformation_categories" (in Korean) and possibly an English version. Use them to anchor or inspire each idea, but do not simply copy the entire list. Instead, selectively reference a few relevant subcategories.
|
| 354 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
return prompt.strip()
|
| 356 |
|
|
|
|
|
|
|
| 357 |
# ββββββββββββββββββββββββββββββββ Brave Search API ββββββββββββββββββββββββ
|
| 358 |
@st.cache_data(ttl=3600)
|
| 359 |
def brave_search(query: str, count: int = 20):
|
|
@@ -635,6 +641,16 @@ def idea_generator_app():
|
|
| 635 |
"example3": "λ―Έλν κ΅μ‘ μλΉμ€ ꡬμ"
|
| 636 |
}
|
| 637 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 638 |
sb.subheader("Example Prompts")
|
| 639 |
c1, c2, c3 = sb.columns(3)
|
| 640 |
if c1.button("AI & λΉμ¦λμ€", key="ex1"):
|
|
|
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
import streamlit as st
|
| 6 |
+
|
| 7 |
+
st.set_page_config(layout="wide")
|
| 8 |
+
|
| 9 |
from openai import OpenAI # OpenAI λΌμ΄λΈλ¬λ¦¬
|
| 10 |
|
| 11 |
from gradio_client import Client
|
|
|
|
| 315 |
)
|
| 316 |
|
| 317 |
# ββββββββββββββββββββββββββββββββ New System Prompt for Idea Generation βββββββββββββββββββββ
|
| 318 |
+
# βββββββββββββββββ System Prompt (REPORT STYLE) βββββββββββββββββ
|
| 319 |
+
def get_idea_system_prompt(selected_category: str | None = None) -> str:
|
| 320 |
"""
|
| 321 |
+
Return an enhanced system prompt that forces:
|
| 322 |
+
βΈ Report-style output with tables
|
| 323 |
+
βΈ Clear focus on NEED βΈ VALUE βΈ PROBLEM SOLVED βΈ IMPLEMENTATION SNAPSHOT
|
| 324 |
+
βΈ Three idea modes: Similarity-based, Contrarian, Random
|
| 325 |
+
βΈ If `selected_category` is given, all ideas must chiefly reference
|
| 326 |
+
sub-items inside that category.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
"""
|
| 328 |
+
cat_clause = (f"\n**Category Focus**: Concentrate on the Korean list "
|
| 329 |
+
f"under β{selected_category}β. You *must* anchor every idea "
|
| 330 |
+
"to 2-3 sub-items from this category and reference them by name.\n")
|
| 331 |
+
prompt = f"""
|
| 332 |
+
λ°λμ νκΈ(νκ΅μ΄)λ‘ λ΅λ³νλΌ. You are an elite innovation consultant. Your deliverable is a concise **report** in Markdown.
|
| 333 |
+
|
| 334 |
+
### OUTPUT SPECIFICATION
|
| 335 |
+
Produce **exactly three ideas** (Similarity-Based, Contrarian, Random) using these sections **for *each* idea**:
|
| 336 |
+
|
| 337 |
+
| νλͺ© | λ΄μ© |
|
| 338 |
+
|---|---|
|
| 339 |
+
| **Idea Title** | 8-12 Korean characters + μλ¬Έ κ΄νΈλ³μΉ |
|
| 340 |
+
| **Need / Pain-Point** | μ΄λ€ λ¬Έμ Β·κΈ°ν λλ¬Έμ νμνκ°? (1-2 λ¬Έμ₯) |
|
| 341 |
+
| **Core Concept** | μμ΄λμ΄ κ°μ (2-3 λ¬Έλ¨) |
|
| 342 |
+
| **Key Category Links** | μ¬μ©ν λ³ν μΉ΄ν
κ³ λ¦¬/νμνλͺ©(3κ° μ΄ν) |
|
| 343 |
+
| **Value Proposition** | κΈ°λ ν¨κ³ΌΒ·κ°μΉ (λΆλ¦Ώ 3κ°) |
|
| 344 |
+
| **Potential Obstacles** | μ£Όμ 리μ€ν¬Β·μ μ½ (λΆλ¦Ώ 2-3κ°) |
|
| 345 |
+
| **Image Prompt** | μλ¬Έ 1μ€λ‘ μκ°νλ₯Ό μν ν둬ννΈ |
|
| 346 |
+
|
| 347 |
+
- ν¬ν¨λ νλ λ§ν¬λ€μ΄ κ·Έλλ‘ μΆλ ₯.
|
| 348 |
+
- μΈ μμ΄λμ΄λ₯Ό β## Idea 1β, β## Idea 2β, β## Idea 3β ν€λ©μΌλ‘ μμν.
|
| 349 |
+
- μ λ¬Έμ©μ΄ μ΅μν, κ°κ²°νμ§λ§ μ€λλ ₯ μκ².
|
| 350 |
+
|
| 351 |
+
### IDEA MODES
|
| 352 |
+
1. **Similarity-Based Augmentation** β κΈ°μ‘΄ μ£Όμ μ κ°μ₯ κ°κΉκ² νμ₯.
|
| 353 |
+
2. **Contrarian / Inverse** β μ£Όμ μ μ μ λ₯Ό λ€μ§μ΄ μλ‘μ΄ μκ° μ μ.
|
| 354 |
+
3. **Random Spark** β 무μμ νμνλͺ©(μΉ΄ν
κ³ λ¦¬ λΆλ¬Έ)μ κ²°ν©ν μμΈμ ν΅μ°°.
|
| 355 |
+
|
| 356 |
+
{cat_clause if selected_category else ""}
|
| 357 |
+
Always think step-by-step but **show only the final report**.
|
| 358 |
+
"""
|
| 359 |
return prompt.strip()
|
| 360 |
|
| 361 |
+
|
| 362 |
+
|
| 363 |
# ββββββββββββββββββββββββββββββββ Brave Search API ββββββββββββββββββββββββ
|
| 364 |
@st.cache_data(ttl=3600)
|
| 365 |
def brave_search(query: str, count: int = 20):
|
|
|
|
| 641 |
"example3": "λ―Έλν κ΅μ‘ μλΉμ€ ꡬμ"
|
| 642 |
}
|
| 643 |
|
| 644 |
+
sb.subheader("Category Focus (Optional)")
|
| 645 |
+
category_keys = ["(None)"] + list(physical_transformation_categories.keys())
|
| 646 |
+
sb.selectbox(
|
| 647 |
+
"Generate ideas mainly using this category",
|
| 648 |
+
options=category_keys,
|
| 649 |
+
key="category_focus",
|
| 650 |
+
index=0 # κΈ°λ³Έκ° "(None)"
|
| 651 |
+
)
|
| 652 |
+
|
| 653 |
+
|
| 654 |
sb.subheader("Example Prompts")
|
| 655 |
c1, c2, c3 = sb.columns(3)
|
| 656 |
if c1.button("AI & λΉμ¦λμ€", key="ex1"):
|