Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,6 +21,7 @@ def read_pdf(path):
|
|
| 21 |
def read_txt(path):
|
| 22 |
with open(path, "r", encoding="utf-8") as f:
|
| 23 |
return f.read()
|
|
|
|
| 24 |
AVATAR_IMAGE = "Joe.jpg"
|
| 25 |
linkedin_text = read_pdf("linkedin.pdf")
|
| 26 |
summary_text = read_txt("summary.txt")
|
|
@@ -54,7 +55,6 @@ def chat_fn(user_input, history):
|
|
| 54 |
model="gemini-2.5-flash",
|
| 55 |
contents=f"{prompt_context}\n\n使用者問題:{user_input}"
|
| 56 |
)
|
| 57 |
-
|
| 58 |
ai_text = response.text
|
| 59 |
|
| 60 |
eval_prompt = f"""
|
|
@@ -84,13 +84,34 @@ def chat_fn(user_input, history):
|
|
| 84 |
f"評語:{eval_data.comment}"
|
| 85 |
)
|
| 86 |
|
| 87 |
-
# ===== Step 6:
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
with gr.Blocks(
|
| 92 |
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="slate"),
|
| 93 |
-
title="AI Chatbot – Joe' Digital Twin"
|
|
|
|
| 94 |
) as demo:
|
| 95 |
with gr.Row():
|
| 96 |
with gr.Column(scale=1):
|
|
@@ -100,9 +121,10 @@ with gr.Blocks(
|
|
| 100 |
# 🤖 Joe' AI 聊天助理
|
| 101 |
<div style="color:#9ec5fe; font-size:1.1em;">
|
| 102 |
這是一個由 Gemini 模型驅動的個人化聊天機器人。<br>
|
| 103 |
-
它是Joe的代理人,能以專業且自然的語氣回覆您的問題。<br>
|
| 104 |
</div>
|
| 105 |
""")
|
|
|
|
| 106 |
gr.HTML("<hr style='border: 1px solid #1e3a8a;'>")
|
| 107 |
|
| 108 |
chat = gr.ChatInterface(
|
|
|
|
| 21 |
def read_txt(path):
|
| 22 |
with open(path, "r", encoding="utf-8") as f:
|
| 23 |
return f.read()
|
| 24 |
+
|
| 25 |
AVATAR_IMAGE = "Joe.jpg"
|
| 26 |
linkedin_text = read_pdf("linkedin.pdf")
|
| 27 |
summary_text = read_txt("summary.txt")
|
|
|
|
| 55 |
model="gemini-2.5-flash",
|
| 56 |
contents=f"{prompt_context}\n\n使用者問題:{user_input}"
|
| 57 |
)
|
|
|
|
| 58 |
ai_text = response.text
|
| 59 |
|
| 60 |
eval_prompt = f"""
|
|
|
|
| 84 |
f"評語:{eval_data.comment}"
|
| 85 |
)
|
| 86 |
|
| 87 |
+
# ===== Step 6: 自訂樣式(提問框+聊天框邊界) =====
|
| 88 |
+
CUSTOM_CSS = """
|
| 89 |
+
.gr-text-input textarea, .gr-textbox textarea {
|
| 90 |
+
border: 2px solid #1e3a8a !important;
|
| 91 |
+
box-shadow: 0 0 10px rgba(30, 58, 138, 0.4);
|
| 92 |
+
border-radius: 10px !important;
|
| 93 |
+
color: #dbeafe !important;
|
| 94 |
+
background-color: rgba(15, 23, 42, 0.9) !important;
|
| 95 |
+
}
|
| 96 |
+
.gr-text-input textarea:focus {
|
| 97 |
+
border-color: #2563eb !important;
|
| 98 |
+
box-shadow: 0 0 14px rgba(37, 99, 235, 0.7);
|
| 99 |
+
}
|
| 100 |
+
.gr-chatbot {
|
| 101 |
+
border: 2px solid #1e3a8a !important;
|
| 102 |
+
border-radius: 12px !important;
|
| 103 |
+
box-shadow: 0 0 18px rgba(30, 58, 138, 0.4);
|
| 104 |
+
}
|
| 105 |
+
"""
|
| 106 |
+
|
| 107 |
+
# ===== Step 7: UI =====
|
| 108 |
+
avatar_url = "https://avatars.githubusercontent.com/u/9919?s=200&v=4"
|
| 109 |
+
linkedin_link = "https://www.linkedin.com/in/你的連結"
|
| 110 |
|
| 111 |
with gr.Blocks(
|
| 112 |
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="slate"),
|
| 113 |
+
title="AI Chatbot – Joe' Digital Twin",
|
| 114 |
+
css=CUSTOM_CSS
|
| 115 |
) as demo:
|
| 116 |
with gr.Row():
|
| 117 |
with gr.Column(scale=1):
|
|
|
|
| 121 |
# 🤖 Joe' AI 聊天助理
|
| 122 |
<div style="color:#9ec5fe; font-size:1.1em;">
|
| 123 |
這是一個由 Gemini 模型驅動的個人化聊天機器人。<br>
|
| 124 |
+
它是 Joe 的代理人,能以專業且自然的語氣回覆您的問題。<br>
|
| 125 |
</div>
|
| 126 |
""")
|
| 127 |
+
|
| 128 |
gr.HTML("<hr style='border: 1px solid #1e3a8a;'>")
|
| 129 |
|
| 130 |
chat = gr.ChatInterface(
|