mariusjabami commited on
Commit
6e60b60
·
verified ·
1 Parent(s): 968b137

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -18
app.py CHANGED
@@ -6,13 +6,13 @@ client = InferenceClient("lambdaindie/lambdai")
6
  css = r"""
7
  /* Fonte e cores gerais */
8
  * { font-family: 'JetBrains Mono', monospace; }
9
- .gradio-container { background-color: #0d0d0d; color: #e0e0e0; }
10
  /* Inputs e chat bubbles */
11
- textarea, input, .block, .wrap, .chatbot, .scroll-hide {
12
  background-color: #1a1a1a !important;
13
  color: #e0e0e0 !important;
14
  border: 1px solid #333 !important;
15
- border-radius: 12px;
16
  }
17
  /* Botão com pulse animation */
18
  @keyframes pulse {
@@ -24,7 +24,7 @@ button.pulse {
24
  background-color: #272727 !important;
25
  border: 1px solid #444 !important;
26
  color: #e0e0e0 !important;
27
- border-radius: 12px;
28
  animation: pulse 2s infinite;
29
  }
30
  /* Hover no botão */
@@ -50,7 +50,7 @@ button.pulse:hover {
50
  /* Markdown de thinking dentro do chat */
51
  .thinking-html {
52
  background-color: #2b2b2b;
53
- padding: 10px;
54
  border-radius: 8px;
55
  margin-bottom: 8px;
56
  font-style: italic;
@@ -58,25 +58,44 @@ button.pulse:hover {
58
  display: flex;
59
  align-items: center;
60
  }
 
 
 
 
 
 
 
 
 
 
 
61
  """
62
 
63
- with gr.Blocks(css=css, theme=gr.themes.Base()) as demo:
 
 
 
64
 
65
- gr.Markdown("<h1 style='text-align:center;color:#e0e0e0;'>🅻 Lambdai-v1-1B</h1>")
66
- chatbot = gr.Chatbot(elem_id="chatbot", height=480, render_markdown=True, show_copy_button=True)
67
-
68
- with gr.Row():
69
- system_message = gr.Textbox(value="You are a helpful AI assistant.", label="System message", lines=1)
70
  with gr.Row():
71
- max_tokens = gr.Slider(128, 2048, value=512, step=1, label="Max tokens")
72
- temperature = gr.Slider(0.1, 1.5, value=0.7, step=0.1, label="Temperature")
73
- top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top‑p")
74
  with gr.Row():
75
  user_input = gr.Textbox(show_label=False, placeholder="Type your message here...", lines=2)
76
  send_button = gr.Button("Λ Think", elem_classes="pulse")
77
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  def respond(message, chat_history, system_message, max_tokens, temperature, top_p):
79
- # 1) exibe o spinner + texto de thinking
80
  thinking_html = (
81
  f"<div class='thinking-html'>"
82
  f"<div class='loader'></div>"
@@ -85,14 +104,14 @@ with gr.Blocks(css=css, theme=gr.themes.Base()) as demo:
85
  )
86
  yield chat_history + [[message, thinking_html]]
87
 
88
- # 2) prepara payload para API
89
  messages = [{"role": "system", "content": system_message}]
90
  for u, a in chat_history:
91
  if u: messages.append({"role":"user", "content":u})
92
  if a: messages.append({"role":"assistant","content":a})
93
  messages.append({"role": "user", "content": message})
94
 
95
- # 3) chama streaming da API
96
  response = ""
