Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,6 @@ import os
|
|
16 |
OPENAI_API_KEY = os.getenv("OPENAI_API")
|
17 |
TOKEN=os.getenv('HF_TOKEN')
|
18 |
subprocess.run(["huggingface-cli", "login", "--token", TOKEN, "--add-to-git-credential"])
|
19 |
-
st.sidebar.title("Welcome to MBAL Chatbot")
|
20 |
class PDFChatbot:
|
21 |
def __init__(self):
|
22 |
self.azure_client = openai.OpenAI()
|
@@ -98,13 +97,13 @@ Please provide a helpful response based on the insurance document content above.
|
|
98 |
}
|
99 |
]
|
100 |
# Add conversation history
|
101 |
-
for msg in self.conversation_history[-
|
102 |
messages.append(msg)
|
103 |
# Get response from Azure OpenAI
|
104 |
response = self.azure_client.chat.completions.create(
|
105 |
model="gpt-4o-mini",
|
106 |
messages=messages,
|
107 |
-
max_tokens=
|
108 |
temperature=0.7
|
109 |
)
|
110 |
bot_response = response.choices[0].message.content
|
@@ -114,9 +113,8 @@ Please provide a helpful response based on the insurance document content above.
|
|
114 |
return bot_response
|
115 |
|
116 |
def main():
|
117 |
-
# st.set_page_config(page_title="
|
118 |
-
st.title("🛡️
|
119 |
-
st.markdown("Upload your insurance policy PDF and ask questions about your coverage, claims, deductibles, and more!")
|
120 |
# Initialize chatbot
|
121 |
if 'chatbot' not in st.session_state:
|
122 |
st.session_state.chatbot = PDFChatbot()
|
@@ -130,12 +128,12 @@ def main():
|
|
130 |
st.session_state.chat_history = []
|
131 |
st.rerun()
|
132 |
# Main chat interface
|
133 |
-
st.header("💬
|
134 |
# Display chat history
|
135 |
for i, (question, answer) in enumerate(st.session_state.chat_history):
|
136 |
with st.container():
|
137 |
-
st.markdown(f"**
|
138 |
-
st.markdown(f"**
|
139 |
st.divider()
|
140 |
# Chat input
|
141 |
user_question = st.chat_input("Hãy đặt những câu hỏi về hợp đồng bảo hiểm cơ bản...")
|
|
|
16 |
OPENAI_API_KEY = os.getenv("OPENAI_API")
|
17 |
TOKEN=os.getenv('HF_TOKEN')
|
18 |
subprocess.run(["huggingface-cli", "login", "--token", TOKEN, "--add-to-git-credential"])
|
|
|
19 |
class PDFChatbot:
|
20 |
def __init__(self):
|
21 |
self.azure_client = openai.OpenAI()
|
|
|
97 |
}
|
98 |
]
|
99 |
# Add conversation history
|
100 |
+
for msg in self.conversation_history[-6:]: # Keep last 6 messages for context
|
101 |
messages.append(msg)
|
102 |
# Get response from Azure OpenAI
|
103 |
response = self.azure_client.chat.completions.create(
|
104 |
model="gpt-4o-mini",
|
105 |
messages=messages,
|
106 |
+
max_tokens=800, #TODO
|
107 |
temperature=0.7
|
108 |
)
|
109 |
bot_response = response.choices[0].message.content
|
|
|
113 |
return bot_response
|
114 |
|
115 |
def main():
|
116 |
+
# st.set_page_config(page_title="Chatbot t", page_icon="🛡️", layout="wide")
|
117 |
+
st.title("🛡️ Chatbot tư vấn bảo hiểm của công ty bảo hiểm nhân thọ MB Ageas Life")
|
|
|
118 |
# Initialize chatbot
|
119 |
if 'chatbot' not in st.session_state:
|
120 |
st.session_state.chatbot = PDFChatbot()
|
|
|
128 |
st.session_state.chat_history = []
|
129 |
st.rerun()
|
130 |
# Main chat interface
|
131 |
+
st.header("💬 Hãy đặt câu hỏi cho tôi về gói bảo hiểm bạn quan tâm")
|
132 |
# Display chat history
|
133 |
for i, (question, answer) in enumerate(st.session_state.chat_history):
|
134 |
with st.container():
|
135 |
+
st.markdown(f"**Câu hỏi:** {question}")
|
136 |
+
st.markdown(f"**Trợ lý bảo hiểm:** {answer}")
|
137 |
st.divider()
|
138 |
# Chat input
|
139 |
user_question = st.chat_input("Hãy đặt những câu hỏi về hợp đồng bảo hiểm cơ bản...")
|