import sys import os import logging # Add the current directory to the Python path current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(current_dir) import gradio as gr from bot.chat import bot # Import the bot function from chat.py # Set up logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) async def chat_interface(message, history): try: updated_history = await bot(history + [(message, None)]) bot_response = updated_history[-1][1] # Debugging: Print the bot response print(f"Bot response: {bot_response}") # Ensure the bot response is a string if isinstance(bot_response, list): bot_response = " ".join(bot_response) # Debugging: Print the formatted bot response print(f"Formatted bot response: {bot_response}") return bot_response, updated_history except Exception as e: logger.error(f"Error in chat_interface: {str(e)}") burner_error_message = ( "Whoa there, playa pal! It seems the dust has clogged my circuits. " "Let's take a deep breath and try that again. Radical self-reliance, remember?" ) return burner_error_message, history + [(message, burner_error_message)] gr.ChatInterface( chat_interface, chatbot=gr.Chatbot(height=300), textbox=gr.Textbox(placeholder="Ask me anything about Burning Man!", container=False), title="BurnerBot", description="Chat with me about Burning Man! I can help with event dates, packing lists, principles, and more!", theme="soft", examples=["When is Burning Man this year?", "What are the 10 principles?", "Can you give me a packing list?"], cache_examples=False, retry_btn=None, undo_btn="Delete Previous", clear_btn="Clear", ).launch(share = True)