Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,4 @@
|
|
1 |
-
|
2 |
-
# 2.0 λ²μ μ© μμ μ μΈ API νΈμΆ
|
3 |
-
response = self.model.generate_content(
|
4 |
-
contents=f"{system_prompt}\n\nμ¬μ©μ μ§λ¬Έ: {message}",
|
5 |
-
generation_config=genai.GenerationConfig(
|
6 |
-
temperature=0.1,
|
7 |
-
max_output_tokens=1000,
|
8 |
-
),
|
9 |
-
stream=True
|
10 |
-
)
|
11 |
-
|
12 |
-
partial_message = ""
|
13 |
-
for chunk in response:
|
14 |
-
try:
|
15 |
-
if chunk.text:
|
16 |
-
partial_message += chunk.text
|
17 |
-
yield partial_message
|
18 |
-
except Exception as chunk_error:
|
19 |
-
# κ°λ³ μ²ν¬ μλ¬λ 무μνκ³ κ³μ μ§ν
|
20 |
-
continue
|
21 |
-
|
22 |
-
except Exception as e:
|
23 |
-
# μλ¬ λ΄μ©μ λ μμΈν 보기 μν΄
|
24 |
-
print(f"μλ¬ λ°μ: {str(e)}")
|
25 |
-
|
26 |
-
# μ€νΈλ¦¬λ°μ΄ μλλ©΄ μΌλ° λ°©μμΌλ‘ μλ
|
27 |
-
try:
|
28 |
-
response = self.model.generate_content(
|
29 |
-
contents=f"{system_prompt}\n\nμ¬μ©μ μ§λ¬Έ: {message}",
|
30 |
-
generation_config=genai.GenerationConfig(
|
31 |
-
temperature=0.1,
|
32 |
-
max_output_tokens=1000,
|
33 |
-
),
|
34 |
-
stream=False
|
35 |
-
)
|
36 |
-
yield response.text
|
37 |
-
except Exception as fallback_error:
|
38 |
-
print(f"Fallback μλ¬: {str(fallback_error)}")
|
39 |
-
yield f"μ£μ‘ν©λλ€. μμ€ν
μ€λ₯κ° λ°μνμ΅λλ€. κ³ κ°μΌν°(010-8082-0047)λ‘ μ°λ½ν΄μ£ΌμΈμ."import gradio as gr
|
40 |
import google.generativeai as genai
|
41 |
import os
|
42 |
|
@@ -49,7 +11,6 @@ class SimpleBanchanChatbot:
|
|
49 |
|
50 |
# μ λ―Έλμ΄ ν΄λΌμ΄μΈνΈ μ€μ
|
51 |
genai.configure(api_key=api_key)
|
52 |
-
# 2.0 λ²μ μ¬μ©
|
53 |
self.model = genai.GenerativeModel('gemini-2.0-flash-exp')
|
54 |
|
55 |
# μμ
μμ μΆμΆν λͺ¨λ FAQ λ°μ΄ν°
|
@@ -156,23 +117,38 @@ class SimpleBanchanChatbot:
|
|
156 |
|
157 |
try:
|
158 |
response = self.model.generate_content(
|
159 |
-
message,
|
160 |
-
generation_config=genai.
|
161 |
temperature=0.1,
|
162 |
max_output_tokens=1000,
|
163 |
),
|
164 |
-
system_instruction=system_prompt,
|
165 |
stream=True
|
166 |
)
|
167 |
|
168 |
partial_message = ""
|
169 |
for chunk in response:
|
170 |
-
|
171 |
-
|
172 |
-
|
|
|
|
|
|
|
173 |
|
174 |
except Exception as e:
|
175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
|
177 |
# μ±λ΄ μΈμ€ν΄μ€ μμ±
|
178 |
try:
|
@@ -203,7 +179,6 @@ try:
|
|
203 |
)
|
204 |
|
205 |
except Exception as e:
|
206 |
-
# API ν€κ° μμ λ μλ¬ λ©μμ§ νμ
|
207 |
def error_message(message, history):
|
208 |
yield "β GEMINI_API_KEYκ° μ€μ λμ§ μμμ΅λλ€. κ΄λ¦¬μμκ² λ¬ΈμνμΈμ."
|
209 |
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import google.generativeai as genai
|
3 |
import os
|
4 |
|
|
|
11 |
|
12 |
# μ λ―Έλμ΄ ν΄λΌμ΄μΈνΈ μ€μ
|
13 |
genai.configure(api_key=api_key)
|
|
|
14 |
self.model = genai.GenerativeModel('gemini-2.0-flash-exp')
|
15 |
|
16 |
# μμ
μμ μΆμΆν λͺ¨λ FAQ λ°μ΄ν°
|
|
|
117 |
|
118 |
try:
|
119 |
response = self.model.generate_content(
|
120 |
+
contents=f"{system_prompt}\n\nμ¬μ©μ μ§λ¬Έ: {message}",
|
121 |
+
generation_config=genai.GenerationConfig(
|
122 |
temperature=0.1,
|
123 |
max_output_tokens=1000,
|
124 |
),
|
|
|
125 |
stream=True
|
126 |
)
|
127 |
|
128 |
partial_message = ""
|
129 |
for chunk in response:
|
130 |
+
try:
|
131 |
+
if chunk.text:
|
132 |
+
partial_message += chunk.text
|
133 |
+
yield partial_message
|
134 |
+
except:
|
135 |
+
continue
|
136 |
|
137 |
except Exception as e:
|
138 |
+
print(f"μλ¬ λ°μ: {str(e)}")
|
139 |
+
try:
|
140 |
+
response = self.model.generate_content(
|
141 |
+
contents=f"{system_prompt}\n\nμ¬μ©μ μ§λ¬Έ: {message}",
|
142 |
+
generation_config=genai.GenerationConfig(
|
143 |
+
temperature=0.1,
|
144 |
+
max_output_tokens=1000,
|
145 |
+
),
|
146 |
+
stream=False
|
147 |
+
)
|
148 |
+
yield response.text
|
149 |
+
except Exception as fallback_error:
|
150 |
+
print(f"Fallback μλ¬: {str(fallback_error)}")
|
151 |
+
yield f"μ£μ‘ν©λλ€. μμ€ν
μ€λ₯κ° λ°μνμ΅λλ€. κ³ κ°μΌν°(010-8082-0047)λ‘ μ°λ½ν΄μ£ΌμΈμ."
|
152 |
|
153 |
# μ±λ΄ μΈμ€ν΄μ€ μμ±
|
154 |
try:
|
|
|
179 |
)
|
180 |
|
181 |
except Exception as e:
|
|
|
182 |
def error_message(message, history):
|
183 |
yield "β GEMINI_API_KEYκ° μ€μ λμ§ μμμ΅λλ€. κ΄λ¦¬μμκ² λ¬ΈμνμΈμ."
|
184 |
|