BICORP commited on
Commit
47b6ea0
·
verified ·
1 Parent(s): 6a98d1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -8
app.py CHANGED
@@ -27,27 +27,53 @@ def call_api(message, model, preset):
27
  except Exception as e:
28
  return f"Error: {str(e)}"
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  # Create Gradio interface
31
  def create_interface():
32
- with gr.Blocks() as demo:
33
  gr.Markdown("## 💬 Chatbot")
34
 
35
  # Chat display area
36
- chatbox = gr.Textbox(label="", interactive=False, lines=12)
37
-
38
- # Input box for user messages
39
- user_input = gr.Textbox(label="Type your message here...", placeholder="Enter your message...", lines=1)
40
 
41
- # Send button
42
- send_button = gr.Button("Send")
 
 
43
 
44
  # Settings section
45
  with gr.Accordion("⚙️ Settings", open=False):
46
  model = gr.Dropdown(choices=["Lake 1 Base"], label="Model", value="Lake 1 Base")
47
  preset = gr.Dropdown(choices=["Fast", "Normal", "Quality", "Unreal Performance"], label="Preset", value="Fast")
 
 
 
 
48
 
49
  # Define the action for the send button
50
- send_button.click(fn=call_api, inputs=[user_input, model, preset], outputs=chatbox)
 
 
 
 
 
 
 
51
 
52
  return demo
53
 
 
27
  except Exception as e:
28
  return f"Error: {str(e)}"
29
 
30
+ # Dark mode CSS
31
+ dark_css = """
32
+ .gradio-container {
33
+ background-color: #1e1e1e; /* Dark background */
34
+ color: white; /* Light text color */
35
+ }
36
+ #chatbox {
37
+ background-color: #2e2e2e; /* Dark chatbox */
38
+ color: white; /* Light text color */
39
+ }
40
+ """
41
+
42
+ # Function to toggle dark mode
43
+ def toggle_dark_mode(is_dark):
44
+ return dark_css if is_dark else ""
45
+
46
  # Create Gradio interface
47
  def create_interface():
48
+ with gr.Blocks(css=dark_css) as demo:
49
  gr.Markdown("## 💬 Chatbot")
50
 
51
  # Chat display area
52
+ chatbox = gr.Textbox(label="", interactive=False, elem_id="chatbox", lines=12)
 
 
 
53
 
54
+ # Input area
55
+ with gr.Row():
56
+ user_input = gr.Textbox(label="Type your message here...", placeholder="Enter your message...", interactive=True)
57
+ send_button = gr.Button("Send")
58
 
59
  # Settings section
60
  with gr.Accordion("⚙️ Settings", open=False):
61
  model = gr.Dropdown(choices=["Lake 1 Base"], label="Model", value="Lake 1 Base")
62
  preset = gr.Dropdown(choices=["Fast", "Normal", "Quality", "Unreal Performance"], label="Preset", value="Fast")
63
+ dark_mode = gr.Checkbox(label="Enable Dark Mode", value=False)
64
+
65
+ # Change CSS based on dark mode toggle
66
+ dark_mode.change(lambda x: demo.css.update(toggle_dark_mode(x)), inputs=[dark_mode])
67
 
68
  # Define the action for the send button
69
+ def send_message(message):
70
+ if message:
71
+ response = call_api(message, model.value, preset.value)
72
+ return f"You: {message}\nBot: {response}"
73
+ return ""
74
+
75
+ # Connect the send button to the send_message function
76
+ send_button.click(send_message, inputs=user_input, outputs=chatbox)
77
 
78
  return demo
79