Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,42 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
|
@@ -11,6 +49,7 @@ class SimpleBanchanChatbot:
|
|
| 11 |
|
| 12 |
# ์ ๋ฏธ๋์ด ํด๋ผ์ด์ธํธ ์ค์
|
| 13 |
genai.configure(api_key=api_key)
|
|
|
|
| 14 |
self.model = genai.GenerativeModel('gemini-2.0-flash-exp')
|
| 15 |
|
| 16 |
# ์์
์์ ์ถ์ถํ ๋ชจ๋ FAQ ๋ฐ์ดํฐ
|
|
|
|
| 1 |
+
try:
|
| 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 |
|
| 50 |
# ์ ๋ฏธ๋์ด ํด๋ผ์ด์ธํธ ์ค์
|
| 51 |
genai.configure(api_key=api_key)
|
| 52 |
+
# 2.0 ๋ฒ์ ์ฌ์ฉ
|
| 53 |
self.model = genai.GenerativeModel('gemini-2.0-flash-exp')
|
| 54 |
|
| 55 |
# ์์
์์ ์ถ์ถํ ๋ชจ๋ FAQ ๋ฐ์ดํฐ
|