updated app
Browse files
app.py
CHANGED
|
@@ -1,20 +1,14 @@
|
|
| 1 |
import os
|
| 2 |
-
import sys
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
if 'GROQ_API_KEY' not in os.environ:
|
| 12 |
-
raise EnvironmentError("GROQ_API_KEY is not set in the environment variables or .env file")
|
| 13 |
-
|
| 14 |
-
# Set GROQ_API_KEY as a global variable
|
| 15 |
-
os.environ['GROQ_API_KEY'] = os.getenv('GROQ_API_KEY')
|
| 16 |
-
|
| 17 |
-
# Now import the chat_interface
|
| 18 |
from bot.chat import chat_interface
|
| 19 |
|
| 20 |
# Custom CSS for Burning Man theme
|
|
@@ -57,39 +51,28 @@ body {
|
|
| 57 |
}
|
| 58 |
"""
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
with gr.Blocks(css=custom_css) as demo:
|
| 69 |
-
gr.HTML(
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
height=400
|
| 76 |
-
)
|
| 77 |
-
msg = gr.Textbox(
|
| 78 |
-
show_label=False,
|
| 79 |
-
placeholder="Ask me anything about Burning Man...",
|
| 80 |
-
container=False
|
| 81 |
-
)
|
| 82 |
-
clear = gr.Button("Clear")
|
| 83 |
|
| 84 |
-
def user(user_message, history):
|
| 85 |
return "", history + [[user_message, None]]
|
| 86 |
|
| 87 |
-
def bot(history):
|
| 88 |
-
user_message = history[-1][0]
|
| 89 |
-
bot_message = chat_interface(user_message, history[:-1])
|
| 90 |
-
history[-1][1] = bot_message
|
| 91 |
-
return history
|
| 92 |
-
|
| 93 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 94 |
bot, chatbot, chatbot
|
| 95 |
)
|
|
@@ -110,4 +93,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 110 |
"""
|
| 111 |
)
|
| 112 |
|
| 113 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
+
import asyncio
|
| 4 |
+
import logging
|
| 5 |
|
| 6 |
+
# Set up logging
|
| 7 |
+
logging.basicConfig(level=logging.INFO)
|
| 8 |
+
logger = logging.getLogger(__name__)
|
| 9 |
|
| 10 |
|
| 11 |
+
# Import chat_interface after environment variables are loaded
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
from bot.chat import chat_interface
|
| 13 |
|
| 14 |
# Custom CSS for Burning Man theme
|
|
|
|
| 51 |
}
|
| 52 |
"""
|
| 53 |
|
| 54 |
+
async def bot(history):
|
| 55 |
+
try:
|
| 56 |
+
user_message = history[-1][0]
|
| 57 |
+
bot_message = await chat_interface(user_message, history[:-1])
|
| 58 |
+
history[-1][1] = bot_message
|
| 59 |
+
return history
|
| 60 |
+
except Exception as e:
|
| 61 |
+
logger.error(f"Error in bot function: {str(e)}")
|
| 62 |
+
history[-1][1] = "Oops! Something went wrong. Please try again later."
|
| 63 |
+
return history
|
| 64 |
|
| 65 |
with gr.Blocks(css=custom_css) as demo:
|
| 66 |
+
gr.HTML("<h1 style='text-align: center; color: #ff6b35;'>BurnerBot</h1>")
|
| 67 |
+
gr.HTML("<p style='text-align: center; color: #ffffff;'>Your dusty digital companion for all things Burning Man!</p>")
|
| 68 |
+
|
| 69 |
+
chatbot = gr.Chatbot(height=400)
|
| 70 |
+
msg = gr.Textbox(label="Ask about Burning Man", placeholder="What would you like to know about Burning Man?")
|
| 71 |
+
clear = gr.Button("Clear Chat")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
+
async def user(user_message, history):
|
| 74 |
return "", history + [[user_message, None]]
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 77 |
bot, chatbot, chatbot
|
| 78 |
)
|
|
|
|
| 93 |
"""
|
| 94 |
)
|
| 95 |
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
+
demo.queue()
|
| 98 |
+
demo.launch()
|