# app.py # ------------------------------------------- # Imports # ------------------------------------------- import gradio as gr from main import process_user_query # Import only the processing function # ------------------------------------------- # Interface Elements # ------------------------------------------- # Function to handle chat interactions def chat_interface(user_input, history): """ Manages the chat interface flow: - Sends user input to the query processor. - Returns updated conversation history. """ response = process_user_query(user_input) history.append(("User", user_input)) history.append(("Bot", response)) return "", history # Return empty input box and updated history # Function to clear chat def clear_chat(): """ Clears the chat history. """ return [] # ------------------------------------------- # Gradio Interface Setup # ------------------------------------------- def run_gradio_app(): """ Configures and launches the Gradio app. """ with gr.Blocks() as chat_app: gr.Markdown("### ShopWise Chatbot") # Title for the chat UI chatbot = gr.Chatbot() # Chat display # Text input and buttons with gr.Row(): user_input = gr.Textbox(show_label=False, placeholder="Type your question here...") submit_button = gr.Button("Submit") clear_button = gr.Button("Clear Chat") # Button functionality submit_button.click(chat_interface, inputs=[user_input, chatbot], outputs=[user_input, chatbot]) clear_button.click(clear_chat, outputs=chatbot) # Launch the Gradio interface chat_app.launch() # Run the Gradio app if this is the main file if __name__ == "__main__": run_gradio_app()