Update app.py
Browse files
app.py
CHANGED
|
@@ -14,16 +14,28 @@ if API_KEY:
|
|
| 14 |
else:
|
| 15 |
raise ValueError("API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. Hugging Face Spaces์ Repository secrets์ 'GOOGLE_API_KEY'๋ฅผ ์ค์ ํด์ฃผ์ธ์.")
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
model = SentenceTransformer('jhgan/ko-sbert-nli')
|
| 22 |
|
| 23 |
-
print("๋ฐ์ดํฐ์
์๋ฒ ๋ฉ์
|
| 24 |
df['embedding'] = df['์ ์ '].apply(lambda x: model.encode(x))
|
| 25 |
print("์๋ฒ ๋ฉ ๊ณ์ฐ์ด ์๋ฃ๋์์ต๋๋ค! ์ด์ ์ฑ๋ด ์๋ต์ด ํจ์ฌ ๋นจ๋ผ์ง๋๋ค.")
|
| 26 |
|
|
|
|
| 27 |
def call_gemini_api(question):
|
| 28 |
try:
|
| 29 |
llm_model = genai.GenerativeModel('gemini-2.0-flash')
|
|
@@ -58,8 +70,8 @@ demo = gr.Interface(
|
|
| 58 |
fn=chatbot,
|
| 59 |
inputs=gr.Textbox(lines=2, placeholder="์ง๋ฌธ์ ์
๋ ฅํด ์ฃผ์ธ์...", label="์ง๋ฌธ", elem_id="user_question_input"),
|
| 60 |
outputs=gr.Textbox(lines=5, label="์ฑ๋ด ๋ต๋ณ"),
|
| 61 |
-
title="๋๋ ์๋ด ์ฑ๋ด",
|
| 62 |
-
description="5๋ถ ๋์ ๋ํํ์ฌ ์ฃผ์๊ณ ๋ค์์ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ๊ผญ ์ค๋ฌธ์กฐ์ฌ์ ์ฐธ์ฌํด์ฃผ์ธ์! https://forms.gle/eWtyejQaQntKbbxG8"
|
| 63 |
)
|
| 64 |
|
| 65 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|
|
| 14 |
else:
|
| 15 |
raise ValueError("API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. Hugging Face Spaces์ Repository secrets์ 'GOOGLE_API_KEY'๋ฅผ ์ค์ ํด์ฃผ์ธ์.")
|
| 16 |
|
| 17 |
+
# 1. ๊ธฐ์กด ๋ฐ์ดํฐ ๋ก๋ ๋ฐ ์ ์ฒ๋ฆฌ
|
| 18 |
+
original_df = pd.read_csv('https://raw.githubusercontent.com/kairess/mental-health-chatbot/master/wellness_dataset_original.csv')
|
| 19 |
+
original_df = original_df.drop(columns=['Unnamed: 3'], errors='ignore')
|
| 20 |
+
original_df = original_df.dropna(subset=['์ ์ ', '์ฑ๋ด'])
|
| 21 |
+
|
| 22 |
+
# 2. ์๋ก์ด ๋ฐ์ดํฐ์
๋ก๋ ๋ฐ ์ ์ฒ๋ฆฌ
|
| 23 |
+
new_data_url = 'https://gist.githubusercontent.com/kimminchear/469d84e61bad0334b34a58a030e4a27a/raw/260bde0f335b2bb365a9837e6a6105a93b0b957d/2025_gpdba.csv'
|
| 24 |
+
new_df = pd.read_csv(new_data_url)
|
| 25 |
+
# ์๋ก์ด ๋ฐ์ดํฐ์
์ ์ปฌ๋ผ๋ช
์ด '์ ์ '์ '์ฑ๋ด'๊ณผ ๋ค๋ฅผ ๊ฒฝ์ฐ, ์ฌ๊ธฐ์ ๋ง์ถฐ์ ๋ณ๊ฒฝํด์ผ ํฉ๋๋ค.
|
| 26 |
+
# ์์: new_df = new_df.rename(columns={'์ง๋ฌธ': '์ ์ ', '๋ต๋ณ': '์ฑ๋ด'})
|
| 27 |
+
new_df = new_df.dropna(subset=['์ ์ ', '์ฑ๋ด']) # ๊ฒฐ์ธก๊ฐ ์ ๊ฑฐ
|
| 28 |
+
|
| 29 |
+
# 3. ๋ ๋ฐ์ดํฐํ๋ ์ ๋ณํฉ (concatenate)
|
| 30 |
+
df = pd.concat([original_df, new_df], ignore_index=True)
|
| 31 |
|
| 32 |
model = SentenceTransformer('jhgan/ko-sbert-nli')
|
| 33 |
|
| 34 |
+
print(f"์ด {len(df)}๊ฐ์ ์ง๋ฌธ-๋ต๋ณ ์์ ๋ํด ๋ฐ์ดํฐ์
์๋ฒ ๋ฉ์ ๋ค์ ๊ณ์ฐ ์ค์
๋๋ค. ์ด ๊ณผ์ ์ ์๊ฐ์ด ์์๋ฉ๋๋ค...")
|
| 35 |
df['embedding'] = df['์ ์ '].apply(lambda x: model.encode(x))
|
| 36 |
print("์๋ฒ ๋ฉ ๊ณ์ฐ์ด ์๋ฃ๋์์ต๋๋ค! ์ด์ ์ฑ๋ด ์๋ต์ด ํจ์ฌ ๋นจ๋ผ์ง๋๋ค.")
|
| 37 |
|
| 38 |
+
# ๋๋จธ์ง ํจ์๋ ๋์ผํฉ๋๋ค.
|
| 39 |
def call_gemini_api(question):
|
| 40 |
try:
|
| 41 |
llm_model = genai.GenerativeModel('gemini-2.0-flash')
|
|
|
|
| 70 |
fn=chatbot,
|
| 71 |
inputs=gr.Textbox(lines=2, placeholder="์ง๋ฌธ์ ์
๋ ฅํด ์ฃผ์ธ์...", label="์ง๋ฌธ", elem_id="user_question_input"),
|
| 72 |
outputs=gr.Textbox(lines=5, label="์ฑ๋ด ๋ต๋ณ"),
|
| 73 |
+
title="๋๋ ์๋ด ์ฑ๋ด 2.0",
|
| 74 |
+
description="๋ฐ์ดํฐ์
์ด ํ์ฅ๋์ด ๋ ๋ง์ ์ง๋ฌธ์ ๋ํด ์ ํํ ๋ต๋ณ์ ์ ๊ณตํฉ๋๋ค. 5๋ถ ๋์ ๋ํํ์ฌ ์ฃผ์๊ณ ๋ค์์ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ๊ผญ ์ค๋ฌธ์กฐ์ฌ์ ์ฐธ์ฌํด์ฃผ์ธ์! https://forms.gle/eWtyejQaQntKbbxG8"
|
| 75 |
)
|
| 76 |
|
| 77 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|