import gradio as gr from dotenv import load_dotenv from answer import answer_question load_dotenv(override=True) # ----------------------------- # FORMAT CONTEXT PANEL # ----------------------------- def format_context(docs): result = "
📄 {title}"
if doc_type:
result += f" | {doc_type}"
result += "
{doc.page_content}\n\n"
return result
# -----------------------------
# CHAT LOGIC
# -----------------------------
def chat(history):
last_message = history[-1]["content"]
prior = history[:-1]
answer, docs = answer_question(last_message, prior)
history.append({"role": "assistant", "content": answer})
return history, format_context(docs)
# -----------------------------
# UI
# -----------------------------
def main():
def put_message_in_chatbot(message, history):
return "", history + [{"role": "user", "content": message}]
theme = gr.themes.Soft(font=["Inter", "system-ui", "sans-serif"])
with gr.Blocks(title="Infor LN Dev Assistant") as ui:
gr.Markdown("# 🛠️ Infor LN Development Assistant\nAsk me anything about 4GL, DAL, functions, and Infor LN development!")
with gr.Row():
with gr.Column(scale=1):
chatbot = gr.Chatbot(
label="💬 Conversation",
height=600,
render_markdown=True, # 👈 renders newlines and markdown
)
message = gr.Textbox(
placeholder="Ask anything about Infor LN development...",
show_label=False,
submit_btn=True, # shows send button on textbox
)
with gr.Column(scale=1):
context_display = gr.HTML(
label="📚 Retrieved Context",
value="Retrieved context will appear here...
", ) message.submit( put_message_in_chatbot, inputs=[message, chatbot], outputs=[message, chatbot] ).then( chat, inputs=chatbot, outputs=[chatbot, context_display] ) ui.launch( server_name="0.0.0.0", server_port=7860, inbrowser=True, share=False, theme=theme ) if __name__ == "__main__": main()