Abhlash commited on
Commit
ff12aa6
·
verified ·
1 Parent(s): cfa68e6

updated app

Browse files
Files changed (1) hide show
  1. app.py +26 -41
app.py CHANGED
@@ -1,20 +1,14 @@
1
  import os
2
- import sys
3
  import gradio as gr
 
 
4
 
5
- # Add the current directory to the Python path
6
- current_dir = os.path.dirname(os.path.abspath(__file__))
7
- sys.path.append(current_dir)
8
 
9
 
10
- # Check if GROQ_API_KEY is set
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
- # Custom HTML for header and footer
61
- custom_html = """
62
- <div style="text-align: center; max-width: 800px; margin: 0 auto;">
63
- <h1 style="color: #ff6b35; font-size: 3em; margin-bottom: 10px;">BurnerBot</h1>
64
- <p style="color: #ffffff; font-size: 1.2em; margin-bottom: 20px;">Your dusty digital companion for all things Burning Man!</p>
65
- </div>
66
- """
 
 
 
67
 
68
  with gr.Blocks(css=custom_css) as demo:
69
- gr.HTML(custom_html)
70
- chatbot = gr.Chatbot(
71
- [],
72
- elem_id="chatbot",
73
- bubble_full_width=False,
74
- avatar_images=(None, "https://i.imgur.com/nAcdSry.png"),
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
- demo.launch()
 
 
 
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()