Abhlash commited on
Commit
c5329f9
Β·
verified Β·
1 Parent(s): a5c8933

updated app

Browse files
Files changed (1) hide show
  1. app.py +107 -44
app.py CHANGED
@@ -1,53 +1,116 @@
1
- import sys
2
  import os
3
- import logging
 
 
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
- import gradio as gr
10
- from bot.chat import bot # Import the bot function from chat.py
11
 
12
- # Set up logging
13
- logging.basicConfig(level=logging.INFO)
14
- logger = logging.getLogger(__name__)
15
 
16
- async def chat_interface(message, history):
17
- try:
18
- updated_history = await bot(history + [(message, None)])
19
- bot_response = updated_history[-1][1]
20
-
21
- # Debugging: Print the bot response
22
- print(f"Bot response: {bot_response}")
23
-
24
- # Ensure the bot response is a string
25
- if isinstance(bot_response, list):
26
- bot_response = " ".join(bot_response)
27
-
28
- # Debugging: Print the formatted bot response
29
- print(f"Formatted bot response: {bot_response}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- return bot_response # Return only the bot_response, not the history
32
- except Exception as e:
33
- logger.error(f"Error in chat_interface: {str(e)}")
34
- burner_error_message = (
35
- "Whoa there, playa pal! It seems the dust has clogged my circuits. "
36
- "Let's take a deep breath and try that again. Radical self-reliance, remember?"
37
- )
38
- return burner_error_message # Return only the error message, not the history
39
-
40
-
41
- gr.ChatInterface(
42
- chat_interface,
43
- chatbot=gr.Chatbot(height=300),
44
- textbox=gr.Textbox(placeholder="Ask me anything about Burning Man!", container=False),
45
- title="BurnerBot",
46
- description="Chat with me about Burning Man! I can help with event dates, packing lists, principles, and more!",
47
- theme="soft",
48
- examples=["When is Burning Man this year?", "What are the 10 principles?", "Can you give me a packing list?"],
49
- cache_examples=False,
50
- retry_btn=None,
51
- undo_btn="Delete Previous",
52
- clear_btn="Clear",
53
- ).launch(share=True)
 
 
1
  import os
2
+ import sys
3
+ from dotenv import load_dotenv
4
+ import gradio as gr
5
 
6
  # Add the current directory to the Python path
7
  current_dir = os.path.dirname(os.path.abspath(__file__))
8
  sys.path.append(current_dir)
9
 
10
+ # Load environment variables from .env file
11
+ load_dotenv()
12
 
13
+ # Check if GROQ_API_KEY is set
14
+ if 'GROQ_API_KEY' not in os.environ:
15
+ raise EnvironmentError("GROQ_API_KEY is not set in the environment variables or .env file")
16
 
17
+ # Set GROQ_API_KEY as a global variable
18
+ os.environ['GROQ_API_KEY'] = os.getenv('GROQ_API_KEY')
19
+
20
+ # Now import the chat_interface
21
+ from bot.chat import chat_interface
22
+
23
+ # Custom CSS for Burning Man theme
24
+ custom_css = """
25
+ body {
26
+ background-color: #f4a460;
27
+ background-image: url('https://i.imgur.com/JZjMiZR.jpg');
28
+ background-size: cover;
29
+ background-attachment: fixed;
30
+ font-family: 'Roboto', sans-serif;
31
+ }
32
+ .container {
33
+ max-width: 800px !important;
34
+ margin: auto;
35
+ background-color: rgba(0, 0, 0, 0.7);
36
+ border-radius: 15px;
37
+ padding: 20px;
38
+ box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
39
+ }
40
+ .gr-button {
41
+ background-color: #ff6b35 !important;
42
+ border: none !important;
43
+ }
44
+ .gr-button:hover {
45
+ background-color: #ff8c61 !important;
46
+ }
47
+ .gr-input {
48
+ border-color: #ff6b35 !important;
49
+ }
50
+ .gr-input:focus {
51
+ border-color: #ff8c61 !important;
52
+ box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.25) !important;
53
+ }
54
+ .gr-box {
55
+ border-radius: 15px !important;
56
+ background-color: rgba(255, 255, 255, 0.1) !important;
57
+ }
58
+ .gr-padded {
59
+ padding: 15px !important;
60
+ }
61
+ """
62
+
63
+ # Custom HTML for header and footer
64
+ custom_html = """
65
+ <div style="text-align: center; max-width: 800px; margin: 0 auto;">
66
+ <h1 style="color: #ff6b35; font-size: 3em; margin-bottom: 10px;">BurnerBot</h1>
67
+ <p style="color: #ffffff; font-size: 1.2em; margin-bottom: 20px;">Your dusty digital companion for all things Burning Man!</p>
68
+ </div>
69
+ """
70
+
71
+ with gr.Blocks(css=custom_css) as demo:
72
+ gr.HTML(custom_html)
73
+ chatbot = gr.Chatbot(
74
+ [],
75
+ elem_id="chatbot",
76
+ bubble_full_width=False,
77
+ avatar_images=(None, "https://i.imgur.com/nAcdSry.png"),
78
+ height=400
79
+ )
80
+ msg = gr.Textbox(
81
+ show_label=False,
82
+ placeholder="Ask me anything about Burning Man...",
83
+ container=False
84
+ )
85
+ clear = gr.Button("Clear")
86
+
87
+ def user(user_message, history):
88
+ return "", history + [[user_message, None]]
89
+
90
+ def bot(history):
91
+ user_message = history[-1][0]
92
+ bot_message = chat_interface(user_message, history[:-1])
93
+ history[-1][1] = bot_message
94
+ return history
95
+
96
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
97
+ bot, chatbot, chatbot
98
+ )
99
+ clear.click(lambda: None, None, chatbot, queue=False)
100
+
101
+ gr.Markdown(
102
+ """
103
+ ### πŸ”₯ Welcome to the Playa, Burner! πŸ”₯
104
+ Ask me about:
105
+ - πŸ“… Event dates and tickets
106
+ - πŸ•οΈ Survival guide and packing tips
107
+ - 🌟 The 10 Principles
108
+ - 🎨 Art installations and theme camps
109
+ - 🚲 Transportation and arrival
110
+ - And much more!
111
 
112
+ Remember, participation is key. Let's co-create an amazing experience! )'(
113
+ """
114
+ )
115
+
116
+ demo.launch()