mariusjabami commited on
Commit
3cfecb5
·
verified ·
1 Parent(s): e3c453c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -65
app.py CHANGED
@@ -1,83 +1,65 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Inicia o cliente para o modelo
5
  client = InferenceClient("lambdaindie/lambdai")
6
 
7
- # CSS simples
8
- css = r"""
9
- * { font-family: 'JetBrains Mono', monospace; }
10
- .gradio-container { background-color: #111; color: #e0e0e0; }
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
- button.pulse {
18
- background-color: #272727 !important;
19
- border: 1px solid #444 !important;
20
- color: #e0e0e0 !important;
21
- border-radius: 10px;
22
- animation: pulse 2s infinite;
23
- }
24
- @keyframes pulse {
25
- 0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,255,255,0.5); }
26
- 70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(255,255,255,0); }
27
- 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,255,255,0); }
28
  }
29
  .loader {
30
- border: 3px solid #2b2b2b;
31
- border-top: 3px solid #e0e0e0;
32
- border-radius: 50%;
33
- width: 18px;
34
- height: 18px;
35
- animation: spin 1s linear infinite;
36
  }
37
  @keyframes spin {
38
- 0% { transform: rotate(0deg); }
39
- 100% { transform: rotate(360deg); }
40
  }
41
- .thinking-html {
42
- background-color: #2b2b2b;
43
- padding: 8px;
44
- border-radius: 8px;
45
- margin-bottom: 8px;
46
- font-style: italic;
47
- color: #aaaaaa;
48
- display: flex;
49
- align-items: center;
50
  }
51
  """
52
 
53
- # Função principal para responder
54
- def respond(message, chat_history):
55
- thinking_html = (
56
- f"<div class='thinking-html'>"
57
- f"<div class='loader'></div>"
58
- f"Thinking… generating response..."
59
- f"</div>"
60
  )
61
- yield chat_history + [{"role": "user", "content": message}, {"role": "assistant", "content": thinking_html}]
62
-
63
- response = client.chat_completion([{"role": "user", "content": message}], stream=False)
64
- answer = response['choices'][0]['message']['content']
65
- yield chat_history + [{"role": "user", "content": message}, {"role": "assistant", "content": answer}]
66
 
67
- # Interface Gradio
68
- with gr.Blocks(css=css) as demo:
69
- gr.Markdown("<h1 style='text-align:center;color:#e0e0e0;'>Lambdai-v1-1B</h1>")
70
- chatbot = gr.Chatbot(elem_id="chatbot", height=480, render_markdown=True)
71
 
72
- with gr.Row():
73
- user_input = gr.Textbox(show_label=False, placeholder="Type your message here...", lines=2)
74
- send_button = gr.Button("Send", elem_classes="pulse")
 
75
 
76
- # Aciona a função ao clicar no botão
77
- send_button.click(
78
- fn=respond,
79
- inputs=[user_input, chatbot],
80
- outputs=chatbot
81
- )
 
 
 
 
 
 
82
 
83
- demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
4
  client = InferenceClient("lambdaindie/lambdai")
5
 
6
+ css = """
7
+ .thinking-html {
8
+ display: flex;
9
+ align-items: center;
10
+ gap: 8px;
11
+ color: #666;
12
+ font-style: italic;
13
+ margin-bottom: 5px;
14
+ animation: pulse 1.5s infinite;
 
 
 
 
 
 
 
 
 
 
 
 
15
  }
16
  .loader {
17
+ width: 14px;
18
+ height: 14px;
19
+ border: 2px solid #ccc;
20
+ border-top: 2px solid #666;
21
+ border-radius: 50%;
22
+ animation: spin 1s linear infinite;
23
  }
24
  @keyframes spin {
25
+ to { transform: rotate(360deg); }
 
26
  }
27
+ @keyframes pulse {
28
+ 0% { opacity: 1; transform: scale(1); }
29
+ 50% { opacity: 0.6; transform: scale(1.05); }
30
+ 100% { opacity: 1; transform: scale(1); }
 
 
 
 
 
31
  }
32
  """
33
 
34
+ def respond(message, history):
35
+ thinking = (
36
+ "<div class='thinking-html'>"
37
+ "<div class='loader'></div>"
38
+ "Thinking..."
39
+ "</div>"
 
40
  )
41
+ yield history + [[message, thinking]]
 
 
 
 
42
 
43
+ prompt = f"Think step by step and explain your reasoning before answering:\n\n{message}"
44
+ response = client.chat_completion([{"role": "user", "content": prompt}], stream=False)
45
+ output = response['choices'][0]['message']['content']
 
46
 
47
+ if "\n\n" in output:
48
+ reasoning, answer = output.split("\n\n", 1)
49
+ else:
50
+ reasoning, answer = "No reasoning provided.", output
51
 
52
+ reasoning_md = f"> {reasoning.strip()}"
53
+ final = f"{reasoning_md}\n\n{answer.strip()}"
54
+ yield history + [[message, final]]
55
+
56
+ with gr.Blocks(css=css) as demo:
57
+ gr.Markdown("## Lambdai-v1-1B")
58
+ chatbot = gr.Chatbot()
59
+ msg = gr.Textbox(label="Message")
60
+ send = gr.Button("Send")
61
+
62
+ send.click(respond, [msg, chatbot], chatbot)
63
+ msg.submit(respond, [msg, chatbot], chatbot)
64
 
65
+ demo.launch()