hassan773 commited on
Commit
2569b9b
·
verified ·
1 Parent(s): 45ea408

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -6,7 +6,7 @@ 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 - Adjusted height to 500px to be less lengthy
10
  custom_css = """
11
  .gradio-container { max-width: 1200px; margin: auto; }
12
  #chatbot-window { height: 500px !important; border-radius: 12px; border: 1px solid #e0e0e0; }
@@ -47,7 +47,7 @@ def chat_with_groq(message, history, model, temperature, system_prompt):
47
  except Exception as e:
48
  yield f"⚠️ API Error: {str(e)}"
49
 
50
- # 4. Define Event Functions BEFORE using them
51
  def user_turn(msg, hist):
52
  if not msg:
53
  return "", hist
@@ -69,24 +69,35 @@ with gr.Blocks() as demo:
69
  gr.Markdown("# ⚡ Groq Professional Studio")
70
 
71
  with gr.Row():
72
- # LEFT COLUMN: Chat Interface (Height set to 500)
73
  with gr.Column(scale=4):
74
  chatbot = gr.Chatbot(elem_id="chatbot-window", height=500)
75
  with gr.Row():
76
  msg_input = gr.Textbox(placeholder="Ask me anything...", container=False, scale=9)
77
  submit_btn = gr.Button("Send", variant="primary", scale=1)
78
 
79
- # RIGHT COLUMN: Integrated Sidebar
80
  with gr.Column(scale=1, elem_classes="sidebar-column"):
81
  gr.Markdown("### ⚙️ Settings")
 
82
  model_choice = gr.Dropdown(
83
  choices=["llama-3.3-70b-versatile", "llama-3.1-8b-instant"],
84
- value="llama-3.3-70b-versatile", label="Select Model"
 
85
  )
 
86
  temp = gr.Slider(0.0, 1.0, 0.7, label="Temperature")
87
- sys_msg = gr.Textbox(value="You are a professional assistant.", label="System Prompt", lines=4)
 
 
 
 
 
 
 
88
  clear = gr.Button("Clear Chat", variant="secondary")
89
 
 
90
  gr.HTML("""
91
  <div class="sidebar-footer">
92
  <p style="font-size: 0.9em; margin-bottom: 12px; color: #555;"><b>Developer Support</b></p>
@@ -99,7 +110,7 @@ with gr.Blocks() as demo:
99
  </div>
100
  """)
101
 
102
- # --- Event Linking ---
103
  msg_input.submit(user_turn, [msg_input, chatbot], [msg_input, chatbot], queue=False).then(
104
  bot_turn, [chatbot, model_choice, temp, sys_msg], chatbot
105
  )
@@ -109,4 +120,5 @@ with gr.Blocks() as demo:
109
  clear.click(lambda: [], None, chatbot, queue=False)
110
 
111
  if __name__ == "__main__":
 
112
  demo.launch(theme=gr.themes.Soft(primary_hue="blue"), css=custom_css)
 
6
  api_key = os.environ.get("GROQ_API_KEY")
7
  client = Groq(api_key=api_key)
8
 
9
+ # 2. UI Styling for Sidebar Layout
10
  custom_css = """
11
  .gradio-container { max-width: 1200px; margin: auto; }
12
  #chatbot-window { height: 500px !important; border-radius: 12px; border: 1px solid #e0e0e0; }
 
47
  except Exception as e:
48
  yield f"⚠️ API Error: {str(e)}"
49
 
50
+ # 4. Define Event Functions
51
  def user_turn(msg, hist):
52
  if not msg:
53
  return "", hist
 
69
  gr.Markdown("# ⚡ Groq Professional Studio")
70
 
71
  with gr.Row():
72
+ # LEFT COLUMN: Main Chat Interface
73
  with gr.Column(scale=4):
74
  chatbot = gr.Chatbot(elem_id="chatbot-window", height=500)
75
  with gr.Row():
76
  msg_input = gr.Textbox(placeholder="Ask me anything...", container=False, scale=9)
77
  submit_btn = gr.Button("Send", variant="primary", scale=1)
78
 
79
+ # RIGHT COLUMN: The Sidebar (All Settings & Support moved here)
80
  with gr.Column(scale=1, elem_classes="sidebar-column"):
81
  gr.Markdown("### ⚙️ Settings")
82
+
83
  model_choice = gr.Dropdown(
84
  choices=["llama-3.3-70b-versatile", "llama-3.1-8b-instant"],
85
+ value="llama-3.3-70b-versatile",
86
+ label="Select Model"
87
  )
88
+
89
  temp = gr.Slider(0.0, 1.0, 0.7, label="Temperature")
90
+
91
+ sys_msg = gr.Textbox(
92
+ value="You are a professional assistant.",
93
+ label="System Prompt",
94
+ lines=4
95
+ )
96
+
97
+ # Moved from below input bar to here
98
  clear = gr.Button("Clear Chat", variant="secondary")
99
 
100
+ # LinkedIn Support correctly placed at the bottom of the sidebar
101
  gr.HTML("""
102
  <div class="sidebar-footer">
103
  <p style="font-size: 0.9em; margin-bottom: 12px; color: #555;"><b>Developer Support</b></p>
 
110
  </div>
111
  """)
112
 
113
+ # --- Event Handling ---
114
  msg_input.submit(user_turn, [msg_input, chatbot], [msg_input, chatbot], queue=False).then(
115
  bot_turn, [chatbot, model_choice, temp, sys_msg], chatbot
116
  )
 
120
  clear.click(lambda: [], None, chatbot, queue=False)
121
 
122
  if __name__ == "__main__":
123
+ # Settings moved to launch() for Gradio 6 compatibility
124
  demo.launch(theme=gr.themes.Soft(primary_hue="blue"), css=custom_css)