Spaces:
Running
Running
import os | |
import gradio as gr | |
from dotenv import load_dotenv | |
import logging | |
import time | |
import uuid | |
import google.generativeai as genai | |
# ๋ก๊น ์ค์ - INFO ๋ ๋ฒจ๋ก ๋ณ๊ฒฝ | |
logging.basicConfig(level=logging.INFO) | |
logger = logging.getLogger(__name__) | |
# ํ๊ฒฝ ๋ณ์ ๋ก๋ | |
load_dotenv() | |
# API ํค ์ค์ | |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY") | |
logger.info("API ํค ์ค์ ์๋ฃ") | |
# Google Gemini ์ด๊ธฐํ | |
genai.configure(api_key=GOOGLE_API_KEY) | |
# ๋ชจ๋ธ๋ณ ํ๋กฌํํธ ์ ์ | |
GEMINI_PROMPTS = { | |
"๋ง์ถค๋ฒ ๊ฒ์ฌ๊ธฐ": """ | |
# ๋ชฉ์ : ํ๊ตญ์ด ๋ฌธ๋ฒ ๊ต์ ๋ฐ ๊ฐ์ | |
## ์ง์นจ | |
1. ์ฃผ์ด์ง ํ ์คํธ์ ๋ฌธ๋ฒ์ ์ ๋ฌธ์ ์ผ๋ก ๊ฒํ ํ๊ณ ๊ต์ ํ์ธ์. | |
2. ์๋ณธ ํ ์คํธ์ ์๋ฏธ์ ์๋๋ฅผ ์ฒ ์ ํ ์ ์งํ๋ฉด์ ๋ฌธ๋ฒ์ ์ธ ๋ถ๋ถ๋ง ์์ ํ์ธ์. | |
3. ๋ค์ ์์๋ค์ ํ๊ตญ์ด ๋ฌธ๋ฒ ๊ท์น์ ๋ง๊ฒ ์ ํํ๊ฒ ์์ ํ์ธ์: | |
- ๋ง์ถค๋ฒ ์ค๋ฅ | |
- ๋์ด์ฐ๊ธฐ ์ค๋ฅ | |
- ๋ฌธ์ฅ ๋ถํธ ์ฌ์ฉ | |
- ์กฐ์ฌ ์ฌ์ฉ์ ์ ํ์ฑ | |
- ์ด๋ฏธ ํ์ฉ์ ์ ํ์ฑ | |
- ๋ฌธ์ฅ ์ฑ๋ถ์ ํธ์ ๊ด๊ณ | |
4. ์ ๋ ์๋ณธ ํ ์คํธ์ ์๋ ๋ด์ฉ์ ์ถ๊ฐํ๊ฑฐ๋ ์๋ฏธ๋ฅผ ๋ณ๊ฒฝํ์ง ๋ง์ธ์. | |
5. ๋ถ๊ฐ ์ค๋ช ์ด๋ ๋ฉํ ์ ๋ณด(์: "์์ ๋ ํ ์คํธ:", "๊ฐ์ ๋ ํ ์คํธ:" ๋ฑ)๋ ์ถ๋ ฅํ์ง ๋ง์ธ์. | |
6. ์ค์ง ๊ต์ ๋ ํ ์คํธ๋ง ์ถ๋ ฅํ์ธ์. | |
""", | |
"๊ธ ๋ค๋ฌ๊ธฐ": """ | |
# ๋ชฉ์ : ๋ฌธ์ฅ ๊ตฌ์กฐ์ ํํ ๊ฐ์ | |
## ์ง์นจ | |
1. ๋ฌธ์ฅ ๊ตฌ์กฐ ์ต์ ํ | |
- ๋ถํ์ํ ๋ฌธ๊ตฌ์ ์ค๋ณต ํํ์ ์ ๊ฑฐํ์ฌ ๊ฐ๊ฒฐ์ฑ ํ๋ณด | |
- ์ฃผ์ด-์์ ์ด ๊ด๊ณ๋ฅผ ๋ช ํํ ํ์ฌ ์๋ฏธ ์ ๋ฌ๋ ฅ ๊ฐํ | |
- ๊ณผ๋ํ๊ฒ ๊ธด ๋ฌธ์ฅ์ ์ ์ ํ ๋ถ๋ฆฌํ์ฌ ๊ฐ๋ ์ฑ ํฅ์ | |
- ๋ฌธ์ฅ ๊ฐ์ ๋ ผ๋ฆฌ์ ์ฐ๊ฒฐ์ฑ ํ๋ณด | |
2. ๋จ๋ฝ ๊ตฌ์ฑ ์ต์ ํ | |
- ๊ฐ ๋จ๋ฝ์ด ๋ช ํํ ํต์ฌ ์ฃผ์ ๋ฅผ ๊ฐ์ง๋๋ก ์กฐ์ | |
- ๋จ๋ฝ ๊ฐ ์์ฐ์ค๋ฌ์ด ํ๋ฆ์ ์ํ ์ฐ๊ฒฐ์ด ์ฌ์ฉ | |
- ๋จ๋ฝ ๊ธธ์ด์ ๊ท ํ ์ ์ง | |
3. ์ดํ ๋ฐ ํํ ๊ฐ์ | |
- ๋ถํ์ํ ์ธ๋์ด๋ ์ ์ ํ ํ๊ตญ์ด๋ก ๋์ฒด | |
- ์ถ์์ ์ด๊ฑฐ๋ ๋ชจํธํ ํํ์ ๊ตฌ์ฒด์ ์ด๊ณ ๋ช ํํ ์ฉ์ด๋ก ๋์ฒด | |
- ์ค๋ณต๋๋ ํํ ์ ๊ฑฐ๋ก ๋ฌธ์ฅ ํจ์จ์ฑ ์ฆ๋ | |
- ๊ด์ฉ์ ํํ๊ณผ ์ ์ ํ ๋น์ ๋ฅผ ํ์ฉํ์ฌ ํํ๋ ฅ ๊ฐํ | |
4. ์ ๋ฌ๋ ฅ ๊ฐํ | |
- ํต์ฌ ๋ฉ์์ง๊ฐ ๋๋ณด์ด๋๋ก ๋ฌธ์ฅ ๊ตฌ์กฐ ์ฌ๋ฐฐ์น | |
- ๋ ผ๋ฆฌ์ ํ๋ฆ๊ณผ ์ผ๊ด์ฑ ํ๋ณด | |
- ๋ ์์ ์ดํด๋๋ฅผ ๊ณ ๋ คํ ํํ ์ ํ | |
5. ์ผ๊ด์ฑ ์ ์ง | |
- ๋ฌธ์ฒด์ ํค์ ์ผ๊ด์ฑ ์ ์ง | |
- ์ ๋ฌธ ์ฉ์ด์ ํํ์ ํต์ผ์ฑ ํ๋ณด | |
- ์์ ์ ์ผ๊ด๋ ์ฌ์ฉ | |
## ์ถ๋ ฅ ํ์ | |
- ์๋ณธ ํ ์คํธ์ ๋์ผํ ๋งํฌ์ ์ด์กฐ๋ฅผ ์ ์งํ๋, ์ ๊ธฐ์ค์ ๋ฐ๋ผ ๊ฐ์ ๋ ํ ์คํธ๋ง ์ถ๋ ฅ | |
- ๋ถ๊ฐ ์ค๋ช ์ด๋ ๋ฉํ ์ ๋ณด๋ ํฌํจํ์ง ์์ | |
""", | |
"๋ช ์ธ ์ธ์ฉํ๊ธฐ": """ | |
# ๋ชฉ์ : ๋ช ์ธ์ ํ์ฉํ ์ค๋๋ ฅ ์๋ ํ ์คํธ ๊ฐ์ | |
## ์ง์นจ | |
1. ๋ฌธ๋งฅ ๋ถ์ | |
- ํ ์คํธ์ ํต์ฌ ์ฃผ์ ์ ์๋ ํ์ | |
- ํ ์คํธ์ ๋ถ์๊ธฐ์ ํค ๋ถ์ | |
- ๋ ์์ธต๊ณผ ๋ชฉ์ ๊ณ ๋ ค | |
2. ์ ์ ํ ๋ช ์ธ ์ ํ | |
- ํ ์คํธ์ ์ฃผ์ ์ ์ง์ ์ ์ผ๋ก ์ฐ๊ด๋ ๋ช ์ธ ์ ํ | |
- ๋ค์ํ ๋ถ์ผ(์ฒ ํ, ๋ฌธํ, ์ญ์ฌ, ๊ณผํ ๋ฑ)์ ๋ช ์ธ ๊ณ ๋ ค | |
- ๊ณ ์ ์ ์ธ ๋ช ์ธ๋ฟ๋ง ์๋๋ผ ํ๋ ์ ๋ช ์ธ(์ฐ์์ธ, ๊ธฐ์ ์ธ, ์ด๋์ ์, ์ ์น์ธ ๋ฑ)์ ์ธ์์ ์ธ ๋ง๋ ์ ๊ทน ํ์ฉ | |
- ํ๊ตญ ๋ฐ ์ธ๊ณ์ ์ ๋ช ํ ์ธ๋ฌผ์ ๋ช ์ธ ํ์ฉ | |
- ํ ์คํธ์ ํค๊ณผ ๋ถ์๊ธฐ์ ์ด์ธ๋ฆฌ๋ ๋ช ์ธ ์ ํ | |
- ๊ฐ๋ฅํ๋ฉด ์์์ ์ ํ๊ณ ์ต์ ํธ๋ ๋๋ฅผ ๋ฐ์ํ ํ๋์ ๋ช ์ธ ์ฐ์ ๊ณ ๋ ค | |
3. ๋ช ์ธ ํตํฉ | |
- ํ ์คํธ ๋ด ๊ฐ์ฅ ํจ๊ณผ์ ์ธ ์์น์ ๋ช ์ธ ๋ฐฐ์น (์์, ์ค๊ฐ, ๋๋ ๊ฒฐ๋ก ) | |
- ๋ช ์ธ์ ์์ฐ์ค๋ฝ๊ฒ ๋์ ํ์ฌ ๊ธฐ์กด ํ ์คํธ์ ์กฐํ๋กญ๊ฒ ํตํฉ | |
- ํ์์ ๋ช ์ธ์ ์ถ์ฒ(์ธ๋ฌผ ์ด๋ฆ) ํฌํจ | |
- ๋ฑ ํ ๋ฒ๋ง ๋ช ์ธ ์ธ์ฉํ๊ธฐ | |
- ํ๋ ์ ๋ช ์ธ์ ๋ช ์ธ ์ฌ์ฉ ์ ๊ฐ๋จํ ๋งฅ๋ฝ ์ค๋ช ๊ณ ๋ ค(ํ์ํ ๊ฒฝ์ฐ) | |
4. ์ ์ฒด ํ ์คํธ ์กฐ์ | |
- ๋ช ์ธ ๋์ ํ ํ์์ ์ ํ ๋ฌธ์ฅ ์กฐ์ ํ์ฌ ์์ฐ์ค๋ฌ์ด ํ๋ฆ ์ ์ง | |
- ์๋ณธ ํ ์คํธ์ ํต์ฌ ๋ฉ์์ง์ ์๋ ๋ณด์กด | |
- ์ ์ฒด์ ์ธ ์ผ๊ด์ฑ๊ณผ ์์ง๋ ฅ ์ ์ง | |
- ๋ช ์ธ์ด ํ ์คํธ์ ์ ์ ํจ๊ณผ ๊ถ์๋ฅผ ๋ถ์ฌํ๋์ง ํ์ธ | |
## ์ถ๋ ฅ ํ์ | |
- ๋ช ์ธ์ด ์์ฐ์ค๋ฝ๊ฒ ํตํฉ๋ ๊ฐ์ ๋ ํ ์คํธ๋ง ์ถ๋ ฅ | |
- ๋ถ๊ฐ ์ค๋ช ์ด๋ ๋ฉํ ์ ๋ณด ์์ด ์์ํ๊ฒ ๊ฐ์ ๋ ํ ์คํธ๋ง ์ ๊ณต | |
""", | |
"๋ง์ถคํ ๋ณํ": """ | |
# ๋ชฉ์ : ์ฌ์ฉ์ ์ ์ ํ๋ฅด์๋์ ๋ชฉ์ ์ ๋ง๋ ํ ์คํธ ๋ณํ | |
## ์ง์นจ | |
1. ํ๋ฅด์๋ ๋ถ์ ๋ฐ ์ ์ฉ | |
- ์ฌ์ฉ์๊ฐ ์ ๊ณตํ ํ๋ฅด์๋์ ํน์ฑ ๋ถ์ (๋งํฌ, ์ดํ ์ ํ, ๋ฌธ์ฅ ๊ตฌ์กฐ ๋ฑ) | |
- ํด๋น ํ๋ฅด์๋๊ฐ ์ค์ ๋ก ์์ฑํ์ ๋ฒํ ์คํ์ผ๋ก ํ ์คํธ ์ฌ๊ตฌ์ฑ | |
- ํ๋ฅด์๋์ ๊ณ ์ ํ ํํ ๋ฐฉ์๊ณผ ๊ด์ ๋ฐ์ | |
2. ๋ชฉ์ ๋ถ์ ๋ฐ ์ ์ฉ | |
- ์ฌ์ฉ์๊ฐ ๋ช ์ํ ๋ชฉ์ ์ ๋ง๊ฒ ํ ์คํธ์ ์ ๋ฐ์ ์ธ ๋ฐฉํฅ์ฑ ์กฐ์ | |
- ๋ชฉ์ ์ ๋ง๋ ๊ตฌ์กฐ, ๋ ผ์กฐ, ๊ฐ์กฐ์ ์ค์ | |
- ๋ชฉ์ ๋ฌ์ฑ์ ํ์ํ ์์ ๊ฐํ ๋ฐ ๋ถํ์ํ ์์ ์ ๊ฑฐ | |
3. ํ ์คํธ ๋ง์ถค ๋ณํ | |
- ํ๋ฅด์๋์ ๋ชฉ์ ์ ์ข ํฉ์ ์ผ๋ก ๊ณ ๋ คํ ํ ์คํธ ๋ณํ | |
- ์๋ณธ ํ ์คํธ์ ํต์ฌ ์ ๋ณด์ ์ฃผ์ ๋ ผ์ ์ ์ง | |
- ์ดํ, ๋ฌธ์ฅ ๊ตฌ์กฐ, ๋น์ , ์์ ๋ฑ์ ํ๋ฅด์๋์ ๋ชฉ์ ์ ๋ง๊ฒ ์กฐ์ | |
- ์ ์ฒด์ ์ธ ์ผ๊ด์ฑ๊ณผ ์ง์ ์ฑ ์ ์ง | |
4. ํ์ง ๋ฐ ํจ๊ณผ ์ต์ ํ | |
- ๋ช ํ์ฑ๊ณผ ์ดํด๋ ํฅ์ | |
- ์ค๋๋ ฅ๊ณผ ํธ์๋ ฅ ๊ฐํ | |
- ๋ ์ฐฝ์ฑ๊ณผ ์ฐธ์ ํจ ์ถ๊ตฌ | |
- ๋ชฉํ ๋ ์์๊ฒ ํจ๊ณผ์ ์ผ๋ก ์ ๋ฌ๋ ์ ์๋ ํํ๋ก ์ต์ ํ | |
## ์ถ๋ ฅ ํ์ | |
- ํ๋ฅด์๋์ ๋ชฉ์ ์ ๋ง๊ฒ ๋ณํ๋ ํ ์คํธ๋ง ์ถ๋ ฅ | |
- ๋ถ๊ฐ ์ค๋ช ์ด๋ ๋ฉํ ์ ๋ณด ์์ด ์์ํ๊ฒ ๋ณํ๋ ํ ์คํธ๋ง ์ ๊ณต | |
- ์ฌ์ฉ์๊ฐ ๋ช ์ํ ๋ชฉ์ ๊ณผ ํ๋ฅด์๋์ ํน์ฑ์ด ๋ช ํํ ๋๋ฌ๋๋ ๊ฒฐ๊ณผ๋ฌผ ์ ๊ณต | |
""", | |
} | |
def process_text(input_text, improvement_type, custom_purpose, persona, temperature, top_p): | |
"""Gemini ๋ชจ๋ธ์ฉ ํ ์คํธ ์ฒ๋ฆฌ ํจ์""" | |
try: | |
print("ํ ์คํธ ์ฒ๋ฆฌ ์์") | |
request_id = str(uuid.uuid4())[:8] | |
timestamp_micro = int(time.time() * 1000000) % 1000 | |
if improvement_type == "๋ง์ถคํ ๋ณํ": | |
purpose = f"๋ค์ ํ๋ฅด์๋๋ฅผ ๊ฐ์ง๊ณ ํ ์คํธ๋ฅผ ๋ค๋ฌ์ผ์ธ์: {persona}\n\n๋ชฉ์ : {custom_purpose}" | |
else: | |
purpose = GEMINI_PROMPTS[improvement_type] | |
model = genai.GenerativeModel( | |
model_name="gemini-2.0-flash", | |
generation_config={ | |
"temperature": temperature, | |
"top_p": top_p, | |
"max_output_tokens": 2000, | |
} | |
) | |
# ์์คํ ์ง์์ฌํญ์ ์ฒซ ๋ฒ์งธ ์ฌ์ฉ์ ๋ฉ์์ง์ ํฌํจ | |
prompt = f"REQ-{request_id}-{timestamp_micro}\n\n๋ค์ ํ ์คํธ๋ฅผ ๋ชฉ์ ์ ๋ง๊ฒ ๋ค๋ฌ์ด์ฃผ์ธ์.\n\nํ ์คํธ: {input_text}\n\n๋ชฉ์ : {purpose}" | |
response = model.generate_content(prompt) | |
print("ํ ์คํธ ์ฒ๋ฆฌ ์๋ฃ") | |
return response.text | |
except Exception as e: | |
print("ํ ์คํธ ์ฒ๋ฆฌ ์คํจ") | |
logger.error(f"์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}") | |
return f"์ค๋ฅ ๋ฐ์: {str(e)}" | |
def create_interface(): | |
# FontAwesome ์์ด์ฝ ํฌํจ | |
fontawesome = """ | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" /> | |
""" | |
# ์ปค์คํ CSS ์คํ์ผ | |
css = """ | |
:root { | |
--primary-color: #FF7F00; | |
--secondary-color: #ff9a8b; | |
--accent-color: #FF6B6B; | |
--background-color: #FFF8F0; | |
--card-bg: #ffffff; | |
--text-color: #334155; | |
--border-radius: 18px; | |
--shadow: 0 8px 30px rgba(251, 127, 13, 0.08); | |
} | |
body { | |
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif; | |
background-color: var(--background-color); | |
color: var(--text-color); | |
line-height: 1.6; | |
} | |
footer { | |
visibility: hidden; | |
} | |
.container { | |
max-width: 1200px; | |
margin: 0 auto; | |
} | |
.header { | |
background: linear-gradient(135deg, #FF7F00, #FF9A5B); | |
padding: 2rem; | |
border-radius: 15px; | |
margin-bottom: 20px; | |
box-shadow: var(--shadow); | |
text-align: center; | |
color: white; | |
} | |
.header h1 { | |
margin: 0; | |
font-size: 2.5rem; | |
font-weight: 700; | |
} | |
.header p { | |
margin: 10px 0 0; | |
font-size: 1.2rem; | |
opacity: 0.9; | |
} | |
.card { | |
background-color: var(--card-bg); | |
border-radius: var(--border-radius); | |
padding: 20px; | |
margin: 10px 0; | |
box-shadow: var(--shadow); | |
border: 1px solid rgba(0, 0, 0, 0.04); | |
} | |
.button-primary { | |
border-radius: 30px !important; | |
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)) !important; | |
color: white !important; | |
font-size: 18px !important; | |
padding: 10px 20px !important; | |
border: none; | |
box-shadow: 0 4px 8px rgba(251, 127, 13, 0.25); | |
transition: transform 0.3s ease; | |
text-align: center; | |
font-weight: 600; | |
} | |
.button-primary:hover { | |
transform: translateY(-2px); | |
box-shadow: 0 6px 12px rgba(251, 127, 13, 0.3); | |
} | |
.section-title { | |
display: flex; | |
align-items: center; | |
font-size: 20px; | |
font-weight: 700; | |
color: #333333; | |
margin-bottom: 15px; | |
padding-bottom: 8px; | |
border-bottom: 2px solid #FF7F00; | |
} | |
.section-title i { | |
margin-right: 10px; | |
color: #FF7F00; | |
} | |
.guide-container { | |
background-color: #FFF0E2; | |
border-radius: var(--border-radius); | |
padding: 1.5rem; | |
margin-bottom: 1.5rem; | |
border: 1px solid rgba(255, 127, 0, 0.1); | |
} | |
.guide-title { | |
font-size: 1.3rem; | |
font-weight: 700; | |
color: var(--primary-color); | |
margin-bottom: 1rem; | |
display: flex; | |
align-items: center; | |
} | |
.guide-title i { | |
margin-right: 0.8rem; | |
font-size: 1.3rem; | |
} | |
.guide-item { | |
display: flex; | |
margin-bottom: 0.8rem; | |
align-items: flex-start; | |
} | |
.guide-number { | |
background-color: var(--primary-color); | |
color: white; | |
width: 24px; | |
height: 24px; | |
border-radius: 50%; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
font-weight: bold; | |
margin-right: 10px; | |
flex-shrink: 0; | |
font-size: 14px; | |
} | |
.guide-text { | |
flex: 1; | |
line-height: 1.6; | |
} | |
.feature-tag { | |
display: inline-block; | |
background-color: rgba(255, 127, 0, 0.1); | |
color: #FF7F00; | |
padding: 3px 10px; | |
border-radius: 12px; | |
font-size: 14px; | |
font-weight: 600; | |
margin-right: 8px; | |
margin-bottom: 8px; | |
} | |
.input-label { | |
font-weight: 600; | |
margin-bottom: 8px; | |
color: #444; | |
} | |
/* ๊ทธ๋ผ๋์ค ์์ ์คํ์ผ ์ปค์คํฐ๋ง์ด์ง */ | |
.gr-input, .gr-text-input, .gr-sample-inputs { | |
border-radius: var(--border-radius) !important; | |
border: 1px solid #e5e7eb !important; | |
padding: 12px !important; | |
transition: all 0.3s ease !important; | |
} | |
.gr-input:focus, .gr-text-input:focus { | |
border-color: var(--primary-color) !important; | |
outline: none !important; | |
box-shadow: 0 0 0 2px rgba(251, 127, 13, 0.2) !important; | |
} | |
/* ์คํฌ๋กค๋ฐ ์คํ์ผ๋ง */ | |
::-webkit-scrollbar { | |
width: 8px; | |
height: 8px; | |
} | |
::-webkit-scrollbar-track { | |
background: rgba(0, 0, 0, 0.05); | |
border-radius: 10px; | |
} | |
::-webkit-scrollbar-thumb { | |
background: var(--primary-color); | |
border-radius: 10px; | |
} | |
""" | |
with gr.Blocks(css=css, theme=gr.themes.Soft( | |
primary_hue=gr.themes.Color( | |
c50="#FFF7ED", | |
c100="#FFEDD5", | |
c200="#FED7AA", | |
c300="#FDBA74", | |
c400="#FB923C", | |
c500="#F97316", | |
c600="#EA580C", | |
c700="#C2410C", | |
c800="#9A3412", | |
c900="#7C2D12", | |
c950="#431407", | |
), | |
secondary_hue="zinc", | |
neutral_hue="zinc", | |
font=("Pretendard", "sans-serif") | |
)) as demo: | |
gr.HTML(fontawesome) | |
with gr.Row(): | |
with gr.Column(scale=1): | |
# ์ผ์ชฝ ์ ๋ ฅ ์์ญ | |
with gr.Column(elem_classes="card"): | |
gr.HTML('<div class="section-title"><i class="fas fa-edit"></i> ์๋ณธ ํ ์คํธ</div>') | |
input_text = gr.Textbox( | |
label="", | |
placeholder="์ฌ๊ธฐ์ ๊ฐ์ ํ๊ณ ์ถ์ ํ ์คํธ๋ฅผ ์ ๋ ฅํ์ธ์...", | |
lines=15 | |
) | |
with gr.Column(elem_classes="card"): | |
gr.HTML('<div class="section-title"><i class="fas fa-sliders"></i> ๋ณํ ์ค์ </div>') | |
improvement_type = gr.Radio( | |
choices=["๋ง์ถค๋ฒ ๊ฒ์ฌ๊ธฐ", "๊ธ ๋ค๋ฌ๊ธฐ", "๋ช ์ธ ์ธ์ฉํ๊ธฐ", "๋ง์ถคํ ๋ณํ"], | |
label="๋ณํ ์ ํ ์ ํ", | |
value="๋ง์ถค๋ฒ ๊ฒ์ฌ๊ธฐ" | |
) | |
# ๋ง์ถคํ ๋ณํ ์ต์ ๋ค | |
custom_purpose = gr.Textbox( | |
label="๋ณํ ๋ชฉ์ ", | |
placeholder="ํ ์คํธ๋ฅผ ์ด๋ค ๋ฐฉํฅ์ผ๋ก ๋ณํํ๊ณ ์ถ์ผ์ ์ง ์ค๋ช ํด์ฃผ์ธ์...", | |
lines=2, | |
visible=False | |
) | |
persona = gr.Textbox( | |
label="ํ๋ฅด์๋ ์ค์ ", | |
placeholder="์ด๋ค ์ญํ ์ด๋ ์ฑ๊ฒฉ์ ๊ฐ์ง ๊ธ์ฐ๊ธฐ ์คํ์ผ์ ์ํ์๋์? (์: ์ ๋จธ๋ฌ์คํ ๊ฐ๊ทธ๋งจ, ์ ๋ฌธ์ ์ธ ๋ถ์๊ฐ)", | |
lines=2, | |
visible=False | |
) | |
with gr.Row(visible=False) as generation_settings: | |
temperature = gr.Slider( | |
minimum=0.0, | |
maximum=1.0, | |
value=0.7, | |
step=0.1, | |
label="์ฐฝ์์ฑ ์์ค", | |
info="๋์์๋ก ๋ ์ฐฝ์์ ์ธ ๊ฒฐ๊ณผ๊ฐ ์์ฑ๋ฉ๋๋ค" | |
) | |
top_p = gr.Slider( | |
minimum=0.0, | |
maximum=1.0, | |
value=0.9, | |
step=0.1, | |
label="๋ค์์ฑ ์์ค", | |
info="๋์์๋ก ๋ ๋ค์ํ ํํ์ ์ฌ์ฉํฉ๋๋ค" | |
) | |
submit_btn = gr.Button( | |
"โจ ํ ์คํธ ๋ณํํ๊ธฐ", | |
elem_classes="button-primary" | |
) | |
with gr.Column(scale=1): | |
# ์ค๋ฅธ์ชฝ ์ถ๋ ฅ ์์ญ | |
with gr.Column(elem_classes="card"): | |
gr.HTML('<div class="section-title"><i class="fas fa-wand-magic-sparkles"></i> ๋ณํ๋ ํ ์คํธ</div>') | |
output_text = gr.Textbox( | |
label="", | |
lines=22, | |
show_copy_button=True | |
) | |
def update_custom_inputs_visibility(choice): | |
is_custom = choice == "๋ง์ถคํ ๋ณํ" | |
return { | |
custom_purpose: gr.update(visible=is_custom), | |
persona: gr.update(visible=is_custom), | |
generation_settings: gr.update(visible=is_custom) | |
} | |
improvement_type.change( | |
fn=update_custom_inputs_visibility, | |
inputs=[improvement_type], | |
outputs=[custom_purpose, persona, generation_settings] | |
) | |
submit_btn.click( | |
fn=process_text, | |
inputs=[input_text, improvement_type, custom_purpose, persona, temperature, top_p], | |
outputs=output_text, | |
api_name="improve_text" | |
) | |
return demo | |
if __name__ == "__main__": | |
logger.info("์ ํ๋ฆฌ์ผ์ด์ ์์") | |
demo = create_interface() | |
demo.queue() | |
demo.launch() |