ssboost commited on
Commit
d7f2ca8
ยท
verified ยท
1 Parent(s): 6bb875d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +488 -0
app.py ADDED
@@ -0,0 +1,488 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from dotenv import load_dotenv
4
+ import logging
5
+ import time
6
+ import uuid
7
+ import google.generativeai as genai
8
+
9
+ # ๋กœ๊น… ์„ค์ • - INFO ๋ ˆ๋ฒจ๋กœ ๋ณ€๊ฒฝ
10
+ logging.basicConfig(level=logging.INFO)
11
+ logger = logging.getLogger(__name__)
12
+
13
+ # ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๋กœ๋“œ
14
+ load_dotenv()
15
+
16
+ # API ํ‚ค ์„ค์ •
17
+ GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
18
+ logger.info("API ํ‚ค ์„ค์ • ์™„๋ฃŒ")
19
+
20
+ # Google Gemini ์ดˆ๊ธฐํ™”
21
+ genai.configure(api_key=GOOGLE_API_KEY)
22
+
23
+ # ๋ชจ๋ธ๋ณ„ ํ”„๋กฌํ”„ํŠธ ์ •์˜
24
+ GEMINI_PROMPTS = {
25
+ "๋งž์ถค๋ฒ• ๊ฒ€์‚ฌ๊ธฐ": """
26
+ # ๋ชฉ์ : ํ•œ๊ตญ์–ด ๋ฌธ๋ฒ• ๊ต์ • ๋ฐ ๊ฐœ์„ 
27
+ ## ์ง€์นจ
28
+ 1. ์ฃผ์–ด์ง„ ํ…์ŠคํŠธ์˜ ๋ฌธ๋ฒ•์„ ์ „๋ฌธ์ ์œผ๋กœ ๊ฒ€ํ† ํ•˜๊ณ  ๊ต์ •ํ•˜์„ธ์š”.
29
+ 2. ์›๋ณธ ํ…์ŠคํŠธ์˜ ์˜๋ฏธ์™€ ์˜๋„๋ฅผ ์ฒ ์ €ํžˆ ์œ ์ง€ํ•˜๋ฉด์„œ ๋ฌธ๋ฒ•์ ์ธ ๋ถ€๋ถ„๋งŒ ์ˆ˜์ •ํ•˜์„ธ์š”.
30
+ 3. ๋‹ค์Œ ์š”์†Œ๋“ค์„ ํ•œ๊ตญ์–ด ๋ฌธ๋ฒ• ๊ทœ์น™์— ๋งž๊ฒŒ ์ •ํ™•ํ•˜๊ฒŒ ์ˆ˜์ •ํ•˜์„ธ์š”:
31
+ - ๋งž์ถค๋ฒ• ์˜ค๋ฅ˜
32
+ - ๋„์–ด์“ฐ๊ธฐ ์˜ค๋ฅ˜
33
+ - ๋ฌธ์žฅ ๋ถ€ํ˜ธ ์‚ฌ์šฉ
34
+ - ์กฐ์‚ฌ ์‚ฌ์šฉ์˜ ์ •ํ™•์„ฑ
35
+ - ์–ด๋ฏธ ํ™œ์šฉ์˜ ์ •ํ™•์„ฑ
36
+ - ๋ฌธ์žฅ ์„ฑ๋ถ„์˜ ํ˜ธ์‘ ๊ด€๊ณ„
37
+ 4. ์ ˆ๋Œ€ ์›๋ณธ ํ…์ŠคํŠธ์— ์—†๋Š” ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ์˜๋ฏธ๋ฅผ ๋ณ€๊ฒฝํ•˜์ง€ ๋งˆ์„ธ์š”.
38
+ 5. ๋ถ€๊ฐ€ ์„ค๋ช…์ด๋‚˜ ๋ฉ”ํƒ€ ์ •๋ณด(์˜ˆ: "์ˆ˜์ •๋œ ํ…์ŠคํŠธ:", "๊ฐœ์„ ๋œ ํ…์ŠคํŠธ:" ๋“ฑ)๋Š” ์ถœ๋ ฅํ•˜์ง€ ๋งˆ์„ธ์š”.
39
+ 6. ์˜ค์ง ๊ต์ •๋œ ํ…์ŠคํŠธ๋งŒ ์ถœ๋ ฅํ•˜์„ธ์š”.
40
+ """,
41
+
42
+ "๊ธ€ ๋‹ค๋“ฌ๊ธฐ": """
43
+ # ๋ชฉ์ : ๋ฌธ์žฅ ๊ตฌ์กฐ์™€ ํ‘œํ˜„ ๊ฐœ์„ 
44
+ ## ์ง€์นจ
45
+ 1. ๋ฌธ์žฅ ๊ตฌ์กฐ ์ตœ์ ํ™”
46
+ - ๋ถˆํ•„์š”ํ•œ ๋ฌธ๊ตฌ์™€ ์ค‘๋ณต ํ‘œํ˜„์„ ์ œ๊ฑฐํ•˜์—ฌ ๊ฐ„๊ฒฐ์„ฑ ํ™•๋ณด
47
+ - ์ฃผ์–ด-์„œ์ˆ ์–ด ๊ด€๊ณ„๋ฅผ ๋ช…ํ™•ํžˆ ํ•˜์—ฌ ์˜๋ฏธ ์ „๋‹ฌ๋ ฅ ๊ฐ•ํ™”
48
+ - ๊ณผ๋„ํ•˜๊ฒŒ ๊ธด ๋ฌธ์žฅ์€ ์ ์ ˆํžˆ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ฐ€๋…์„ฑ ํ–ฅ์ƒ
49
+ - ๋ฌธ์žฅ ๊ฐ„์˜ ๋…ผ๋ฆฌ์  ์—ฐ๊ฒฐ์„ฑ ํ™•๋ณด
50
+
51
+ 2. ๋‹จ๋ฝ ๊ตฌ์„ฑ ์ตœ์ ํ™”
52
+ - ๊ฐ ๋‹จ๋ฝ์ด ๋ช…ํ™•ํ•œ ํ•ต์‹ฌ ์ฃผ์ œ๋ฅผ ๊ฐ€์ง€๋„๋ก ์กฐ์ •
53
+ - ๋‹จ๋ฝ ๊ฐ„ ์ž์—ฐ์Šค๋Ÿฌ์šด ํ๋ฆ„์„ ์œ„ํ•œ ์—ฐ๊ฒฐ์–ด ์‚ฌ์šฉ
54
+ - ๋‹จ๋ฝ ๊ธธ์ด์˜ ๊ท ํ˜• ์œ ์ง€
55
+
56
+ 3. ์–ดํœ˜ ๋ฐ ํ‘œํ˜„ ๊ฐœ์„ 
57
+ - ๋ถˆํ•„์š”ํ•œ ์™ธ๋ž˜์–ด๋Š” ์ ์ ˆํ•œ ํ•œ๊ตญ์–ด๋กœ ๋Œ€์ฒด
58
+ - ์ถ”์ƒ์ ์ด๊ฑฐ๋‚˜ ๋ชจํ˜ธํ•œ ํ‘œํ˜„์€ ๊ตฌ์ฒด์ ์ด๊ณ  ๋ช…ํ™•ํ•œ ์šฉ์–ด๋กœ ๋Œ€์ฒด
59
+ - ์ค‘๋ณต๋˜๋Š” ํ‘œํ˜„ ์ œ๊ฑฐ๋กœ ๋ฌธ์žฅ ํšจ์œจ์„ฑ ์ฆ๋Œ€
60
+ - ๊ด€์šฉ์  ํ‘œํ˜„๊ณผ ์ ์ ˆํ•œ ๋น„์œ ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํ‘œํ˜„๋ ฅ ๊ฐ•ํ™”
61
+
62
+ 4. ์ „๋‹ฌ๋ ฅ ๊ฐ•ํ™”
63
+ - ํ•ต์‹ฌ ๋ฉ”์‹œ์ง€๊ฐ€ ๋‹๋ณด์ด๋„๋ก ๋ฌธ์žฅ ๊ตฌ์กฐ ์žฌ๋ฐฐ์น˜
64
+ - ๋…ผ๋ฆฌ์  ํ๋ฆ„๊ณผ ์ผ๊ด€์„ฑ ํ™•๋ณด
65
+ - ๋…์ž์˜ ์ดํ•ด๋„๋ฅผ ๊ณ ๋ คํ•œ ํ‘œํ˜„ ์„ ํƒ
66
+
67
+ 5. ์ผ๊ด€์„ฑ ์œ ์ง€
68
+ - ๋ฌธ์ฒด์™€ ํ†ค์˜ ์ผ๊ด€์„ฑ ์œ ์ง€
69
+ - ์ „๋ฌธ ์šฉ์–ด์™€ ํ‘œํ˜„์˜ ํ†ต์ผ์„ฑ ํ™•๋ณด
70
+ - ์‹œ์ œ์˜ ์ผ๊ด€๋œ ์‚ฌ์šฉ
71
+
72
+ ## ์ถœ๋ ฅ ํ˜•์‹
73
+ - ์›๋ณธ ํ…์ŠคํŠธ์™€ ๋™์ผํ•œ ๋งํˆฌ์™€ ์–ด์กฐ๋ฅผ ์œ ์ง€ํ•˜๋˜, ์œ„ ๊ธฐ์ค€์— ๋”ฐ๋ผ ๊ฐœ์„ ๋œ ํ…์ŠคํŠธ๋งŒ ์ถœ๋ ฅ
74
+ - ๋ถ€๊ฐ€ ์„ค๋ช…์ด๋‚˜ ๋ฉ”ํƒ€ ์ •๋ณด๋Š” ํฌํ•จํ•˜์ง€ ์•Š์Œ
75
+ """,
76
+
77
+ "๋ช…์–ธ ์ธ์šฉํ•˜๊ธฐ": """
78
+ # ๋ชฉ์ : ๋ช…์–ธ์„ ํ™œ์šฉํ•œ ์„ค๋“๋ ฅ ์žˆ๋Š” ํ…์ŠคํŠธ ๊ฐœ์„ 
79
+ ## ์ง€์นจ
80
+ 1. ๋ฌธ๋งฅ ๋ถ„์„
81
+ - ํ…์ŠคํŠธ์˜ ํ•ต์‹ฌ ์ฃผ์ œ์™€ ์˜๋„ ํŒŒ์•…
82
+ - ํ…์ŠคํŠธ์˜ ๋ถ„์œ„๊ธฐ์™€ ํ†ค ๋ถ„์„
83
+ - ๋…์ž์ธต๊ณผ ๋ชฉ์  ๊ณ ๋ ค
84
+
85
+ 2. ์ ์ ˆํ•œ ๋ช…์–ธ ์„ ํƒ
86
+ - ํ…์ŠคํŠธ์˜ ์ฃผ์ œ์™€ ์ง์ ‘์ ์œผ๋กœ ์—ฐ๊ด€๋œ ๋ช…์–ธ ์„ ํƒ
87
+ - ๋‹ค์–‘ํ•œ ๋ถ„์•ผ(์ฒ ํ•™, ๋ฌธํ•™, ์—ญ์‚ฌ, ๊ณผํ•™ ๋“ฑ)์˜ ๋ช…์–ธ ๊ณ ๋ ค
88
+ - ๊ณ ์ „์ ์ธ ๋ช…์–ธ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ํ˜„๋Œ€ ์œ ๋ช…์ธ(์—ฐ์˜ˆ์ธ, ๊ธฐ์—…์ธ, ์šด๋™์„ ์ˆ˜, ์ •์น˜์ธ ๋“ฑ)์˜ ์ธ์ƒ์ ์ธ ๋ง๋„ ์ ๊ทน ํ™œ์šฉ
89
+ - ํ•œ๊ตญ ๋ฐ ์„ธ๊ณ„์˜ ์ €๋ช…ํ•œ ์ธ๋ฌผ์˜ ๋ช…์–ธ ํ™œ์šฉ
90
+ - ํ…์ŠคํŠธ์˜ ํ†ค๊ณผ ๋ถ„์œ„๊ธฐ์— ์–ด์šธ๋ฆฌ๋Š” ๋ช…์–ธ ์„ ํƒ
91
+ - ๊ฐ€๋Šฅํ•˜๋ฉด ์‹œ์˜์ ์ ˆํ•˜๊ณ  ์ตœ์‹  ํŠธ๋ Œ๋“œ๋ฅผ ๋ฐ˜์˜ํ•œ ํ˜„๋Œ€์  ๋ช…์–ธ ์šฐ์„  ๊ณ ๋ ค
92
+
93
+ 3. ๋ช…์–ธ ํ†ตํ•ฉ
94
+ - ํ…์ŠคํŠธ ๋‚ด ๊ฐ€์žฅ ํšจ๊ณผ์ ์ธ ์œ„์น˜์— ๋ช…์–ธ ๋ฐฐ์น˜ (์‹œ์ž‘, ์ค‘๊ฐ„, ๋˜๋Š” ๊ฒฐ๋ก )
95
+ - ๋ช…์–ธ์„ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋„์ž…ํ•˜์—ฌ ๊ธฐ์กด ํ…์ŠคํŠธ์™€ ์กฐํ™”๋กญ๊ฒŒ ํ†ตํ•ฉ
96
+ - ํ•„์š”์‹œ ๋ช…์–ธ์˜ ์ถœ์ฒ˜(์ธ๋ฌผ ์ด๋ฆ„) ํฌํ•จ
97
+ - ๋”ฑ ํ•œ ๋ฒˆ๋งŒ ๋ช…์–ธ ์ธ์šฉํ•˜๊ธฐ
98
+ - ํ˜„๋Œ€ ์œ ๋ช…์ธ์˜ ๋ช…์–ธ ์‚ฌ์šฉ ์‹œ ๊ฐ„๋‹จํ•œ ๋งฅ๋ฝ ์„ค๋ช… ๊ณ ๋ ค(ํ•„์š”ํ•œ ๊ฒฝ์šฐ)
99
+
100
+ 4. ์ „์ฒด ํ…์ŠคํŠธ ์กฐ์ •
101
+ - ๋ช…์–ธ ๋„์ž… ํ›„ ํ•„์š”์‹œ ์ „ํ›„ ๋ฌธ์žฅ ์กฐ์ •ํ•˜์—ฌ ์ž์—ฐ์Šค๋Ÿฌ์šด ํ๋ฆ„ ์œ ์ง€
102
+ - ์›๋ณธ ํ…์ŠคํŠธ์˜ ํ•ต์‹ฌ ๋ฉ”์‹œ์ง€์™€ ์˜๋„ ๋ณด์กด
103
+ - ์ „์ฒด์ ์ธ ์ผ๊ด€์„ฑ๊ณผ ์‘์ง‘๋ ฅ ์œ ์ง€
104
+ - ๋ช…์–ธ์ด ํ…์ŠคํŠธ์— ์‹ ์„ ํ•จ๊ณผ ๊ถŒ์œ„๋ฅผ ๋ถ€์—ฌํ•˜๋Š”์ง€ ํ™•์ธ
105
+
106
+ ## ์ถœ๋ ฅ ํ˜•์‹
107
+ - ๋ช…์–ธ์ด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ†ตํ•ฉ๋œ ๊ฐœ์„ ๋œ ํ…์ŠคํŠธ๋งŒ ์ถœ๋ ฅ
108
+ - ๋ถ€๊ฐ€ ์„ค๋ช…์ด๋‚˜ ๋ฉ”ํƒ€ ์ •๋ณด ์—†์ด ์ˆœ์ˆ˜ํ•˜๊ฒŒ ๊ฐœ์„ ๋œ ํ…์ŠคํŠธ๋งŒ ์ œ๊ณต
109
+ """,
110
+
111
+ "๋งž์ถคํ˜• ๋ณ€ํ™˜": """
112
+ # ๋ชฉ์ : ์‚ฌ์šฉ์ž ์ •์˜ ํŽ˜๋ฅด์†Œ๋‚˜์™€ ๋ชฉ์ ์— ๋งž๋Š” ํ…์ŠคํŠธ ๋ณ€ํ™˜
113
+ ## ์ง€์นจ
114
+ 1. ํŽ˜๋ฅด์†Œ๋‚˜ ๋ถ„์„ ๋ฐ ์ ์šฉ
115
+ - ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•œ ํŽ˜๋ฅด์†Œ๋‚˜์˜ ํŠน์„ฑ ๋ถ„์„ (๋งํˆฌ, ์–ดํœ˜ ์„ ํƒ, ๋ฌธ์žฅ ๊ตฌ์กฐ ๋“ฑ)
116
+ - ํ•ด๋‹น ํŽ˜๋ฅด์†Œ๋‚˜๊ฐ€ ์‹ค์ œ๋กœ ์ž‘์„ฑํ–ˆ์„ ๋ฒ•ํ•œ ์Šคํƒ€์ผ๋กœ ํ…์ŠคํŠธ ์žฌ๊ตฌ์„ฑ
117
+ - ํŽ˜๋ฅด์†Œ๋‚˜์˜ ๊ณ ์œ ํ•œ ํ‘œํ˜„ ๋ฐฉ์‹๊ณผ ๊ด€์  ๋ฐ˜์˜
118
+
119
+ 2. ๋ชฉ์  ๋ถ„์„ ๋ฐ ์ ์šฉ
120
+ - ์‚ฌ์šฉ์ž๊ฐ€ ๋ช…์‹œํ•œ ๋ชฉ์ ์— ๋งž๊ฒŒ ํ…์ŠคํŠธ์˜ ์ „๋ฐ˜์ ์ธ ๋ฐฉํ–ฅ์„ฑ ์กฐ์ •
121
+ - ๋ชฉ์ ์— ๋งž๋Š” ๊ตฌ์กฐ, ๋…ผ์กฐ, ๊ฐ•์กฐ์  ์„ค์ •
122
+ - ๋ชฉ์  ๋‹ฌ์„ฑ์— ํ•„์š”ํ•œ ์š”์†Œ ๏ฟฝ๏ฟฝํ™” ๋ฐ ๋ถˆํ•„์š”ํ•œ ์š”์†Œ ์ œ๊ฑฐ
123
+
124
+ 3. ํ…์ŠคํŠธ ๋งž์ถค ๋ณ€ํ™˜
125
+ - ํŽ˜๋ฅด์†Œ๋‚˜์™€ ๋ชฉ์ ์„ ์ข…ํ•ฉ์ ์œผ๋กœ ๊ณ ๋ คํ•œ ํ…์ŠคํŠธ ๋ณ€ํ™˜
126
+ - ์›๋ณธ ํ…์ŠคํŠธ์˜ ํ•ต์‹ฌ ์ •๋ณด์™€ ์ฃผ์š” ๋…ผ์  ์œ ์ง€
127
+ - ์–ดํœ˜, ๋ฌธ์žฅ ๊ตฌ์กฐ, ๋น„์œ , ์˜ˆ์‹œ ๋“ฑ์„ ํŽ˜๋ฅด์†Œ๋‚˜์™€ ๋ชฉ์ ์— ๋งž๊ฒŒ ์กฐ์ •
128
+ - ์ „์ฒด์ ์ธ ์ผ๊ด€์„ฑ๊ณผ ์ง„์ •์„ฑ ์œ ์ง€
129
+
130
+ 4. ํ’ˆ์งˆ ๋ฐ ํšจ๊ณผ ์ตœ์ ํ™”
131
+ - ๋ช…ํ™•์„ฑ๊ณผ ์ดํ•ด๋„ ํ–ฅ์ƒ
132
+ - ์„ค๋“๋ ฅ๊ณผ ํ˜ธ์†Œ๋ ฅ ๊ฐ•ํ™”
133
+ - ๋…์ฐฝ์„ฑ๊ณผ ์ฐธ์‹ ํ•จ ์ถ”๊ตฌ
134
+ - ๋ชฉํ‘œ ๋…์ž์—๊ฒŒ ํšจ๊ณผ์ ์œผ๋กœ ์ „๋‹ฌ๋  ์ˆ˜ ์žˆ๋Š” ํ˜•ํƒœ๋กœ ์ตœ์ ํ™”
135
+
136
+ ## ์ถœ๋ ฅ ํ˜•์‹
137
+ - ํŽ˜๋ฅด์†Œ๋‚˜์™€ ๋ชฉ์ ์— ๋งž๊ฒŒ ๋ณ€ํ˜•๋œ ํ…์ŠคํŠธ๋งŒ ์ถœ๋ ฅ
138
+ - ๋ถ€๊ฐ€ ์„ค๋ช…์ด๋‚˜ ๋ฉ”ํƒ€ ์ •๋ณด ์—†์ด ์ˆœ์ˆ˜ํ•˜๊ฒŒ ๋ณ€ํ™˜๋œ ํ…์ŠคํŠธ๋งŒ ์ œ๊ณต
139
+ - ์‚ฌ์šฉ์ž๊ฐ€ ๋ช…์‹œํ•œ ๋ชฉ์ ๊ณผ ํŽ˜๋ฅด์†Œ๋‚˜์˜ ํŠน์„ฑ์ด ๋ช…ํ™•ํžˆ ๋“œ๋Ÿฌ๋‚˜๋Š” ๊ฒฐ๊ณผ๋ฌผ ์ œ๊ณต
140
+ """,
141
+ }
142
+
143
+ def process_text(input_text, improvement_type, custom_purpose, persona, temperature, top_p):
144
+ """Gemini ๋ชจ๋ธ์šฉ ํ…์ŠคํŠธ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜"""
145
+ try:
146
+ print("ํ…์ŠคํŠธ ์ฒ˜๋ฆฌ ์‹œ์ž‘")
147
+ request_id = str(uuid.uuid4())[:8]
148
+ timestamp_micro = int(time.time() * 1000000) % 1000
149
+
150
+ if improvement_type == "๋งž์ถคํ˜• ๋ณ€ํ™˜":
151
+ purpose = f"๋‹ค์Œ ํŽ˜๋ฅด์†Œ๋‚˜๋ฅผ ๊ฐ€์ง€๊ณ  ํ…์ŠคํŠธ๋ฅผ ๋‹ค๋“ฌ์œผ์„ธ์š”: {persona}\n\n๋ชฉ์ : {custom_purpose}"
152
+ else:
153
+ purpose = GEMINI_PROMPTS[improvement_type]
154
+
155
+ model = genai.GenerativeModel(
156
+ model_name="gemini-2.0-flash",
157
+ generation_config={
158
+ "temperature": temperature,
159
+ "top_p": top_p,
160
+ "max_output_tokens": 2000,
161
+ }
162
+ )
163
+
164
+ # ์‹œ์Šคํ…œ ์ง€์‹œ์‚ฌํ•ญ์„ ์ฒซ ๋ฒˆ์งธ ์‚ฌ์šฉ์ž ๋ฉ”์‹œ์ง€์— ํฌํ•จ
165
+ prompt = f"REQ-{request_id}-{timestamp_micro}\n\n๋‹ค์Œ ํ…์ŠคํŠธ๋ฅผ ๋ชฉ์ ์— ๋งž๊ฒŒ ๋‹ค๋“ฌ์–ด์ฃผ์„ธ์š”.\n\nํ…์ŠคํŠธ: {input_text}\n\n๋ชฉ์ : {purpose}"
166
+
167
+ response = model.generate_content(prompt)
168
+ print("ํ…์ŠคํŠธ ์ฒ˜๋ฆฌ ์™„๋ฃŒ")
169
+ return response.text
170
+
171
+ except Exception as e:
172
+ print("ํ…์ŠคํŠธ ์ฒ˜๋ฆฌ ์‹คํŒจ")
173
+ logger.error(f"์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
174
+ return f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
175
+
176
+ def create_interface():
177
+ # FontAwesome ์•„์ด์ฝ˜ ํฌํ•จ
178
+ fontawesome = """
179
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
180
+ """
181
+
182
+ # ์ปค์Šคํ…€ CSS ์Šคํƒ€์ผ
183
+ css = """
184
+ :root {
185
+ --primary-color: #FF7F00;
186
+ --secondary-color: #ff9a8b;
187
+ --accent-color: #FF6B6B;
188
+ --background-color: #FFF8F0;
189
+ --card-bg: #ffffff;
190
+ --text-color: #334155;
191
+ --border-radius: 18px;
192
+ --shadow: 0 8px 30px rgba(251, 127, 13, 0.08);
193
+ }
194
+
195
+ body {
196
+ font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
197
+ background-color: var(--background-color);
198
+ color: var(--text-color);
199
+ line-height: 1.6;
200
+ }
201
+
202
+ footer {
203
+ visibility: hidden;
204
+ }
205
+
206
+ .container {
207
+ max-width: 1200px;
208
+ margin: 0 auto;
209
+ }
210
+
211
+ .header {
212
+ background: linear-gradient(135deg, #FF7F00, #FF9A5B);
213
+ padding: 2rem;
214
+ border-radius: 15px;
215
+ margin-bottom: 20px;
216
+ box-shadow: var(--shadow);
217
+ text-align: center;
218
+ color: white;
219
+ }
220
+
221
+ .header h1 {
222
+ margin: 0;
223
+ font-size: 2.5rem;
224
+ font-weight: 700;
225
+ }
226
+
227
+ .header p {
228
+ margin: 10px 0 0;
229
+ font-size: 1.2rem;
230
+ opacity: 0.9;
231
+ }
232
+
233
+ .card {
234
+ background-color: var(--card-bg);
235
+ border-radius: var(--border-radius);
236
+ padding: 20px;
237
+ margin: 10px 0;
238
+ box-shadow: var(--shadow);
239
+ border: 1px solid rgba(0, 0, 0, 0.04);
240
+ }
241
+
242
+ .button-primary {
243
+ border-radius: 30px !important;
244
+ background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)) !important;
245
+ color: white !important;
246
+ font-size: 18px !important;
247
+ padding: 10px 20px !important;
248
+ border: none;
249
+ box-shadow: 0 4px 8px rgba(251, 127, 13, 0.25);
250
+ transition: transform 0.3s ease;
251
+ text-align: center;
252
+ font-weight: 600;
253
+ }
254
+
255
+ .button-primary:hover {
256
+ transform: translateY(-2px);
257
+ box-shadow: 0 6px 12px rgba(251, 127, 13, 0.3);
258
+ }
259
+
260
+ .section-title {
261
+ display: flex;
262
+ align-items: center;
263
+ font-size: 20px;
264
+ font-weight: 700;
265
+ color: #333333;
266
+ margin-bottom: 15px;
267
+ padding-bottom: 8px;
268
+ border-bottom: 2px solid #FF7F00;
269
+ }
270
+
271
+ .section-title i {
272
+ margin-right: 10px;
273
+ color: #FF7F00;
274
+ }
275
+
276
+ .guide-container {
277
+ background-color: #FFF0E2;
278
+ border-radius: var(--border-radius);
279
+ padding: 1.5rem;
280
+ margin-bottom: 1.5rem;
281
+ border: 1px solid rgba(255, 127, 0, 0.1);
282
+ }
283
+
284
+ .guide-title {
285
+ font-size: 1.3rem;
286
+ font-weight: 700;
287
+ color: var(--primary-color);
288
+ margin-bottom: 1rem;
289
+ display: flex;
290
+ align-items: center;
291
+ }
292
+
293
+ .guide-title i {
294
+ margin-right: 0.8rem;
295
+ font-size: 1.3rem;
296
+ }
297
+
298
+ .guide-item {
299
+ display: flex;
300
+ margin-bottom: 0.8rem;
301
+ align-items: flex-start;
302
+ }
303
+
304
+ .guide-number {
305
+ background-color: var(--primary-color);
306
+ color: white;
307
+ width: 24px;
308
+ height: 24px;
309
+ border-radius: 50%;
310
+ display: flex;
311
+ align-items: center;
312
+ justify-content: center;
313
+ font-weight: bold;
314
+ margin-right: 10px;
315
+ flex-shrink: 0;
316
+ font-size: 14px;
317
+ }
318
+
319
+ .guide-text {
320
+ flex: 1;
321
+ line-height: 1.6;
322
+ }
323
+
324
+ .feature-tag {
325
+ display: inline-block;
326
+ background-color: rgba(255, 127, 0, 0.1);
327
+ color: #FF7F00;
328
+ padding: 3px 10px;
329
+ border-radius: 12px;
330
+ font-size: 14px;
331
+ font-weight: 600;
332
+ margin-right: 8px;
333
+ margin-bottom: 8px;
334
+ }
335
+
336
+ .input-label {
337
+ font-weight: 600;
338
+ margin-bottom: 8px;
339
+ color: #444;
340
+ }
341
+
342
+ /* ๊ทธ๋ผ๋””์˜ค ์š”์†Œ ์Šคํƒ€์ผ ์ปค์Šคํ„ฐ๋งˆ์ด์ง• */
343
+ .gr-input, .gr-text-input, .gr-sample-inputs {
344
+ border-radius: var(--border-radius) !important;
345
+ border: 1px solid #e5e7eb !important;
346
+ padding: 12px !important;
347
+ transition: all 0.3s ease !important;
348
+ }
349
+
350
+ .gr-input:focus, .gr-text-input:focus {
351
+ border-color: var(--primary-color) !important;
352
+ outline: none !important;
353
+ box-shadow: 0 0 0 2px rgba(251, 127, 13, 0.2) !important;
354
+ }
355
+
356
+ /* ์Šคํฌ๋กค๋ฐ” ์Šคํƒ€์ผ๋ง */
357
+ ::-webkit-scrollbar {
358
+ width: 8px;
359
+ height: 8px;
360
+ }
361
+
362
+ ::-webkit-scrollbar-track {
363
+ background: rgba(0, 0, 0, 0.05);
364
+ border-radius: 10px;
365
+ }
366
+
367
+ ::-webkit-scrollbar-thumb {
368
+ background: var(--primary-color);
369
+ border-radius: 10px;
370
+ }
371
+ """
372
+
373
+ with gr.Blocks(css=css, theme=gr.themes.Soft(
374
+ primary_hue=gr.themes.Color(
375
+ c50="#FFF7ED",
376
+ c100="#FFEDD5",
377
+ c200="#FED7AA",
378
+ c300="#FDBA74",
379
+ c400="#FB923C",
380
+ c500="#F97316",
381
+ c600="#EA580C",
382
+ c700="#C2410C",
383
+ c800="#9A3412",
384
+ c900="#7C2D12",
385
+ c950="#431407",
386
+ ),
387
+ secondary_hue="zinc",
388
+ neutral_hue="zinc",
389
+ font=("Pretendard", "sans-serif")
390
+ )) as demo:
391
+
392
+ gr.HTML(fontawesome)
393
+ with gr.Row():
394
+ with gr.Column(scale=1):
395
+ # ์™ผ์ชฝ ์ž…๋ ฅ ์˜์—ญ
396
+ with gr.Column(elem_classes="card"):
397
+ gr.HTML('<div class="section-title"><i class="fas fa-edit"></i> ์›๋ณธ ํ…์ŠคํŠธ</div>')
398
+ input_text = gr.Textbox(
399
+ label="",
400
+ placeholder="์—ฌ๊ธฐ์— ๊ฐœ์„ ํ•˜๊ณ  ์‹ถ์€ ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...",
401
+ lines=15
402
+ )
403
+
404
+ with gr.Column(elem_classes="card"):
405
+ gr.HTML('<div class="section-title"><i class="fas fa-sliders"></i> ๋ณ€ํ™˜ ์„ค์ •</div>')
406
+
407
+ improvement_type = gr.Radio(
408
+ choices=["๋งž์ถค๋ฒ• ๊ฒ€์‚ฌ๊ธฐ", "๊ธ€ ๋‹ค๋“ฌ๊ธฐ", "๋ช…์–ธ ์ธ์šฉํ•˜๊ธฐ", "๋งž์ถคํ˜• ๋ณ€ํ™˜"],
409
+ label="๋ณ€ํ™˜ ์œ ํ˜• ์„ ํƒ",
410
+ value="๋งž์ถค๋ฒ• ๊ฒ€์‚ฌ๊ธฐ"
411
+ )
412
+
413
+ # ๋งž์ถคํ˜• ๋ณ€ํ™˜ ์˜ต์…˜๋“ค
414
+ custom_purpose = gr.Textbox(
415
+ label="๋ณ€ํ™˜ ๋ชฉ์ ",
416
+ placeholder="ํ…์ŠคํŠธ๋ฅผ ์–ด๋–ค ๋ฐฉํ–ฅ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  ์‹ถ์œผ์‹ ์ง€ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”...",
417
+ lines=2,
418
+ visible=False
419
+ )
420
+
421
+ persona = gr.Textbox(
422
+ label="ํŽ˜๋ฅด์†Œ๋‚˜ ์„ค์ •",
423
+ placeholder="์–ด๋–ค ์—ญํ• ์ด๋‚˜ ์„ฑ๊ฒฉ์„ ๊ฐ€์ง„ ๊ธ€์“ฐ๊ธฐ ์Šคํƒ€์ผ์„ ์›ํ•˜์‹œ๋‚˜์š”? (์˜ˆ: ์œ ๋จธ๋Ÿฌ์Šคํ•œ ๊ฐœ๊ทธ๋งจ, ์ „๋ฌธ์ ์ธ ๋ถ„์„๊ฐ€)",
424
+ lines=2,
425
+ visible=False
426
+ )
427
+
428
+ with gr.Row(visible=False) as generation_settings:
429
+ temperature = gr.Slider(
430
+ minimum=0.0,
431
+ maximum=1.0,
432
+ value=0.7,
433
+ step=0.1,
434
+ label="์ฐฝ์˜์„ฑ ์ˆ˜์ค€",
435
+ info="๋†’์„์ˆ˜๋ก ๋” ์ฐฝ์˜์ ์ธ ๊ฒฐ๊ณผ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค"
436
+ )
437
+ top_p = gr.Slider(
438
+ minimum=0.0,
439
+ maximum=1.0,
440
+ value=0.9,
441
+ step=0.1,
442
+ label="๋‹ค์–‘์„ฑ ์ˆ˜์ค€",
443
+ info="๋†’์„์ˆ˜๋ก ๋” ๋‹ค์–‘ํ•œ ํ‘œํ˜„์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค"
444
+ )
445
+
446
+ submit_btn = gr.Button(
447
+ "โœจ ํ…์ŠคํŠธ ๋ณ€ํ™˜ํ•˜๊ธฐ",
448
+ elem_classes="button-primary"
449
+ )
450
+
451
+ with gr.Column(scale=1):
452
+ # ์˜ค๋ฅธ์ชฝ ์ถœ๋ ฅ ์˜์—ญ
453
+ with gr.Column(elem_classes="card"):
454
+ gr.HTML('<div class="section-title"><i class="fas fa-wand-magic-sparkles"></i> ๋ณ€ํ™˜๋œ ํ…์ŠคํŠธ</div>')
455
+ output_text = gr.Textbox(
456
+ label="",
457
+ lines=22,
458
+ show_copy_button=True
459
+ )
460
+
461
+ def update_custom_inputs_visibility(choice):
462
+ is_custom = choice == "๋งž์ถคํ˜• ๋ณ€ํ™˜"
463
+ return {
464
+ custom_purpose: gr.update(visible=is_custom),
465
+ persona: gr.update(visible=is_custom),
466
+ generation_settings: gr.update(visible=is_custom)
467
+ }
468
+
469
+ improvement_type.change(
470
+ fn=update_custom_inputs_visibility,
471
+ inputs=[improvement_type],
472
+ outputs=[custom_purpose, persona, generation_settings]
473
+ )
474
+
475
+ submit_btn.click(
476
+ fn=process_text,
477
+ inputs=[input_text, improvement_type, custom_purpose, persona, temperature, top_p],
478
+ outputs=output_text,
479
+ api_name="improve_text"
480
+ )
481
+
482
+ return demo
483
+
484
+ if __name__ == "__main__":
485
+ logger.info("์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹œ์ž‘")
486
+ demo = create_interface()
487
+ demo.queue()
488
+ demo.launch()