Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,13 @@
|
|
1 |
"""
|
2 |
Square Theory Generator (Markdownโonly, up to 20 ideas)
|
3 |
=====================================================
|
4 |
-
2025โ05โ28ย
|
5 |
---------------------------------------------------
|
6 |
๋ณ๊ฒฝ ์์ฝ
|
7 |
---------
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
**๋ฉ์ธ ์นดํผ**
|
12 |
-
โข ์๋จ: ํ๋ฏธ๋ฅผ ๋ด์ ์ปคํผ
|
13 |
-
โข ํ๋จ: ๋น์ ์ ํ๋ฃจ๋ฅผ ํน๋ณํ๊ฒ
|
14 |
-
|
15 |
-
**์ฌ๋ก๊ฑด**
|
16 |
-
> ์ปคํผ ํ์์ ์ฌ์
|
17 |
-
|
18 |
-
**์ฌ๊ฐํ ํค์๋**
|
19 |
-
TL: ํ๋ฏธ ยท TR: ์ปคํผ ยท BR: ํฅ๊ธฐ ยท BL: ํ์
|
20 |
-
```
|
21 |
-
2. **ํ๋กฌํํธ ๋ช
์ธ ์ ์ง** โ JSON ๊ตฌ์กฐ ๋ณ๋์ ์์(ํธํ).
|
22 |
-
3. **์ถ๊ฐ ๊ฐ์ ์ ์** โ ์ฝ๋ ๋ด ์ฃผ์์ผ๋ก โ์ถ๊ฐ ํ๋ยท๋ญํน ๊ธฐ์คยทCSV ๋ค์ด๋ก๋โ ์์ด๋์ด ์ฝ์
.
|
23 |
|
24 |
์คํ๋ฒ
|
25 |
------
|
@@ -33,7 +21,8 @@ python square_theory_gradio.py
|
|
33 |
import os
|
34 |
import json
|
35 |
import gradio as gr
|
36 |
-
|
|
|
37 |
|
38 |
# -------------------------------------------------
|
39 |
# 0. OpenAI ํด๋ผ์ด์ธํธ
|
@@ -57,7 +46,6 @@ FALLBACK_MODELS = ["gpt-4o-mini", "gpt-4o", "gpt-4o-preview", "gpt-4-turbo"]
|
|
57 |
|
58 |
|
59 |
def _clean_json_block(text: str) -> str:
|
60 |
-
"""Strip ```json fences if present."""
|
61 |
text = text.strip()
|
62 |
if text.startswith("```"):
|
63 |
text = text.split("\n", 1)[1] if "\n" in text else text[3:]
|
@@ -86,7 +74,7 @@ def _call_llm(seed: str):
|
|
86 |
if not isinstance(data, list) or not (1 <= len(data) <= 20):
|
87 |
raise ValueError("LLM ์๋ต์ด ์ฌ๋ฐ๋ฅธ 1โ20๊ฐ ๋ฆฌ์คํธ๊ฐ ์๋")
|
88 |
return data
|
89 |
-
except (
|
90 |
last_exc = exc
|
91 |
continue
|
92 |
raise RuntimeError(f"LLM ํธ์ถ ์คํจ: {last_exc}")
|
@@ -128,12 +116,11 @@ with gr.Blocks(title="Square Theory โ ์ต๋ 20๊ฐ ๐ฐ๐ท") as demo:
|
|
128 |
|
129 |
run.click(generate, inputs=seed, outputs=md_out)
|
130 |
|
131 |
-
# queue(): ๋ก๋ฉ ์ธ๋์ผ์ดํฐ & ๋์ ์ ์ ์์ ํ
|
132 |
demo.queue().launch()
|
133 |
|
134 |
# -------------------------------------------------
|
135 |
# 4. (Optional) ์ถ๊ฐ ๊ธฐ๋ฅ ์์ด๋์ด
|
136 |
# -------------------------------------------------
|
137 |
-
# - JSON์ "why"
|
138 |
-
# - ์ฑ๋๋ณ ํ๊ทธ๋ผ์ธ ๋ณํ(
|
139 |
-
# -
|
|
|
1 |
"""
|
2 |
Square Theory Generator (Markdownโonly, up to 20 ideas)
|
3 |
=====================================================
|
4 |
+
2025โ05โ28ย v10 โ ImportErrorย fix (OpenAI error module)
|
5 |
---------------------------------------------------
|
6 |
๋ณ๊ฒฝ ์์ฝ
|
7 |
---------
|
8 |
+
* **๋ฌธ์ **: `from openai import OpenAI, error as oai_err` โ v1ย SDK์๋ `error` ์๋ธ๋ชจ๋์ด ์์ โ `ImportError`.
|
9 |
+
* **ํด๊ฒฐ**: `import openai` ํ `openai.OpenAIError` ์ฐธ์กฐ.
|
10 |
+
`except` ์ ์ `openai.OpenAIError` ๋ก ๊ต์ฒด.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
์คํ๋ฒ
|
13 |
------
|
|
|
21 |
import os
|
22 |
import json
|
23 |
import gradio as gr
|
24 |
+
import openai
|
25 |
+
from openai import OpenAI
|
26 |
|
27 |
# -------------------------------------------------
|
28 |
# 0. OpenAI ํด๋ผ์ด์ธํธ
|
|
|
46 |
|
47 |
|
48 |
def _clean_json_block(text: str) -> str:
|
|
|
49 |
text = text.strip()
|
50 |
if text.startswith("```"):
|
51 |
text = text.split("\n", 1)[1] if "\n" in text else text[3:]
|
|
|
74 |
if not isinstance(data, list) or not (1 <= len(data) <= 20):
|
75 |
raise ValueError("LLM ์๋ต์ด ์ฌ๋ฐ๋ฅธ 1โ20๊ฐ ๋ฆฌ์คํธ๊ฐ ์๋")
|
76 |
return data
|
77 |
+
except (openai.OpenAIError, json.JSONDecodeError, ValueError, TypeError) as exc:
|
78 |
last_exc = exc
|
79 |
continue
|
80 |
raise RuntimeError(f"LLM ํธ์ถ ์คํจ: {last_exc}")
|
|
|
116 |
|
117 |
run.click(generate, inputs=seed, outputs=md_out)
|
118 |
|
|
|
119 |
demo.queue().launch()
|
120 |
|
121 |
# -------------------------------------------------
|
122 |
# 4. (Optional) ์ถ๊ฐ ๊ธฐ๋ฅ ์์ด๋์ด
|
123 |
# -------------------------------------------------
|
124 |
+
# - JSON์ "why" ํ๋ ์์ฒญ โ ๊ฐ ์ ์์ ์ ์ ์ด์ ๋ฅผ ํ์ํด ์ค๋๋ ฅ ๊ฐํ
|
125 |
+
# - ํ๊น ์ฑ๋๋ณ ํ๊ทธ๋ผ์ธ ๋ณํ ์ต์
(OHHยทSNSยทTV)
|
126 |
+
# - CSV ๋ค์ด๋ก๋ ๋ฒํผ์ผ๋ก ๊ฒฐ๊ณผ ์ผ๊ด ์ ์ฅ
|