97
  for chunk in client.chat_completion(
98
  messages,
@@ -107,8 +126,13 @@ with gr.Blocks(css=css, theme=gr.themes.Base()) as demo:
107
 
108
  send_button.click(
109
  fn=respond,
110
- inputs=[user_input, chatbot, system_message, max_tokens, temperature, top_p],
111
  outputs=chatbot
112
  )
113
 
 
 
 
 
 
114
  demo.launch()
 
6
  css = r"""
7
  /* Fonte e cores gerais */
8
  * { font-family: 'JetBrains Mono', monospace; }
9
+ .gradio-container { background-color: #111; color: #e0e0e0; }
10
  /* Inputs e chat bubbles */
11
+ textarea, input, .block, .wrap, .chatbot {
12
  background-color: #1a1a1a !important;
13
  color: #e0e0e0 !important;
14
  border: 1px solid #333 !important;
15
+ border-radius: 10px;
16
  }
17
  /* Botão com pulse animation */
18
  @keyframes pulse {
 
24
  background-color: #272727 !important;
25
  border: 1px solid #444 !important;
26
  color: #e0e0e0 !important;
27
+ border-radius: 10px;
28
  animation: pulse 2s infinite;
29
  }
30
  /* Hover no botão */
 
50
  /* Markdown de thinking dentro do chat */
51
  .thinking-html {
52
  background-color: #2b2b2b;
53
+ padding: 8px;
54
  border-radius: 8px;
55
  margin-bottom: 8px;
56
  font-style: italic;
 
58
  display: flex;
59
  align-items: center;
60
  }
61
+ /* Opções de parâmetros ocultas até clique */
62
+ #settings-panel {
63
+ display: none;
64
+ background-color: #1a1a1a;
65
+ padding: 10px;
66
+ border-radius: 10px;
67
+ margin-top: 10px;
68
+ }
69
+ #settings-panel.show {
70
+ display: block;
71
+ }
72
  """
73
 
74
+ with gr.Blocks(css=css) as demo:
75
+
76
+ gr.Markdown("<h1 style='text-align:center;color:#e0e0e0;'>Lambdai-v1-1B Chat</h1>")
77
+ chatbot = gr.Chatbot(elem_id="chatbot", height=480, render_markdown=True)
78
 
 
 
 
 
 
79
  with gr.Row():
80
+ system_message = gr.Textbox(value="You are a helpful assistant.", label="System message", lines=1)
 
 
81
  with gr.Row():
82
  user_input = gr.Textbox(show_label=False, placeholder="Type your message here...", lines=2)
83
  send_button = gr.Button("Λ Think", elem_classes="pulse")
84
 
85
+ with gr.Row():
86
+ settings_button = gr.Button("Show Settings", elem_classes="pulse")
87
+ settings_panel = gr.Column(
88
+ gr.Slider(128, 2048, value=512, step=1, label="Max tokens"),
89
+ gr.Slider(0.1, 1.5, value=0.7, step=0.1, label="Temperature"),
90
+ gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top‑p"),
91
+ elem_id="settings-panel"
92
+ )
93
+
94
+ def toggle_settings():
95
+ return gr.update(visible=True) if not settings_panel.visible else gr.update(visible=False)
96
+
97
  def respond(message, chat_history, system_message, max_tokens, temperature, top_p):
98
+ # Exibe o spinner + "thinking"
99
  thinking_html = (
100
  f"<div class='thinking-html'>"
101
  f"<div class='loader'></div>"
 
104
  )
105
  yield chat_history + [[message, thinking_html]]
106
 
107
+ # Prepara payload para API
108
  messages = [{"role": "system", "content": system_message}]
109
  for u, a in chat_history:
110
  if u: messages.append({"role":"user", "content":u})
111
  if a: messages.append({"role":"assistant","content":a})
112
  messages.append({"role": "user", "content": message})
113
 
114
+ # Chama API
115
  response = ""
116
  for chunk in client.chat_completion(
117
  messages,
 
126
 
127
  send_button.click(
128
  fn=respond,
129
+ inputs=[user_input, chatbot, system_message, 512, 0.7, 0.95],
130
  outputs=chatbot
131
  )
132
 
133
+ settings_button.click(
134
+ fn=toggle_settings,
135
+ outputs=settings_panel
136
+ )
137
+
138
  demo.launch()