Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,14 @@ import os
|
|
4 |
|
5 |
class SimpleBanchanChatbot:
|
6 |
def __init__(self):
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# ์์
์์ ์ถ์ถํ ๋ชจ๋ FAQ ๋ฐ์ดํฐ
|
10 |
self.faq_data = """
|
@@ -105,16 +112,18 @@ class SimpleBanchanChatbot:
|
|
105 |
- FAQ์ ์๋ ๋ด์ฉ์ "์์ธํ ์ฌํญ์ ๊ณ ๊ฐ์ผํฐ(010-8082-0047)๋ก ๋ฌธ์ํด์ฃผ์ธ์"๋ผ๊ณ ์๋ดํด์ฃผ์ธ์
|
106 |
- ๋ฐ๋ง๋ณด๋ค๋ ์กด๋๋ง์ ์ฌ์ฉํด์ฃผ์ธ์
|
107 |
- ๊ฐ๊ฒฐํ๊ณ ์ดํดํ๊ธฐ ์ฝ๊ฒ ๋ต๋ณํด์ฃผ์ธ์
|
|
|
108 |
"""
|
109 |
|
110 |
try:
|
111 |
-
response = self.
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
118 |
)
|
119 |
|
120 |
partial_message = ""
|
@@ -124,35 +133,46 @@ class SimpleBanchanChatbot:
|
|
124 |
yield partial_message
|
125 |
|
126 |
except Exception as e:
|
127 |
-
yield f"์ฃ์กํฉ๋๋ค. ์์คํ
์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๊ณ ๊ฐ์ผํฐ(010-8082-0047)๋ก ์ฐ๋ฝํด์ฃผ์ธ์.
|
128 |
|
129 |
# ์ฑ๋ด ์ธ์คํด์ค ์์ฑ
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
if __name__ == "__main__":
|
154 |
-
demo.launch(
|
155 |
-
server_name="0.0.0.0",
|
156 |
-
server_port=7860,
|
157 |
-
share=True
|
158 |
-
)
|
|
|
4 |
|
5 |
class SimpleBanchanChatbot:
|
6 |
def __init__(self):
|
7 |
+
# ํ๊น
ํ์ด์ค ์คํ์ด์ค์์๋ secrets์์ API ํค ๊ฐ์ ธ์ค๊ธฐ
|
8 |
+
api_key = os.getenv("GEMINI_API_KEY")
|
9 |
+
if not api_key:
|
10 |
+
raise ValueError("GEMINI_API_KEY ํ๊ฒฝ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค!")
|
11 |
+
|
12 |
+
# ์ ๋ฏธ๋์ด ํด๋ผ์ด์ธํธ ์ค์
|
13 |
+
genai.configure(api_key=api_key)
|
14 |
+
self.model = genai.GenerativeModel('gemini-2.0-flash-exp')
|
15 |
|
16 |
# ์์
์์ ์ถ์ถํ ๋ชจ๋ FAQ ๋ฐ์ดํฐ
|
17 |
self.faq_data = """
|
|
|
112 |
- FAQ์ ์๋ ๋ด์ฉ์ "์์ธํ ์ฌํญ์ ๊ณ ๊ฐ์ผํฐ(010-8082-0047)๋ก ๋ฌธ์ํด์ฃผ์ธ์"๋ผ๊ณ ์๋ดํด์ฃผ์ธ์
|
113 |
- ๋ฐ๋ง๋ณด๋ค๋ ์กด๋๋ง์ ์ฌ์ฉํด์ฃผ์ธ์
|
114 |
- ๊ฐ๊ฒฐํ๊ณ ์ดํดํ๊ธฐ ์ฝ๊ฒ ๋ต๋ณํด์ฃผ์ธ์
|
115 |
+
- ์ธ์ฌ๋ง๋ก ์์ํ๊ณ ๊ฐ์ฌ์ธ์ฌ๋ก ๋ง๋ฌด๋ฆฌํด์ฃผ์ธ์
|
116 |
"""
|
117 |
|
118 |
try:
|
119 |
+
response = self.model.generate_content(
|
120 |
+
message,
|
121 |
+
generation_config=genai.types.GenerationConfig(
|
122 |
+
temperature=0.1,
|
123 |
+
max_output_tokens=1000,
|
124 |
+
),
|
125 |
+
system_instruction=system_prompt,
|
126 |
+
stream=True
|
127 |
)
|
128 |
|
129 |
partial_message = ""
|
|
|
133 |
yield partial_message
|
134 |
|
135 |
except Exception as e:
|
136 |
+
yield f"์ฃ์กํฉ๋๋ค. ์์คํ
์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๊ณ ๊ฐ์ผํฐ(010-8082-0047)๋ก ์ฐ๋ฝํด์ฃผ์ธ์."
|
137 |
|
138 |
# ์ฑ๋ด ์ธ์คํด์ค ์์ฑ
|
139 |
+
try:
|
140 |
+
chatbot = SimpleBanchanChatbot()
|
141 |
+
|
142 |
+
# ๊ทธ๋ผ๋์ค ์ธํฐํ์ด์ค
|
143 |
+
demo = gr.ChatInterface(
|
144 |
+
fn=chatbot.chat_stream,
|
145 |
+
title="๐ฅข ๋ง์๋๋ฐ์ฐฌ๊ฐ๊ฒ AI ์๋ด๋ด",
|
146 |
+
description="์ ๋ฏธ๋์ด 2.0 ๊ธฐ๋ฐ ๋ฐ์ฐฌ๊ฐ๊ฒ ๊ณ ๊ฐ ์๋ด๋ด์
๋๋ค. ๊ถ๊ธํ ๊ฒ์ ๋ฌผ์ด๋ณด์ธ์!",
|
147 |
+
examples=[
|
148 |
+
"์ฃผ๋ฌธ์ ์ด๋ป๊ฒ ํ๋์?",
|
149 |
+
"ํฌ์ธํธ๋ ์ด๋ป๊ฒ ์ฌ์ฉํ๋์?",
|
150 |
+
"๋ฐฐ์ก๋น๊ฐ ์ผ๋ง์ธ๊ฐ์?",
|
151 |
+
"ํ๋ถ ๋ฐฉ๋ฒ์ ์๋ ค์ฃผ์ธ์",
|
152 |
+
"์ ๊ธฐ์ ๊ตฌ์ฑ์ด ์ด๋ป๊ฒ ๋๋์?",
|
153 |
+
"ํ๊ธฐ ์ฐ๋ฉด ํํ์ด ์๋์?",
|
154 |
+
"๋ฐ์ฐฌ์ด ์ํ ๊ฒ ๊ฐ์์",
|
155 |
+
"์์ฐ์ง๋ฅผ ์๊ณ ์ถ์ด์"
|
156 |
+
],
|
157 |
+
theme=gr.themes.Soft(),
|
158 |
+
css="""
|
159 |
+
.gradio-container {
|
160 |
+
max-width: 800px !important;
|
161 |
+
margin: auto !important;
|
162 |
+
}
|
163 |
+
"""
|
164 |
+
)
|
165 |
+
|
166 |
+
except Exception as e:
|
167 |
+
# API ํค๊ฐ ์์ ๋ ์๋ฌ ๋ฉ์์ง ํ์
|
168 |
+
def error_message(message, history):
|
169 |
+
yield "โ GEMINI_API_KEY๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ๊ด๋ฆฌ์์๊ฒ ๋ฌธ์ํ์ธ์."
|
170 |
+
|
171 |
+
demo = gr.ChatInterface(
|
172 |
+
fn=error_message,
|
173 |
+
title="๐ฅข ์ค์ ์ค๋ฅ",
|
174 |
+
description="API ํค ์ค์ ์ด ํ์ํฉ๋๋ค."
|
175 |
+
)
|
176 |
|
177 |
if __name__ == "__main__":
|
178 |
+
demo.launch()
|
|
|
|
|
|
|
|