Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,10 @@ import gradio as gr
|
|
2 |
import google.generativeai as genai
|
3 |
import os
|
4 |
|
|
|
|
|
|
|
|
|
5 |
# API ν€ μ€μ
|
6 |
api_key = os.environ.get("GEMINI_API_KEY")
|
7 |
if api_key:
|
@@ -9,11 +13,18 @@ if api_key:
|
|
9 |
|
10 |
def chat(message, history):
|
11 |
if not api_key:
|
12 |
-
return "β API ν€κ° μ€μ λμ§ μμμ΅λλ€.
|
13 |
|
|
|
|
|
14 |
try:
|
15 |
-
#
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# λν κΈ°λ‘ λ³ν
|
19 |
chat_history = []
|
@@ -33,12 +44,12 @@ def chat(message, history):
|
|
33 |
except Exception as e:
|
34 |
return f"β μ€λ₯ λ°μ: {str(e)}"
|
35 |
|
36 |
-
# Gradio μΈν°νμ΄μ€
|
37 |
demo = gr.ChatInterface(
|
38 |
fn=chat,
|
39 |
-
title="π€ Gemini μ±λ΄",
|
40 |
-
description="
|
41 |
-
examples=["
|
42 |
)
|
43 |
|
44 |
if __name__ == "__main__":
|
|
|
2 |
import google.generativeai as genai
|
3 |
import os
|
4 |
|
5 |
+
# --- 1. μ±λ΄μ μν (μμ€ν
ν둬ννΈ)μ μ¬κΈ°μ μ μν©λλ€. ---
|
6 |
+
# μμ: IT λ° μ½λ© μ§λ¬Έμ μ λ¬Έμ μΌλ‘ λ΅λ³νλ AI μ΄μμ€ν΄νΈ
|
7 |
+
SYSTEM_PROMPT = "λ°ν λλ³Έμ λ§λ€μ΄μ£Όλ μ±λ΄μ
λλ€. λ°νν λ΄μ©μ μ
λ ₯νλ©΄ 'μλνλ©΄ ~μ΄κΈ° λλ¬Έμ
λλ€'λ‘ λλ³Έμ λ§λ€μ΄μ€λλ€"
|
8 |
+
|
9 |
# API ν€ μ€μ
|
10 |
api_key = os.environ.get("GEMINI_API_KEY")
|
11 |
if api_key:
|
|
|
13 |
|
14 |
def chat(message, history):
|
15 |
if not api_key:
|
16 |
+
return "β API ν€κ° μ€μ λμ§ μμμ΅λλ€. Hugging Face Spacesμ Settingsμμ GEMINI_API_KEYλ₯Ό SecretμΌλ‘ μΆκ°νμΈμ."
|
17 |
|
18 |
+
# --- 2. ꡬ문 μ€λ₯ μμ ---
|
19 |
+
# try λΈλ‘μ΄ if λ¬Έκ³Ό λμΌν λ 벨μ μλλ‘ λ€μ¬μ°κΈ°λ₯Ό μμ νμ΅λλ€.
|
20 |
try:
|
21 |
+
# --- 3. λͺ¨λΈ μ΄κΈ°ν μ μμ€ν
ν둬ννΈ μ μ© ---
|
22 |
+
# μμ€ν
ν둬ννΈλ₯Ό μ§μνλ 곡μ λͺ¨λΈλͺ
(gemini-1.5-flash)μΌλ‘ μμ νκ³ ,
|
23 |
+
# system_instruction νλΌλ―Έν°μ μμμ μ μν ν둬ννΈλ₯Ό μ λ¬ν©λλ€.
|
24 |
+
model = genai.GenerativeModel(
|
25 |
+
'gemini-2.0-flash',
|
26 |
+
system_instruction=SYSTEM_PROMPT
|
27 |
+
)
|
28 |
|
29 |
# λν κΈ°λ‘ λ³ν
|
30 |
chat_history = []
|
|
|
44 |
except Exception as e:
|
45 |
return f"β μ€λ₯ λ°μ: {str(e)}"
|
46 |
|
47 |
+
# Gradio μΈν°νμ΄μ€ (μμ²λλ‘ κ·Έλλ‘ μ μ§)
|
48 |
demo = gr.ChatInterface(
|
49 |
fn=chat,
|
50 |
+
title="π€ λ
Όλ¦¬μ μΌλ‘ λ§νλ λ°νλμ°λ―Έ Gemini μ±λ΄",
|
51 |
+
description="λ
Όλ¦¬μ μΌλ‘ λ°ννλ λ°©λ²μ λμμ€λλ€.",
|
52 |
+
examples=["νκΈνμλ λ§νλ λ°©λ²", "κ΅μ΄μκ°μ μ£Όμ₯νλ λ§ νλ λ°©λ²", "μ¬ννμμ λν μ견"],
|
53 |
)
|
54 |
|
55 |
if __name__ == "__main__":
|