Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,26 +27,17 @@ repo.git_pull() # Pull the latest changes (if any)
|
|
27 |
pdf_file_path = "Private_Book/KOMBI_all2.pdf" # Replace with your PDF file path
|
28 |
|
29 |
|
30 |
-
# Add this function to handle button clicks
|
31 |
-
def on_button_click(query):
|
32 |
-
st.session_state['button_clicked'] = query
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
def cloud_button(label, query, key=None, color=None, overlap=30):
|
39 |
button_id = f"cloud-button-{key or label}"
|
40 |
color_class = f"color-{color}" if color else ""
|
41 |
num_circles = max(3, min(35, len(label) // 4))
|
42 |
circle_size = 60
|
43 |
|
44 |
-
# Create circles with text enclosed
|
45 |
circles_html = ''.join([
|
46 |
f'<div class="circle {color_class}" style="margin-right: -{overlap}px;"></div>'
|
47 |
for _ in range(num_circles)
|
48 |
])
|
49 |
-
circles_html += f'<div class="circle-text">{label}</div>'
|
50 |
|
51 |
cloud_button_html = f"""
|
52 |
<div class="cloud" id="{button_id}" style="margin-bottom: 20px;">
|
@@ -82,12 +73,12 @@ def cloud_button(label, query, key=None, color=None, overlap=30):
|
|
82 |
transform: translate(-50%, -50%);
|
83 |
font-weight: bold;
|
84 |
z-index: 2;
|
85 |
-
white-space: nowrap;
|
86 |
-
text-align: center;
|
87 |
}}
|
88 |
.cloud:hover .circle {{
|
89 |
-
transform: scale(1.1);
|
90 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
91 |
}}
|
92 |
.color-1 .circle {{ background-color: #FFA07A; }}
|
93 |
.color-2 .circle {{ background-color: #FF7F50; }}
|
@@ -105,69 +96,11 @@ def cloud_button(label, query, key=None, color=None, overlap=30):
|
|
105 |
"""
|
106 |
st.markdown(cloud_button_html, unsafe_allow_html=True)
|
107 |
|
108 |
-
|
109 |
def display_chat_history(chat_history):
|
110 |
for sender, msg, _ in chat_history:
|
111 |
background_color = "#FFA07A" if sender == "User" else "#caf"
|
112 |
st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{sender}: {msg}</div>", unsafe_allow_html=True)
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
with st.sidebar:
|
117 |
-
st.title('BinDoc GmbH')
|
118 |
-
st.markdown("Experience revolutionary interaction with BinDocs Chat App, leveraging state-of-the-art AI technology.")
|
119 |
-
|
120 |
-
add_vertical_space(1) # Adjust as per the desired spacing
|
121 |
-
|
122 |
-
st.markdown("""
|
123 |
-
Hello! I’m here to assist you with:<br><br>
|
124 |
-
📘 **Glossary Inquiries:**<br>
|
125 |
-
I can clarify terms like "DiGA", "AOP", or "BfArM", providing clear and concise explanations to help you understand our content better.<br><br>
|
126 |
-
🆘 **Help Page Navigation:**<br>
|
127 |
-
Ask me if you forgot your password or want to know more about topics related to the platform.<br><br>
|
128 |
-
📰 **Latest Whitepapers Insights:**<br>
|
129 |
-
Curious about our recent publications? Feel free to ask about our latest whitepapers!<br><br>
|
130 |
-
""", unsafe_allow_html=True)
|
131 |
-
|
132 |
-
add_vertical_space(1) # Adjust as per the desired spacing
|
133 |
-
|
134 |
-
st.write('Made with ❤️ by BinDoc GmbH')
|
135 |
-
|
136 |
-
api_key = os.getenv("OPENAI_API_KEY")
|
137 |
-
# Retrieve the API key from st.secrets
|
138 |
-
|
139 |
-
|
140 |
-
def load_pdf(file_path):
|
141 |
-
pdf_reader = PdfReader(file_path)
|
142 |
-
text = ""
|
143 |
-
for page in pdf_reader.pages:
|
144 |
-
text += page.extract_text()
|
145 |
-
|
146 |
-
text_splitter = RecursiveCharacterTextSplitter(
|
147 |
-
chunk_size=1000,
|
148 |
-
chunk_overlap=200,
|
149 |
-
length_function=len
|
150 |
-
)
|
151 |
-
chunks = text_splitter.split_text(text=text)
|
152 |
-
|
153 |
-
store_name, _ = os.path.splitext(os.path.basename(file_path))
|
154 |
-
|
155 |
-
if os.path.exists(f"{store_name}.pkl"):
|
156 |
-
with open(f"{store_name}.pkl", "rb") as f:
|
157 |
-
VectorStore = pickle.load(f)
|
158 |
-
else:
|
159 |
-
embeddings = OpenAIEmbeddings()
|
160 |
-
VectorStore = FAISS.from_texts(chunks, embedding=embeddings)
|
161 |
-
with open(f"{store_name}.pkl", "wb") as f:
|
162 |
-
pickle.dump(VectorStore, f)
|
163 |
-
|
164 |
-
return VectorStore
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
def load_chatbot():
|
169 |
-
return load_qa_chain(llm=OpenAI(), chain_type="stuff")
|
170 |
-
|
171 |
def main():
|
172 |
hide_streamlit_style = """
|
173 |
<style>
|
|
|
27 |
pdf_file_path = "Private_Book/KOMBI_all2.pdf" # Replace with your PDF file path
|
28 |
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def cloud_button(label, query, key=None, color=None, overlap=30):
|
31 |
button_id = f"cloud-button-{key or label}"
|
32 |
color_class = f"color-{color}" if color else ""
|
33 |
num_circles = max(3, min(35, len(label) // 4))
|
34 |
circle_size = 60
|
35 |
|
|
|
36 |
circles_html = ''.join([
|
37 |
f'<div class="circle {color_class}" style="margin-right: -{overlap}px;"></div>'
|
38 |
for _ in range(num_circles)
|
39 |
])
|
40 |
+
circles_html += f'<div class="circle-text">{label}</div>'
|
41 |
|
42 |
cloud_button_html = f"""
|
43 |
<div class="cloud" id="{button_id}" style="margin-bottom: 20px;">
|
|
|
73 |
transform: translate(-50%, -50%);
|
74 |
font-weight: bold;
|
75 |
z-index: 2;
|
76 |
+
white-space: nowrap;
|
77 |
+
text-align: center;
|
78 |
}}
|
79 |
.cloud:hover .circle {{
|
80 |
+
transform: scale(1.1);
|
81 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
82 |
}}
|
83 |
.color-1 .circle {{ background-color: #FFA07A; }}
|
84 |
.color-2 .circle {{ background-color: #FF7F50; }}
|
|
|
96 |
"""
|
97 |
st.markdown(cloud_button_html, unsafe_allow_html=True)
|
98 |
|
|
|
99 |
def display_chat_history(chat_history):
|
100 |
for sender, msg, _ in chat_history:
|
101 |
background_color = "#FFA07A" if sender == "User" else "#caf"
|
102 |
st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{sender}: {msg}</div>", unsafe_allow_html=True)
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
def main():
|
105 |
hide_streamlit_style = """
|
106 |
<style>
|