hassan773 commited on
Commit
089b085
·
verified ·
1 Parent(s): 2ac9925

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -15
app.py CHANGED
@@ -6,25 +6,24 @@ from groq import Groq
6
  api_key = os.environ.get("GROQ_API_KEY")
7
  client = Groq(api_key=api_key)
8
 
9
- # 2. UI Styling for Full-Screen & Sidebar Toggle
10
  custom_css = """
11
- /* Full-screen container setup */
12
  .gradio-container {
13
  max-width: 100% !important;
14
  height: 100vh !important;
15
  margin: 0 !important;
16
  padding: 10px 20px !important;
 
17
  }
18
 
19
- /* Chat window fills remaining height */
20
  #chatbot-window {
21
- height: 75vh !important;
22
  border-radius: 12px;
23
  border: 1px solid #e0e0e0;
24
  background: white;
25
  }
26
 
27
- /* Scrolling fixes for inputs */
28
  #system-prompt-container textarea, .scroll-input textarea {
29
  height: 45px !important;
30
  max-height: 45px !important;
@@ -32,12 +31,12 @@ custom_css = """
32
  resize: none !important;
33
  }
34
 
35
- /* Sidebar panel styling */
36
  .sidebar-panel {
37
  background-color: #f9f9f9;
38
  padding: 15px !important;
39
  border-radius: 12px;
40
- border-left: 1px solid #ddd;
 
41
  }
42
  """
43
 
@@ -65,14 +64,17 @@ def chat_with_groq(message, history, model, temperature, system_prompt):
65
 
66
  # 4. Interface Setup
67
  with gr.Blocks(css=custom_css) as demo:
 
 
 
68
  with gr.Row():
69
  gr.Markdown("# 🌿🤖 SageBot")
70
- # Toggle Button placed at top right
71
  settings_btn = gr.Button("⚙️ Settings", scale=0, min_width=120)
72
 
73
  with gr.Row():
74
- # Main Interaction Area (Starts full width)
75
- with gr.Column(scale=4, elem_id="main-chat-area") as chat_col:
76
  chatbot = gr.Chatbot(elem_id="chatbot-window")
77
  with gr.Row():
78
  msg_input = gr.Textbox(
@@ -84,7 +86,7 @@ with gr.Blocks(css=custom_css) as demo:
84
  submit_btn = gr.Button("Send", variant="primary", scale=1, min_width=80)
85
 
86
  # Sidebar Area (Hidden by default)
87
- with gr.Column(scale=1, variant="panel", visible=False, elem_classes="sidebar-panel") as sidebar_col:
88
  gr.Markdown("### ⚙️ Global Settings")
89
  model_choice = gr.Dropdown(
90
  choices=["llama-3.3-70b-versatile", "llama-3.1-8b-instant"],
@@ -102,17 +104,23 @@ with gr.Blocks(css=custom_css) as demo:
102
  # LinkedIn Support
103
  gr.HTML("""
104
  <div style="text-align: center; margin-top: 20px; padding-top: 15px; border-top: 1px solid #ddd;">
 
105
  <a href="https://www.linkedin.com/in/hassan-naseer-web-developer" target="_blank">
106
  <svg width="30" height="30" viewBox="0 0 24 24" fill="#0077b5"><path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.239-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z"/></svg>
107
  </a>
108
  </div>
109
  """)
110
 
111
- # --- Sidebar Toggle Logic ---
112
- def toggle_sidebar(visible):
113
- return gr.update(visible=not visible)
 
114
 
115
- settings_btn.click(toggle_sidebar, [sidebar_col], [sidebar_col])
 
 
 
 
116
 
117
  # --- UI Event Flow ---
118
  def user_turn(msg, hist):
 
6
  api_key = os.environ.get("GROQ_API_KEY")
7
  client = Groq(api_key=api_key)
8
 
9
+ # 2. UI Styling for ChatGPT-like Full-Screen
10
  custom_css = """
 
11
  .gradio-container {
12
  max-width: 100% !important;
13
  height: 100vh !important;
14
  margin: 0 !important;
15
  padding: 10px 20px !important;
16
+ overflow-y: auto !important;
17
  }
18
 
 
19
  #chatbot-window {
20
+ height: 70vh !important;
21
  border-radius: 12px;
22
  border: 1px solid #e0e0e0;
23
  background: white;
24
  }
25
 
26
+ /* One-line scroll for inputs */
27
  #system-prompt-container textarea, .scroll-input textarea {
28
  height: 45px !important;
29
  max-height: 45px !important;
 
31
  resize: none !important;
32
  }
33
 
 
34
  .sidebar-panel {
35
  background-color: #f9f9f9;
36
  padding: 15px !important;
37
  border-radius: 12px;
38
+ border: 1px solid #ddd;
39
+ min-width: 300px !important;
40
  }
41
  """
42
 
 
64
 
65
  # 4. Interface Setup
66
  with gr.Blocks(css=custom_css) as demo:
67
+ # State to track sidebar visibility
68
+ sidebar_state = gr.State(False)
69
+
70
  with gr.Row():
71
  gr.Markdown("# 🌿🤖 SageBot")
72
+ # Settings Toggle Button
73
  settings_btn = gr.Button("⚙️ Settings", scale=0, min_width=120)
74
 
75
  with gr.Row():
76
+ # Main Interaction Area
77
+ with gr.Column(scale=4) as chat_col:
78
  chatbot = gr.Chatbot(elem_id="chatbot-window")
79
  with gr.Row():
80
  msg_input = gr.Textbox(
 
86
  submit_btn = gr.Button("Send", variant="primary", scale=1, min_width=80)
87
 
88
  # Sidebar Area (Hidden by default)
89
+ with gr.Column(scale=1, visible=False, elem_classes="sidebar-panel") as sidebar_col:
90
  gr.Markdown("### ⚙️ Global Settings")
91
  model_choice = gr.Dropdown(
92
  choices=["llama-3.3-70b-versatile", "llama-3.1-8b-instant"],
 
104
  # LinkedIn Support
105
  gr.HTML("""
106
  <div style="text-align: center; margin-top: 20px; padding-top: 15px; border-top: 1px solid #ddd;">
107
+ <p style="font-size: 0.85em; color: #555; margin-bottom: 10px;">Connect with the developer</p>
108
  <a href="https://www.linkedin.com/in/hassan-naseer-web-developer" target="_blank">
109
  <svg width="30" height="30" viewBox="0 0 24 24" fill="#0077b5"><path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.239-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z"/></svg>
110
  </a>
111
  </div>
112
  """)
113
 
114
+ # --- FIXED Sidebar Toggle Logic ---
115
+ def toggle_sidebar(current_state):
116
+ new_state = not current_state
117
+ return gr.update(visible=new_state), new_state
118
 
119
+ settings_btn.click(
120
+ toggle_sidebar,
121
+ inputs=[sidebar_state],
122
+ outputs=[sidebar_col, sidebar_state]
123
+ )
124
 
125
  # --- UI Event Flow ---
126
  def user_turn(msg, hist):