Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
| 7 |
import faiss
|
| 8 |
from simple_salesforce import Salesforce
|
| 9 |
from dotenv import load_dotenv
|
|
|
|
| 10 |
import zipfile
|
| 11 |
from pathlib import Path
|
| 12 |
|
|
@@ -180,7 +181,7 @@ def answer_query(query):
|
|
| 180 |
logger.error(f"Error in answer_query: {str(e)}")
|
| 181 |
return f"Error: {str(e)}", "", "", ""
|
| 182 |
|
| 183 |
-
# --- Gradio Chatbot UI
|
| 184 |
def process_question(q):
|
| 185 |
if not q.strip():
|
| 186 |
return "Please enter a question.", "", ""
|
|
@@ -188,28 +189,37 @@ def process_question(q):
|
|
| 188 |
answer, confidence, source, record_id = answer_query(q)
|
| 189 |
return answer, confidence, source, record_id
|
| 190 |
|
| 191 |
-
# ---
|
| 192 |
with gr.Blocks(title="Company Documents Q&A Chatbot", theme=gr.themes.Soft()) as demo:
|
| 193 |
gr.Markdown("## 📚 Company Documents Q&A Chatbot")
|
| 194 |
-
|
| 195 |
with gr.Row():
|
| 196 |
with gr.Column(scale=3):
|
| 197 |
question = gr.Textbox(
|
| 198 |
label="Ask a Question",
|
| 199 |
placeholder="What are the conditions for permanent employment status?",
|
| 200 |
-
lines=1
|
|
|
|
| 201 |
)
|
| 202 |
with gr.Column(scale=1):
|
| 203 |
submit_btn = gr.Button("Submit", variant="primary")
|
| 204 |
|
| 205 |
with gr.Row():
|
| 206 |
with gr.Column():
|
| 207 |
-
# Chatbot
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
|
|
|
| 7 |
import faiss
|
| 8 |
from simple_salesforce import Salesforce
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
+
import json
|
| 11 |
import zipfile
|
| 12 |
from pathlib import Path
|
| 13 |
|
|
|
|
| 181 |
logger.error(f"Error in answer_query: {str(e)}")
|
| 182 |
return f"Error: {str(e)}", "", "", ""
|
| 183 |
|
| 184 |
+
# --- Gradio Chatbot UI ---
|
| 185 |
def process_question(q):
|
| 186 |
if not q.strip():
|
| 187 |
return "Please enter a question.", "", ""
|
|
|
|
| 189 |
answer, confidence, source, record_id = answer_query(q)
|
| 190 |
return answer, confidence, source, record_id
|
| 191 |
|
| 192 |
+
# --- Chatbot UI Design (Chat bubble style) ---
|
| 193 |
with gr.Blocks(title="Company Documents Q&A Chatbot", theme=gr.themes.Soft()) as demo:
|
| 194 |
gr.Markdown("## 📚 Company Documents Q&A Chatbot")
|
| 195 |
+
|
| 196 |
with gr.Row():
|
| 197 |
with gr.Column(scale=3):
|
| 198 |
question = gr.Textbox(
|
| 199 |
label="Ask a Question",
|
| 200 |
placeholder="What are the conditions for permanent employment status?",
|
| 201 |
+
lines=1,
|
| 202 |
+
interactive=True
|
| 203 |
)
|
| 204 |
with gr.Column(scale=1):
|
| 205 |
submit_btn = gr.Button("Submit", variant="primary")
|
| 206 |
|
| 207 |
with gr.Row():
|
| 208 |
with gr.Column():
|
| 209 |
+
# Chatbot styled for a more modern chat look with bubbles
|
| 210 |
+
output_area = gr.HTML(
|
| 211 |
+
label="Chat",
|
| 212 |
+
elem_id="chatbox",
|
| 213 |
+
value="""
|
| 214 |
+
<div style="padding: 10px; background-color: #f5f5f5; border-radius: 10px;">
|
| 215 |
+
<div style="padding: 5px 10px; background-color: #dfe1e6; border-radius: 10px; margin-bottom: 10px;">
|
| 216 |
+
<b>User:</b> <span id="user-message"> </span>
|
| 217 |
+
</div>
|
| 218 |
+
<div style="padding: 5px 10px; background-color: #007bff; color: white; border-radius: 10px;">
|
| 219 |
+
<b>Bot:</b> <span id="bot-message"> </span>
|
| 220 |
+
</div>
|
| 221 |
+
</div>""")
|
| 222 |
+
|
| 223 |
+
submit_btn.click(fn=process_question, inputs=question, outputs=[output_area])
|
| 224 |
|
| 225 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
|